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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { expect, Page } from '@playwright/test';
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
import { Mailbox } from '../utils/mailbox';
|
||||
|
||||
export class AuthPageObject {
|
||||
@@ -23,10 +24,7 @@ export class AuthPageObject {
|
||||
await this.page.click('[data-test="account-dropdown-sign-out"]');
|
||||
}
|
||||
|
||||
async signIn(params: {
|
||||
email: string,
|
||||
password: string
|
||||
}) {
|
||||
async signIn(params: { email: string; password: string }) {
|
||||
await this.page.waitForTimeout(1000);
|
||||
|
||||
await this.page.fill('input[name="email"]', params.email);
|
||||
@@ -35,9 +33,9 @@ export class AuthPageObject {
|
||||
}
|
||||
|
||||
async signUp(params: {
|
||||
email: string,
|
||||
password: string,
|
||||
repeatPassword: string
|
||||
email: string;
|
||||
password: string;
|
||||
repeatPassword: string;
|
||||
}) {
|
||||
await this.page.waitForTimeout(1000);
|
||||
|
||||
@@ -48,14 +46,19 @@ export class AuthPageObject {
|
||||
await this.page.click('button[type="submit"]');
|
||||
}
|
||||
|
||||
async visitConfirmEmailLink(email: string, params: {
|
||||
deleteAfter: boolean
|
||||
} = {
|
||||
deleteAfter: true
|
||||
}) {
|
||||
return expect(async() => {
|
||||
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();
|
||||
}
|
||||
@@ -79,4 +82,4 @@ export class AuthPageObject {
|
||||
|
||||
await this.visitConfirmEmailLink(email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,9 +97,11 @@ test.describe('Full Invitation Flow', () => {
|
||||
// sign out and sign in with the first email
|
||||
await invitations.auth.signOut();
|
||||
|
||||
await invitations.auth.visitConfirmEmailLink(invites[0]!.email);
|
||||
console.log(`Finding email to ${firstEmail} ...`);
|
||||
|
||||
console.log(`Signing up with ${firstEmail}`);
|
||||
await invitations.auth.visitConfirmEmailLink(firstEmail);
|
||||
|
||||
console.log(`Signing up with ${firstEmail} ...`);
|
||||
|
||||
await invitations.auth.signUp({
|
||||
email: firstEmail,
|
||||
|
||||
@@ -2,17 +2,17 @@ import { Page } from '@playwright/test';
|
||||
import { parse } from 'node-html-parser';
|
||||
|
||||
export class Mailbox {
|
||||
constructor(
|
||||
private readonly page: Page
|
||||
) {
|
||||
}
|
||||
constructor(private readonly page: Page) {}
|
||||
|
||||
async visitMailbox(email: string, params?: {
|
||||
deleteAfter: boolean
|
||||
}) {
|
||||
async visitMailbox(
|
||||
email: string,
|
||||
params: {
|
||||
deleteAfter: boolean;
|
||||
},
|
||||
) {
|
||||
const mailbox = email.split('@')[0];
|
||||
|
||||
console.log(`Visiting mailbox ${email} ...`)
|
||||
console.log(`Visiting mailbox ${email} ...`);
|
||||
|
||||
if (!mailbox) {
|
||||
throw new Error('Invalid email');
|
||||
@@ -20,10 +20,12 @@ export class Mailbox {
|
||||
|
||||
const json = await this.getInviteEmail(mailbox, params);
|
||||
|
||||
if (!json.body) {
|
||||
if (!json?.body) {
|
||||
throw new Error('Email body was not found');
|
||||
}
|
||||
|
||||
console.log('Email found');
|
||||
|
||||
const html = (json.body as { html: string }).html;
|
||||
const el = parse(html);
|
||||
|
||||
@@ -40,9 +42,9 @@ export class Mailbox {
|
||||
|
||||
async getInviteEmail(
|
||||
mailbox: string,
|
||||
params = {
|
||||
deleteAfter: false,
|
||||
}
|
||||
params: {
|
||||
deleteAfter: boolean;
|
||||
},
|
||||
) {
|
||||
const url = `http://localhost:54324/api/v1/mailbox/${mailbox}`;
|
||||
|
||||
@@ -69,11 +71,17 @@ export class Mailbox {
|
||||
|
||||
// delete message
|
||||
if (params.deleteAfter) {
|
||||
await fetch(messageUrl, {
|
||||
method: 'DELETE'
|
||||
console.log(`Deleting email ${messageId} ...`);
|
||||
|
||||
const res = await fetch(messageUrl, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.error(`Failed to delete email: ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
|
||||
return await messageResponse.json();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user