Skip to content

Commit c191bcc

Browse files
Add unit tests for shouldClearConvertedAmount
Cover all branches: undefined destinationCurrency, matching source/destination, matching transaction/destination, cross-currency clear, and sourceCurrency fallback to transactionCurrency. Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
1 parent 4906add commit c191bcc

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/unit/TransactionUtilsTest.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,4 +2930,36 @@ describe('TransactionUtils', () => {
29302930
expect(TransactionUtils.getExchangeRate(transaction)).toBe('1.25 USD/EUR');
29312931
});
29322932
});
2933+
2934+
describe('shouldClearConvertedAmount', () => {
2935+
it('returns false when destinationCurrency is undefined', () => {
2936+
const transaction = generateTransaction({currency: 'USD'});
2937+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'EUR', undefined)).toBe(false);
2938+
});
2939+
2940+
it('returns false when sourceCurrency equals destinationCurrency', () => {
2941+
const transaction = generateTransaction({currency: 'USD'});
2942+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'EUR', 'EUR')).toBe(false);
2943+
});
2944+
2945+
it('returns false when transactionCurrency equals destinationCurrency', () => {
2946+
const transaction = generateTransaction({currency: 'EUR'});
2947+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'USD', 'EUR')).toBe(false);
2948+
});
2949+
2950+
it('returns true when both sourceCurrency and transactionCurrency differ from destinationCurrency', () => {
2951+
const transaction = generateTransaction({currency: 'GBP'});
2952+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'USD', 'EUR')).toBe(true);
2953+
});
2954+
2955+
it('falls back to transactionCurrency when sourceCurrency is undefined and currencies differ', () => {
2956+
const transaction = generateTransaction({currency: 'GBP'});
2957+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, undefined, 'EUR')).toBe(true);
2958+
});
2959+
2960+
it('returns false when sourceCurrency is undefined and transactionCurrency matches destinationCurrency', () => {
2961+
const transaction = generateTransaction({currency: 'EUR'});
2962+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, undefined, 'EUR')).toBe(false);
2963+
});
2964+
});
29332965
});

0 commit comments

Comments
 (0)