Skip to content

Commit

Permalink
Trim and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-hauser committed Feb 14, 2024
1 parent 68014b6 commit e28bfb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/scrapers/max.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MaxScraper from './max';
import MaxScraper, { getMemo } from './max';
import {
maybeTestCompanyAPI, extendAsyncTimeout, getTestsConfig, exportTransactions,
} from '../tests/tests-utils';
Expand Down Expand Up @@ -50,3 +50,16 @@ describe('Max scraper', () => {
exportTransactions(COMPANY_ID, result.accounts || []);
});
});

describe('getMemo', () => {
type TransactionForMemoTest = Parameters<typeof getMemo>[0];
test.each<[TransactionForMemoTest, string]>([
[{ comments: '' }, ''],
[{ comments: 'comment without funds' }, 'comment without funds'],
[{ comments: '', fundsTransferReceiverOrTransfer: 'Daniel H' }, 'Daniel H'],
[{ comments: '', fundsTransferReceiverOrTransfer: 'Daniel', fundsTransferComment: 'Foo bar' }, 'Daniel: Foo bar'],
])('%o should create memo: %s', (transaction, expected) => {
const memo = getMemo(transaction);
expect(memo).toBe(expected);
});
});
15 changes: 6 additions & 9 deletions src/scrapers/max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SHEKEL_CURRENCY, DOLLAR_CURRENCY, EURO_CURRENCY } from '../constants';

const debug = getDebug('max');

interface ScrapedTransaction {
export interface ScrapedTransaction {
shortCardNumber: string;
paymentDate?: string;
purchaseDate: string;
Expand Down Expand Up @@ -180,16 +180,13 @@ function getChargedCurrency(currencyId: number | null) {
}
}

function getMemo(rawTransaction: ScrapedTransaction) {
let memo = rawTransaction.comments;
if (rawTransaction.fundsTransferReceiverOrTransfer) {
memo += ` ${rawTransaction.fundsTransferReceiverOrTransfer}`;
if (rawTransaction.fundsTransferComment) {
memo += `: ${rawTransaction.fundsTransferComment}`;
}
export function getMemo({ comments, fundsTransferReceiverOrTransfer, fundsTransferComment }: Pick<ScrapedTransaction, 'comments'| 'fundsTransferReceiverOrTransfer' | 'fundsTransferComment'>) {
if (fundsTransferReceiverOrTransfer) {
const memo = `${comments} ${fundsTransferReceiverOrTransfer}`.trim();
return fundsTransferComment ? `${memo}: ${fundsTransferComment}` : memo;
}

return memo;
return comments;
}

function mapTransaction(rawTransaction: ScrapedTransaction): Transaction {
Expand Down

0 comments on commit e28bfb3

Please sign in to comment.