Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
syukronrm committed Sep 17, 2023
1 parent 0bb481f commit ee1a612
Showing 1 changed file with 24 additions and 3 deletions.
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

0 comments on commit ee1a612

Please sign in to comment.