Skip to content

Commit

Permalink
fix: filter empty note (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
syukronrm authored Sep 22, 2023
1 parent 2f97c3a commit 2a597fb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let CONDITION_TYPES = {
},
string: {
ops: ['is', 'contains', 'oneOf', 'isNot', 'doesNotContain', 'notOneOf'],
nullable: false,
nullable: true,
parse(op, value, fieldName) {
if (op === 'oneOf' || op === 'notOneOf') {
assert(
Expand Down
27 changes: 24 additions & 3 deletions packages/loot-core/src/server/accounts/transaction-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,22 @@ describe('Transaction rules', () => {
notes: 'FooO',
amount: -322,
});
await db.insertTransaction({
id: '4',
date: '2020-10-16',
account,
payee: lowesId,
notes: null,
amount: 101,
});
await db.insertTransaction({
id: '5',
date: '2020-10-16',
account,
payee: lowesId,
notes: '',
amount: 124,
});

let transactions = await getMatchingTransactions([
{ field: 'date', op: 'is', value: '2020-10-15' },
Expand All @@ -411,7 +427,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'payee', op: 'is', value: lowesId },
]);
expect(transactions.map(t => t.id)).toEqual(['3']);
expect(transactions.map(t => t.id)).toEqual(['4', '5', '3']);

transactions = await getMatchingTransactions([
{ field: 'amount', op: 'is', value: 353 },
Expand All @@ -433,6 +449,11 @@ describe('Transaction rules', () => {
]);
expect(transactions.map(t => t.id)).toEqual(['2', '3', '1']);

transactions = await getMatchingTransactions([
{ field: 'notes', op: 'is', value: '' },
]);
expect(transactions.map(t => t.id)).toEqual(['4', '5']);

transactions = await getMatchingTransactions([
{ field: 'amount', op: 'gt', value: 300 },
]);
Expand All @@ -454,7 +475,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'amount', op: 'gt', value: -1000, options: { inflow: true } },
]);
expect(transactions.map(t => t.id)).toEqual(['2', '1']);
expect(transactions.map(t => t.id)).toEqual(['4', '5', '2', '1']);

// Same thing for `outflow`: never return `inflow` transactions
transactions = await getMatchingTransactions([
Expand All @@ -465,7 +486,7 @@ describe('Transaction rules', () => {
transactions = await getMatchingTransactions([
{ field: 'date', op: 'gt', value: '2020-10-10' },
]);
expect(transactions.map(t => t.id)).toEqual(['2', '3']);
expect(transactions.map(t => t.id)).toEqual(['4', '5', '2', '3']);

// todo: isapprox
});
Expand Down
6 changes: 6 additions & 0 deletions packages/loot-core/src/server/accounts/transaction-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ export function conditionsToAQL(conditions, { recurDateBounds = 100 } = {}) {
};
}
return apply(field, '$eq', number);
} else if (type === 'string') {
if (value === '') {
return {
$or: [apply(field, '$eq', null), apply(field, '$eq', '')],
};
}
}
return apply(field, '$eq', value);
case 'isNot':
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/shared/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const TYPE_INFO = {
},
string: {
ops: ['is', 'contains', 'oneOf', 'isNot', 'doesNotContain', 'notOneOf'],
nullable: false,
nullable: true,
},
number: {
ops: ['is', 'isapprox', 'isbetween', 'gt', 'gte', 'lt', 'lte'],
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1708.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [syukronrm]
---

fixing filter transaction to show empty note instead of showing error "Value cannot be empty"

0 comments on commit 2a597fb

Please sign in to comment.