Skip to content

Commit 36c4e5a

Browse files
committed
Tests: Mock coveo credentials
1 parent bb5bfb0 commit 36c4e5a

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

.github/workflows/playwright.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- 'main'
88
pull_request:
99

10+
env:
11+
FRONT_DOOR_USERNAME: ${{ secrets.FRONT_DOOR_USERNAME }}
12+
FRONT_DOOR_PASSWORD: ${{ secrets.FRONT_DOOR_PASSWORD }}
1013
jobs:
1114
playwright:
1215
name: Run Playwright

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.key
55
*~
66
\#*
7+
.env
78

89
# OS Specific #
910
###############

tests/package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"private": "true",
55
"devDependencies": {
6-
"@playwright/test": "1.48.0"
6+
"@playwright/test": "1.48.0",
7+
"dotenv": "^17.2.3"
78
}
89
}

tests/playwright.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { defineConfig, devices } from '@playwright/test';
2+
import dotenv from 'dotenv';
23

34
const BASE_URL = 'http://127.0.0.1';
45
const PORT = 1313;
6+
7+
dotenv.config();
8+
59
export default defineConfig({
610
testDir: './src',
711
fullyParallel: true,

tests/src/coveo.spec.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,41 @@ function buildFilter() {
2323
.replaceAll(' ', '%20');
2424
}
2525

26+
async function mockCoveo(page, request) {
27+
// Get credentials
28+
const tokenBaseURL = 'https://docs-dev.nginx.com';
29+
const tokenEndpoint = '/api/v1/auth/search_token';
30+
const username = process.env.FRONT_DOOR_USERNAME;
31+
const password = process.env.FRONT_DOOR_PASSWORD;
32+
const response = await request.get(tokenBaseURL + tokenEndpoint, {
33+
headers: {
34+
Authorization:
35+
'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
36+
},
37+
});
38+
39+
expect(response.ok()).toBeTruthy();
40+
expect(response.status()).toBe(200);
41+
42+
const credentials = await response.json();
43+
44+
// Mock the local request to be successful, then reload the page.
45+
await page.route(`**${tokenEndpoint}`, async (route) => {
46+
await route.fulfill({
47+
status: 200,
48+
contentType: 'application/json',
49+
body: JSON.stringify(credentials),
50+
});
51+
});
52+
await page.reload();
53+
}
54+
2655
test.describe('Coveo test', () => {
27-
test.beforeEach(async ({ page }) => {
56+
test.beforeEach(async ({ page, request }) => {
2857
await page.goto('/');
2958
await page.waitForLoadState('load');
3059
await waitFor(async () => await handleConsentPopup(page));
60+
await mockCoveo(page, request);
3161
});
3262

3363
test.afterEach(async ({ page }) => {
@@ -58,5 +88,9 @@ test.describe('Coveo test', () => {
5888

5989
// should retain the same link instead of resetting
6090
expect(page.url()).toContain(endpoint);
91+
92+
// reloading should retain the same link instead of resetting
93+
await page.reload();
94+
expect(page.url()).toContain(endpoint);
6195
});
6296
});

0 commit comments

Comments
 (0)