forked from albumprinter/Editors-QA-Engineer-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
66 lines (61 loc) · 2 KB
/
setup.ts
File metadata and controls
66 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { test as base } from "@playwright/test";
export type TestEnvironment = "test" | "acceptance" | "production";
export type Channel = "bonusprint.co.uk";
export type ArticleType = "HardCoverPhotoBook";
export type TestConfig = {
testEnvironment: TestEnvironment;
getInstantEditorUrl: (channel: Channel, articleType: ArticleType, papId: string) => string;
};
export const testEnvironment: TestEnvironment = getAndValidateEnvironment(process.env.TEST_ENV);
export const test = base.extend<TestConfig>({
testEnvironment: testEnvironment,
getInstantEditorUrl: async ({ testEnvironment }, use) => {
await use(getInstantEditorUrl.bind(this, testEnvironment));
},
});
/**
* @see: packages/e2e/package.json
* Example:
* npx cross-env TEST_ENV=local playwright test
* @param option
* @return option
*/
function getAndValidateEnvironment(option?: string): TestEnvironment {
option = String(option || "").toLowerCase();
switch (option) {
case "":
return "test";
case "test":
case "acceptance":
case "production":
return option as TestEnvironment;
default:
throw Error(`Unknown environment: ${option}.`);
}
}
/**
* @return {string} href
*/
function getInstantEditorUrl(env: TestEnvironment, channel: Channel, articleType: ArticleType, papId: string): string {
const url = new URL("http://localhost/index.html");
switch (env) {
case "test":
url.hostname = `t-dtap.editor.${channel}`;
url.pathname = `/instant` + url.pathname;
break;
case "acceptance":
url.hostname = `a-dtap.editor.${channel}`;
url.pathname = `/instant` + url.pathname;
break;
case "production":
url.hostname = `editor.${channel}`;
url.pathname = `/instant` + url.pathname;
break;
default:
throw Error(`Unknown environment: ${env}.`);
}
url.searchParams.set("articleType", articleType.toLocaleLowerCase());
url.searchParams.set("papId", papId.toUpperCase());
url.searchParams.set("testExecution", "true");
return url.href;
}