|
1 | 1 | import Onyx from 'react-native-onyx'; |
| 2 | +import DateUtils from '@libs/DateUtils'; |
2 | 3 | import {shouldShowBrokenConnectionViolation, shouldShowBrokenConnectionViolationForMultipleTransactions} from '@libs/TransactionUtils'; |
3 | 4 | import CONST from '@src/CONST'; |
4 | 5 | import IntlStore from '@src/languages/IntlStore'; |
@@ -34,6 +35,7 @@ function generateTransaction(values: Partial<Transaction> = {}): Transaction { |
34 | 35 | } |
35 | 36 |
|
36 | 37 | const CURRENT_USER_ID = 1; |
| 38 | +const CURRENT_USER_EMAIL = 'test@example.com'; |
37 | 39 | const SECOND_USER_ID = 2; |
38 | 40 | const FAKE_OPEN_REPORT_ID = 'FAKE_OPEN_REPORT_ID'; |
39 | 41 | const FAKE_OPEN_REPORT_SECOND_USER_ID = 'FAKE_OPEN_REPORT_SECOND_USER_ID'; |
@@ -111,7 +113,7 @@ describe('TransactionUtils', () => { |
111 | 113 | Onyx.init({ |
112 | 114 | keys: ONYXKEYS, |
113 | 115 | initialKeyStates: { |
114 | | - [ONYXKEYS.SESSION]: {accountID: CURRENT_USER_ID}, |
| 116 | + [ONYXKEYS.SESSION]: {accountID: CURRENT_USER_ID, email: 'test@example.com'}, |
115 | 117 | ...reportCollectionDataSet, |
116 | 118 | }, |
117 | 119 | }); |
@@ -646,4 +648,21 @@ describe('TransactionUtils', () => { |
646 | 648 | expect(result).toBe(true); |
647 | 649 | }); |
648 | 650 | }); |
| 651 | + |
| 652 | + describe('isViolationDismissed', () => { |
| 653 | + it('should return true when violation is dismissed for current user', () => { |
| 654 | + const transaction = generateTransaction({ |
| 655 | + comment: { |
| 656 | + dismissedViolations: { |
| 657 | + [CONST.VIOLATIONS.DUPLICATED_TRANSACTION]: { |
| 658 | + [CURRENT_USER_EMAIL]: DateUtils.getDBTime(), |
| 659 | + }, |
| 660 | + }, |
| 661 | + }, |
| 662 | + }); |
| 663 | + const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; |
| 664 | + const result = TransactionUtils.isViolationDismissed(transaction, violation); |
| 665 | + expect(result).toBe(true); |
| 666 | + }); |
| 667 | + }); |
649 | 668 | }); |
0 commit comments