-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCorbadoAuthModel.ts
More file actions
85 lines (70 loc) · 3.01 KB
/
CorbadoAuthModel.ts
File metadata and controls
85 lines (70 loc) · 3.01 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
import type { ScreenNames } from '../utils/constants';
import { EmailVerifyBlockModel, OtpCodeType } from './corbado-auth-blocks/EmailVerifyBlockModel';
import { expectScreen } from './corbado-auth-blocks/expectScreen';
import { LoginInitBlockModel } from './corbado-auth-blocks/LoginInitBlockModel';
import { PasskeyAppendBlockModel } from './corbado-auth-blocks/PasskeyAppendBlockModel';
import { PasskeyVerifyBlockModel } from './corbado-auth-blocks/PasskeyVerifyBlockModel';
import { PhoneVerifyBlockModel } from './corbado-auth-blocks/PhoneVerifyBlockModel';
import { SignupInitBlockModel } from './corbado-auth-blocks/SignupInitBlockModel';
import type { VirtualAuthenticator } from './utils/VirtualAuthenticator';
export class CorbadoAuthModel {
projectId = '';
page: Page;
virtualAuthenticator: VirtualAuthenticator;
signupInit: SignupInitBlockModel;
loginInit: LoginInitBlockModel;
passkeyAppend: PasskeyAppendBlockModel;
passkeyVerify: PasskeyVerifyBlockModel;
emailVerify: EmailVerifyBlockModel;
phoneVerify: PhoneVerifyBlockModel;
constructor(page: Page, virtualAuthenticator: VirtualAuthenticator) {
this.page = page;
this.virtualAuthenticator = virtualAuthenticator;
this.signupInit = new SignupInitBlockModel(page);
this.loginInit = new LoginInitBlockModel(page);
this.passkeyAppend = new PasskeyAppendBlockModel(page, virtualAuthenticator);
this.passkeyVerify = new PasskeyVerifyBlockModel(page, virtualAuthenticator);
this.emailVerify = new EmailVerifyBlockModel(page);
this.phoneVerify = new PhoneVerifyBlockModel(page);
}
async load(projectId: string, port: number, passkeySupport?: boolean, hashCode?: string) {
this.projectId = projectId;
let url = `http://localhost:${port.toString()}/${this.projectId}/auth`;
if (hashCode) {
url += `#${hashCode}`;
}
if (passkeySupport !== undefined) {
await this.virtualAuthenticator.addWebAuthn(passkeySupport);
}
await this.page.goto(url);
await this.page.waitForSelector('.cb-container-body');
}
async logout() {
await this.page.getByRole('button', { name: 'Logout' }).click();
}
async defaultSignupWithPasskey() {
const email = SignupInitBlockModel.generateRandomEmail();
await this.signupInit.fillEmail(email);
await this.signupInit.submitPrimary();
await this.passkeyAppend.startPasskeyOperation(true);
await this.logout();
return email;
}
async defaultSignupWithFallback() {
const email = SignupInitBlockModel.generateRandomEmail();
await this.signupInit.fillEmail(email);
await this.signupInit.submitPrimary();
await this.passkeyAppend.navigateFallbackEmail();
await this.emailVerify.fillOtpCode(OtpCodeType.Correct);
await this.logout();
return email;
}
expectScreen(screenName: ScreenNames) {
return expectScreen(this.page, screenName);
}
expectError(value: string) {
return expect(this.page.getByText(value)).toBeVisible();
}
}