Skip to content

Commit fd50a27

Browse files
committed
fix lint
1 parent 4c68252 commit fd50a27

1 file changed

Lines changed: 60 additions & 44 deletions

File tree

tests/unit/ExpensifyCardFeedSelectorUtilsTest.ts

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,81 @@
1+
import type {OnyxCollection} from 'react-native-onyx';
12
import {getAdminExpensifyCardFeedEntries, getExpensifyCardFeedDescription} from '@libs/ExpensifyCardFeedSelectorUtils';
23
import CONST from '@src/CONST';
34
import ONYXKEYS from '@src/ONYXKEYS';
4-
import type {CardList, Domain, ExpensifyCardSettings, Policy} from '@src/types/onyx';
5+
import type {Card, CardList, Domain, ExpensifyCardSettings, Policy} from '@src/types/onyx';
6+
import {createRandomExpensifyCard} from '../utils/collections/card';
7+
import createRandomPolicy from '../utils/collections/policies';
58

69
const fundID = 5555;
710
const policyID = 'policy_other';
811

12+
function createDomain(email: string, accountID: number): Domain {
13+
return {
14+
validated: true,
15+
accountID,
16+
email,
17+
};
18+
}
19+
20+
function createCardList(...cards: Card[]): CardList {
21+
return cards.reduce<CardList>((list, card, index) => {
22+
list[`card${index}`] = card;
23+
return list;
24+
}, {});
25+
}
26+
27+
function createPolicyWithAccountID(accountID: number, overrides?: Partial<Policy>): Policy {
28+
return {
29+
...createRandomPolicy(1),
30+
role: CONST.POLICY.ROLE.ADMIN,
31+
owner: 'admin@workspace.com',
32+
policyAccountID: accountID,
33+
...overrides,
34+
};
35+
}
36+
937
describe('getExpensifyCardFeedDescription', () => {
1038
it('returns domainName from card settings root', () => {
11-
const settings = {domainName: 'example.com', isEnabled: true} as ExpensifyCardSettings;
39+
const settings: ExpensifyCardSettings = {domainName: 'example.com', isEnabled: true};
1240
expect(getExpensifyCardFeedDescription(settings, {})).toBe('example.com');
1341
});
1442

1543
it('returns domainName nested under a program block when root is missing', () => {
16-
const settings = {
44+
const settings: ExpensifyCardSettings = {
1745
[CONST.COUNTRY.US]: {isEnabled: true},
1846
[CONST.COUNTRY.GB]: {domainName: 'example.co.uk', isEnabled: true},
1947
hasOnceLoaded: true,
20-
} as ExpensifyCardSettings;
48+
};
2149

2250
expect(getExpensifyCardFeedDescription(settings, {})).toBe('example.co.uk');
2351
});
2452

2553
it('falls back to domain email when settings have no domainName', () => {
26-
const settings = {isEnabled: true} as ExpensifyCardSettings;
27-
const domains = {
28-
[`${ONYXKEYS.COLLECTION.DOMAIN}${fundID}`]: {
29-
email: '+@company.com',
30-
},
31-
} as Record<string, Domain>;
54+
const settings: ExpensifyCardSettings = {isEnabled: true};
55+
const domains: OnyxCollection<Domain> = {
56+
[`${ONYXKEYS.COLLECTION.DOMAIN}${fundID}`]: createDomain('+@company.com', fundID),
57+
};
3258

3359
expect(getExpensifyCardFeedDescription(settings, {}, domains, fundID)).toBe('company.com');
3460
});
3561

3662
it('falls back to card list domainName when settings and domain email are missing', () => {
37-
const settings = {isEnabled: true} as ExpensifyCardSettings;
38-
const cardList = {
39-
card1: {
40-
bank: CONST.EXPENSIFY_CARD.BANK,
63+
const settings: ExpensifyCardSettings = {isEnabled: true};
64+
const cardList = createCardList(
65+
createRandomExpensifyCard(1, {
4166
fundID: fundID.toString(),
4267
domainName: 'cards.example.com',
43-
},
44-
} as unknown as CardList;
68+
}),
69+
);
4570

4671
expect(getExpensifyCardFeedDescription(settings, {}, {}, fundID, cardList)).toBe('cards.example.com');
4772
});
4873

4974
it('falls back to workspace policy owner domain when fundID matches policyAccountID', () => {
50-
const settings = {isEnabled: true} as ExpensifyCardSettings;
51-
const policies = {
52-
[`${ONYXKEYS.COLLECTION.POLICY}${policyID.toUpperCase()}`]: {
53-
policyAccountID: fundID,
54-
owner: 'admin@workspace.com',
55-
},
56-
} as Record<string, Policy>;
75+
const settings: ExpensifyCardSettings = {isEnabled: true};
76+
const policies: OnyxCollection<Policy> = {
77+
[`${ONYXKEYS.COLLECTION.POLICY}${policyID.toUpperCase()}`]: createPolicyWithAccountID(fundID),
78+
};
5779

5880
expect(getExpensifyCardFeedDescription(settings, policies, {}, fundID)).toBe('workspace.com');
5981
});
@@ -62,22 +84,16 @@ describe('getExpensifyCardFeedDescription', () => {
6284
describe('getAdminExpensifyCardFeedEntries', () => {
6385
const currentUserAccountID = 999;
6486
const orphanFundID = 1234;
65-
const cardSettingsCollection = {
66-
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: {isEnabled: true, hasOnceLoaded: true},
67-
} as Record<string, ExpensifyCardSettings>;
68-
const adminPolicyForFund = {
69-
[`${ONYXKEYS.COLLECTION.POLICY}WS1`]: {
70-
id: 'WS1',
71-
policyAccountID: orphanFundID,
72-
role: CONST.POLICY.ROLE.ADMIN,
73-
owner: 'admin@workspace.com',
74-
},
75-
} as Record<string, Policy>;
87+
const orphanFeedSettings: ExpensifyCardSettings = {isEnabled: true, hasOnceLoaded: true};
88+
const cardSettingsCollection: OnyxCollection<ExpensifyCardSettings> = {
89+
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: orphanFeedSettings,
90+
};
91+
const adminPolicyForFund: OnyxCollection<Policy> = {
92+
[`${ONYXKEYS.COLLECTION.POLICY}WS1`]: createPolicyWithAccountID(orphanFundID, {id: 'WS1'}),
93+
};
7694

7795
it('shows an orphan feed when the fund has an issued Expensify Card', () => {
78-
const cardList = {
79-
card1: {bank: CONST.EXPENSIFY_CARD.BANK, fundID: orphanFundID.toString()},
80-
} as unknown as CardList;
96+
const cardList = createCardList(createRandomExpensifyCard(1, {fundID: orphanFundID.toString()}));
8197

8298
const entries = getAdminExpensifyCardFeedEntries(cardSettingsCollection, adminPolicyForFund, {}, currentUserAccountID, cardList);
8399

@@ -86,27 +102,27 @@ describe('getAdminExpensifyCardFeedEntries', () => {
86102
});
87103

88104
it('hides an orphan feed when the fund has no issued Expensify Card', () => {
89-
const cardList = {} as CardList;
105+
const cardList: CardList = {};
90106

91107
const entries = getAdminExpensifyCardFeedEntries(cardSettingsCollection, adminPolicyForFund, {}, currentUserAccountID, cardList);
92108

93109
expect(entries).toHaveLength(0);
94110
});
95111

96112
it('still shows a feed with a preferredPolicy even when the fund has no issued Expensify Card', () => {
97-
const settingsWithPreferredPolicy = {
98-
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: {isEnabled: true, hasOnceLoaded: true, preferredPolicy: 'WS1'},
99-
} as Record<string, ExpensifyCardSettings>;
113+
const settingsWithPreferredPolicy: OnyxCollection<ExpensifyCardSettings> = {
114+
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: {...orphanFeedSettings, preferredPolicy: 'WS1'},
115+
};
100116

101117
const entries = getAdminExpensifyCardFeedEntries(settingsWithPreferredPolicy, adminPolicyForFund, {}, currentUserAccountID, {});
102118

103119
expect(entries).toHaveLength(1);
104120
});
105121

106122
it('still shows a feed with linkedPolicyIDs even when the fund has no issued Expensify Card', () => {
107-
const settingsWithLinkedPolicies = {
108-
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: {isEnabled: true, hasOnceLoaded: true, linkedPolicyIDs: ['WS1']},
109-
} as Record<string, ExpensifyCardSettings>;
123+
const settingsWithLinkedPolicies: OnyxCollection<ExpensifyCardSettings> = {
124+
[`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${orphanFundID}`]: {...orphanFeedSettings, linkedPolicyIDs: ['WS1']},
125+
};
110126

111127
const entries = getAdminExpensifyCardFeedEntries(settingsWithLinkedPolicies, adminPolicyForFund, {}, currentUserAccountID, {});
112128

0 commit comments

Comments
 (0)