Files
myeasycms-v2/apps/e2e/tests/authentication/auth.po.ts
giancarlo 08c86102d8 Refactor code and improve error handling in authentication methods
This commit contains several changes including the removal of an unused onClick event handler in remove-member-dialog.tsx. It also includes an update to the POST handler in the Webhook route of the database API where the authentication property has been updated. Lastly, it also brings improvements in error handling and logging in various areas, such as e2e authentication tests and the mailbox utility.
2024-05-03 23:56:23 +07:00

86 lines
2.0 KiB
TypeScript

import { Page, expect } from '@playwright/test';
import { Mailbox } from '../utils/mailbox';
export class AuthPageObject {
private readonly page: Page;
private readonly mailbox: Mailbox;
constructor(page: Page) {
this.page = page;
this.mailbox = new Mailbox(page);
}
goToSignIn() {
return this.page.goto('/auth/sign-in');
}
goToSignUp() {
return this.page.goto('/auth/sign-up');
}
async signOut() {
await this.page.click('[data-test="account-dropdown-trigger"]');
await this.page.click('[data-test="account-dropdown-sign-out"]');
}
async signIn(params: { email: string; password: string }) {
await this.page.waitForTimeout(1000);
await this.page.fill('input[name="email"]', params.email);
await this.page.fill('input[name="password"]', params.password);
await this.page.click('button[type="submit"]');
}
async signUp(params: {
email: string;
password: string;
repeatPassword: string;
}) {
await this.page.waitForTimeout(1000);
await this.page.fill('input[name="email"]', params.email);
await this.page.fill('input[name="password"]', params.password);
await this.page.fill('input[name="repeatPassword"]', params.repeatPassword);
await this.page.click('button[type="submit"]');
}
async visitConfirmEmailLink(
email: string,
params: {
deleteAfter: boolean;
} = {
deleteAfter: true,
},
) {
return expect(async () => {
const res = await this.mailbox.visitMailbox(email, params);
console.log(res);
expect(res).not.toBeNull();
}).toPass();
}
createRandomEmail() {
const value = Math.random() * 10000000000;
return `${value.toFixed(0)}@makerkit.dev`;
}
async signUpFlow(path: string) {
const email = this.createRandomEmail();
await this.page.goto(`/auth/sign-up?next=${path}`);
await this.signUp({
email,
password: 'password',
repeatPassword: 'password',
});
await this.visitConfirmEmailLink(email);
}
}