Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/useIsAllowedToIssueCompanyCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function useIsAllowedToIssueCompanyCard({policyID}: {policyID?: string}) {
const selectedFeedData = selectedFeed && companyCards[selectedFeed];
const [domain] = useOnyx(`${ONYXKEYS.COLLECTION.DOMAIN}${selectedFeedData?.domainID}`);

if (selectedFeedData?.domainID === policy?.workspaceAccountID) {
if (selectedFeedData?.domainID === policy?.workspaceAccountID || (policyID && selectedFeedData?.linkedPolicyIDs?.includes(policyID))) {
return isPolicyAdmin;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/hooks/useIsAllowedToIssueCompanyCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const workspaceAccountID = 11111111;

const mockPolicy = {...createRandomPolicy(Number(mockPolicyID), CONST.POLICY.TYPE.TEAM, 'TestPolicy'), policyID: mockPolicyID, workspaceAccountID};

const linkedFeedDomainID = 22222222;

const mockedFeeds = {
// eslint-disable-next-line @typescript-eslint/naming-convention
'vcf#19475968': {
Expand All @@ -31,6 +33,15 @@ const mockedFeeds = {
customFeedName: 'Custom feed name 1',
feed: CONST.COMPANY_CARD.FEED_BANK_NAME.VISA,
},
// eslint-disable-next-line @typescript-eslint/naming-convention
'vcf#22222222': {
liabilityType: 'personal',
pending: false,
domainID: linkedFeedDomainID,
customFeedName: 'Linked feed',
feed: CONST.COMPANY_CARD.FEED_BANK_NAME.VISA,
linkedPolicyIDs: [mockPolicyID],
},
};

jest.mock('@hooks/useCardFeeds', () => ({
Expand Down Expand Up @@ -92,4 +103,22 @@ describe('useIsAllowedToIssueCompanyCard', () => {
const {result} = renderHook(() => useIsAllowedToIssueCompanyCard({policyID: mockPolicyID}));
expect(result?.current).toBe(false);
});
it('should return true if feed is shared via linkedPolicyIDs and user is admin', async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${mockPolicy?.policyID}`, 'vcf#22222222');
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${mockPolicy?.policyID}`, {
role: CONST.POLICY.ROLE.ADMIN,
});
(useCardFeeds as jest.Mock).mockReturnValue([mockedFeeds, {status: 'loaded'}]);
const {result} = renderHook(() => useIsAllowedToIssueCompanyCard({policyID: mockPolicyID}));
expect(result?.current).toBe(true);
});
it('should return false if feed is shared via linkedPolicyIDs and user is not an admin', async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${mockPolicy?.policyID}`, 'vcf#22222222');
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${mockPolicy?.policyID}`, {
role: CONST.POLICY.ROLE.USER,
});
(useCardFeeds as jest.Mock).mockReturnValue([mockedFeeds, {status: 'loaded'}]);
const {result} = renderHook(() => useIsAllowedToIssueCompanyCard({policyID: mockPolicyID}));
expect(result?.current).toBe(false);
});
});
Loading