Skip to content

Commit 0e6ca1d

Browse files
author
Juarez Mota
committed
fix: update sign-in gate portal tests
1 parent f0d994f commit 0e6ca1d

File tree

2 files changed

+119
-91
lines changed

2 files changed

+119
-91
lines changed

dotcom-rendering/src/components/StickyBottomBanner/SignInGatePortal.test.tsx

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
// Mock the auxia module before imports so the mock is applied when the module
2+
// under test is evaluated.
3+
import { buildAuxiaGateDisplayData } from '../../lib/auxia';
4+
import type { AuxiaGateDisplayData } from '../SignInGate/types';
15
import { canShowSignInGatePortal } from './SignInGatePortal';
26

7+
// Mock the auxia module (Jest hoists jest.mock calls so placing it after imports is fine).
8+
jest.mock('../../lib/auxia', () => ({
9+
buildAuxiaGateDisplayData: jest.fn(),
10+
}));
11+
312
// Mock document.getElementById
413
const mockGetElementById = jest.fn();
514
Object.defineProperty(document, 'getElementById', {
@@ -52,22 +61,83 @@ describe('SignInGatePortal', () => {
5261
const mockElement = document.createElement('div');
5362
mockGetElementById.mockReturnValue(mockElement);
5463

55-
const result = await canShowSignInGatePortal(false, false, false);
64+
// Mock buildAuxiaGateDisplayData to return auxiaData with userTreatment
65+
const auxiaReturn: AuxiaGateDisplayData = {
66+
browserId: 'browser-1',
67+
auxiaData: {
68+
responseId: 'resp1',
69+
userTreatment: {
70+
treatmentId: 't1',
71+
treatmentTrackingId: 'tt1',
72+
rank: '1',
73+
contentLanguageCode: 'en',
74+
treatmentContent: 'content',
75+
treatmentType: 'type',
76+
surface: 'surface',
77+
},
78+
},
79+
};
80+
(
81+
buildAuxiaGateDisplayData as jest.MockedFunction<
82+
typeof buildAuxiaGateDisplayData
83+
>
84+
).mockResolvedValue(auxiaReturn);
85+
86+
const result = await canShowSignInGatePortal(
87+
false, // isSignedIn
88+
false, // isPaidContent
89+
false, // isPreview
90+
'page-id', // pageId
91+
'https://contributions.local', // contributionsServiceUrl
92+
'UK', // editionId
93+
'Article', // contentType (must be a valid content type)
94+
'section', // sectionId
95+
[], // tags
96+
() => 0, // retrieveDismissedCount
97+
);
5698

57-
expect(result).toEqual({ show: true, meta: undefined });
99+
expect(result).toEqual({ show: true, meta: auxiaReturn });
58100
});
59101

60-
it('should return false when isSignedIn is undefined but truthy check would pass', async () => {
102+
it('should return true when isSignedIn is undefined but other params allow gate', async () => {
61103
const mockElement = document.createElement('div');
62104
mockGetElementById.mockReturnValue(mockElement);
63105

106+
const auxiaReturn: AuxiaGateDisplayData = {
107+
browserId: 'browser-2',
108+
auxiaData: {
109+
responseId: 'resp2',
110+
userTreatment: {
111+
treatmentId: 't2',
112+
treatmentTrackingId: 'tt2',
113+
rank: '1',
114+
contentLanguageCode: 'en',
115+
treatmentContent: 'content',
116+
treatmentType: 'type',
117+
surface: 'surface',
118+
},
119+
},
120+
};
121+
(
122+
buildAuxiaGateDisplayData as jest.MockedFunction<
123+
typeof buildAuxiaGateDisplayData
124+
>
125+
).mockResolvedValue(auxiaReturn);
126+
64127
const result = await canShowSignInGatePortal(
65128
undefined,
66129
false,
67130
false,
131+
'page-id',
132+
'https://contributions.local',
133+
'UK',
134+
'Article',
135+
'section',
136+
[],
137+
() => 0,
68138
);
69139

70-
expect(result).toEqual({ show: true, meta: undefined });
140+
expect(result).toEqual({ show: true, meta: auxiaReturn });
71141
});
72142
});
73143
});

0 commit comments

Comments
 (0)