-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTransactionUtilsTest.ts
64 lines (50 loc) · 2.3 KB
/
TransactionUtilsTest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as TransactionUtils from '../../src/libs/TransactionUtils';
import type {Transaction} from '../../src/types/onyx';
function generateTransaction(values: Partial<Transaction> = {}): Transaction {
const reportID = '1';
const amount = 100;
const currency = 'USD';
const comment = '';
const created = '2023-10-01';
const baseValues = TransactionUtils.buildOptimisticTransaction(amount, currency, reportID, comment, created);
return {...baseValues, ...values};
}
describe('TransactionUtils', () => {
describe('getCreated', () => {
describe('when the transaction property "modifiedCreated" has value', () => {
const transaction = generateTransaction({
created: '2023-10-01',
modifiedCreated: '2023-10-25',
});
it('returns the "modifiedCreated" date with the correct format', () => {
const expectedResult = '2023-10-25';
const result = TransactionUtils.getFormattedCreated(transaction);
expect(result).toEqual(expectedResult);
});
});
describe('when the transaction property "modifiedCreated" does not have value', () => {
describe('and the transaction property "created" has value', () => {
const transaction = generateTransaction({
created: '2023-10-01',
modifiedCreated: undefined,
});
it('returns the "created" date with the correct format', () => {
const expectedResult = '2023-10-01';
const result = TransactionUtils.getFormattedCreated(transaction);
expect(result).toEqual(expectedResult);
});
});
describe('and the transaction property "created" does not have value', () => {
const transaction = generateTransaction({
created: undefined,
modifiedCreated: undefined,
});
it('returns an empty string', () => {
const expectedResult = '';
const result = TransactionUtils.getFormattedCreated(transaction);
expect(result).toEqual(expectedResult);
});
});
});
});
});