Skip to content
Open
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
47 changes: 0 additions & 47 deletions e2etests/api-requests/auth-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,6 @@ export class AuthRequest extends BaseRequest {
});
}

/**
* Creates a new user with the provided email, password, and display name.
* @param {string} email - The email address of the user.
* @param {string} password - The password of the user.
* @param {string} displayName - The display name of the user.
* @returns {Promise<APIResponse>} A promise that resolves to the API response.
* @throws Will throw an error if the user creation fails.
*/
async createUser(email: string, password: string, displayName: string): Promise<APIResponse> {
const response = await this.request.post(this.userEndpoint, {
headers: {
'Content-Type': 'application/json',
Secret: process.env.CLUSTER_SECRET,
},
data: {
email,
display_name: displayName,
password,
verified: true,
},
});

if (response.status() !== 201) {
throw new Error(`Failed to create user: Status ${response.status()}`);
}
return response;
}

/**
* Sets a verification code for a user.
* This method sends a POST request to the verification codes endpoint with the provided email and code.
Expand Down Expand Up @@ -173,23 +145,4 @@ export class AuthRequest extends BaseRequest {
}
return response;
}

/**
* Deletes a user with the provided user ID.
* @param {string} userID - The user identifier.
* @returns {Promise<void>} A promise that resolves when the user is deleted.
* @throws Will throw an error if the user deletion fails.
*/
async deleteUser(userID: string): Promise<void> {
const response = await this.request.delete(`${this.userEndpoint}/${userID}`, {
headers: {
'Content-Type': 'application/json',
Secret: `${process.env.CLUSTER_SECRET}`,
},
});
if (response.status() !== 204) {
throw new Error(`Failed to delete userID ${userID}: response status ${response.status()} reason ${response.statusText}`);
}
console.log(`UserID ${userID} deleted`);
}
}
52 changes: 22 additions & 30 deletions e2etests/fixtures/page.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {test as base, type Page} from '@playwright/test';
import { type Page, test as base } from '@playwright/test';
import * as Pages from '../pages';
import {LiveDemoService} from '../utils/auth-session-storage/auth-helpers';
import {restoreUserSessionInLocalForage} from "../utils/auth-session-storage/localforage-service";
import {BaseRequest} from "../utils/api-requests/base-request";
import {apiInterceptors} from "../utils/api-requests/interceptor";
import {InterceptionEntry} from "../types/interceptor.types";
import { LiveDemoService } from '../utils/auth-session-storage/auth-helpers';
import { restoreUserSessionInLocalForage } from '../utils/auth-session-storage/localforage-service';
import { apiInterceptors } from '../utils/api-interceptor/interceptor';
import { InterceptionEntry } from '../types/interceptor.types';
import { AuthRequest } from '../api-requests/auth-request';

interface Options {
baseRequest: BaseRequest;
authRequest: AuthRequest;
restoreSession?: boolean;
setFixedTime?: boolean;
interceptAPI?: { //List array must be wrapped as object first otherwise it will pass only first array item
interceptAPI?: {
//List array must be wrapped as object first otherwise it will pass only first array item
entries: InterceptionEntry[];
failOnInterceptionMissing?: boolean;
}
};
}

// Generic "new (page) => instance" type for Page Objects
Expand All @@ -22,9 +23,9 @@ type PageObjectCtor<T = unknown> = new (page: Page) => T;
// Build a single fixture from a Page Object constructor
const createFixture =
<T>(Ctor: PageObjectCtor<T>) =>
async ({page}: { page: Page }, use: (po: T) => Promise<void>) => {
await use(new Ctor(page));
};
async ({ page }: { page: Page }, use: (po: T) => Promise<void>) => {
await use(new Ctor(page));
};

// Declare all POs in one place with strong typing
const constructors = {
Expand Down Expand Up @@ -64,15 +65,12 @@ type Fixtures = { [K in keyof Constructors]: InstanceType<Constructors[K]> };

function buildFixtures<C extends Record<string, PageObjectCtor>>(ctors: C) {
const result = {} as {
[K in keyof C]: (
args: { page: Page },
use: (po: InstanceType<C[K]>) => Promise<void>
) => Promise<void>;
[K in keyof C]: (args: { page: Page }, use: (po: InstanceType<C[K]>) => Promise<void>) => Promise<void>;
};

for (const key in ctors) {
const Ctor = ctors[key];
result[key] = createFixture(Ctor) as typeof result[typeof key];
result[key] = createFixture(Ctor) as (typeof result)[typeof key];
}

return result;
Expand All @@ -81,21 +79,17 @@ function buildFixtures<C extends Record<string, PageObjectCtor>>(ctors: C) {
const fixtures = buildFixtures(constructors);

export const test = base.extend<Fixtures & Options>({
restoreSession: [false, {option: true}],
setFixedTime: [false, {option: true}],
interceptAPI: [undefined, {option: true}], // <-- allow full override
restoreSession: [false, { option: true }],
setFixedTime: [false, { option: true }],
interceptAPI: [undefined, { option: true }], // <-- allow full override

page: async ({page, restoreSession, setFixedTime, interceptAPI}, use) => {
page: async ({ page, restoreSession, setFixedTime, interceptAPI }, use) => {
let verifyInterceptions: (() => void) | undefined;
if (restoreSession) {
await restoreUserSessionInLocalForage(page, setFixedTime);
}
if (interceptAPI?.entries?.length > 0) {
verifyInterceptions = await apiInterceptors(
page,
interceptAPI.entries,
interceptAPI.failOnInterceptionMissing
);
verifyInterceptions = await apiInterceptors(page, interceptAPI.entries, interceptAPI.failOnInterceptionMissing);
}
if (process.env.BROWSER_ERROR_LOGGING === 'true') {
page.on('console', msg => {
Expand All @@ -110,11 +104,9 @@ export const test = base.extend<Fixtures & Options>({
verifyInterceptions();
}
},

baseRequest: async ({request}, use) => {
await use(new BaseRequest(request));
authRequest: async ({ request }, use) => {
await use(new AuthRequest(request));
},

storageState: async ({}, use) => {
await use(LiveDemoService.getDefaultUserStorageState());
},
Expand Down
56 changes: 12 additions & 44 deletions e2etests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2etests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.36.0",
"@playwright/test": "^1.49.1",
"@playwright/test": "^1.57.0",
"@types/node": "^22.10.5",
"@types/pngjs": "^6.0.5",
"cross-env": "^7.0.3",
Expand Down
Loading
Loading