Skip to content

Commit af04489

Browse files
force geo-location for banner e2e tests
1 parent f31476d commit af04489

1 file changed

Lines changed: 18 additions & 50 deletions

File tree

dotcom-rendering/playwright/tests/banner.e2e.spec.ts

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,6 @@ const ARTICLE_PATH =
1616
'/Article/https://www.theguardian.com/politics/2019/nov/20/jeremy-corbyn-boris-johnson-tv-debate-watched-by-67-million-people';
1717
const RR_BANNER_URL = 'https://contributions.guardianapis.com/banner';
1818

19-
const isCmpReady = async (page: Page, timeoutMs = 5000): Promise<boolean> => {
20-
const result = await page
21-
.evaluate(
22-
({ timeoutMs: timeout }) =>
23-
new Promise<boolean>((resolve) => {
24-
const start = Date.now();
25-
type TcfApi = (
26-
command: string,
27-
version: number,
28-
callback: (ping: unknown, success: boolean) => void,
29-
) => void;
30-
31-
const check = () => {
32-
const tcfApi = (
33-
window as unknown as Record<string, unknown>
34-
)['__tcfapi'];
35-
36-
if (typeof tcfApi !== 'function') {
37-
if (Date.now() - start >= timeout) {
38-
resolve(false);
39-
return;
40-
}
41-
setTimeout(check, 100);
42-
return;
43-
}
44-
45-
(tcfApi as TcfApi)(
46-
'ping',
47-
2,
48-
(_ping: unknown, pingSuccess: boolean) => {
49-
resolve(pingSuccess);
50-
},
51-
);
52-
};
53-
54-
check();
55-
}),
56-
{ timeoutMs },
57-
)
58-
.catch(() => false);
59-
60-
return result;
61-
};
62-
6319
const requestBodyHasProperties = (
6420
request: Request,
6521
url: string | RegExp,
@@ -102,6 +58,11 @@ test.describe('The banner', function () {
10258
waitUntil: 'domcontentloaded',
10359
region: 'GB',
10460
preventSupportBanner: false,
61+
overrides: {
62+
switchOverrides: {
63+
consentManagement: true,
64+
},
65+
},
10566
});
10667
await cmpAcceptAll(page);
10768

@@ -191,14 +152,15 @@ test.describe('Banner browserId targeting', function () {
191152
waitUntil: 'domcontentloaded',
192153
region: 'GB',
193154
preventSupportBanner: false,
155+
overrides: {
156+
switchOverrides: {
157+
consentManagement: true,
158+
},
159+
},
160+
queryParamsOn: true,
161+
queryParams: { _sp_geo_override: 'GB-XX' },
194162
});
195163

196-
const cmpReady = await isCmpReady(page);
197-
expect(
198-
cmpReady,
199-
'CMP should be ready before running banner consent assertions.',
200-
).toBe(true);
201-
202164
if (acceptConsent) {
203165
await cmpAcceptAll(page);
204166
} else {
@@ -238,6 +200,12 @@ test.describe('Banner browserId targeting', function () {
238200
inAuxiaVariant: true,
239201
});
240202

203+
// CI/CD runs these tests with US geolocation, and fixing the origin to GB in loadPage is not enough for CMP initialization to conclude that the country is GDPR-applied.
204+
// If gdprApplies is false, TCData is allowed to be minimal. If GDPR does not apply to this user in this context then only gdprApplies, tcfPolicyVersion, cmpId and cmpVersion shall exist in the object. (If GDPR does not apply to this user in this context then only gdprApplies, tcfPolicyVersion, cmpId and cmpVersion shall exist in the object.)
205+
// @Guardian/content-management-platform uses the _sp_geo_override query parameter to override geo location in non-production environments.
206+
const currentUrl = new URL(page.url());
207+
expect(currentUrl.searchParams.get('_sp_geo_override')).toBe('GB-XX');
208+
241209
const browserId = getBannerRequestField(
242210
bannerRequest,
243211
RR_BANNER_URL,

0 commit comments

Comments
 (0)