-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathhappyPath.email-pin.spec.ts
More file actions
136 lines (116 loc) · 4.89 KB
/
Copy pathhappyPath.email-pin.spec.ts
File metadata and controls
136 lines (116 loc) · 4.89 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { test, expect } from "@playwright/test";
import { ParaModalExamplePage } from "../../../../pages/paraModalExample";
import * as webauthn from "../../../../helpers/webAuthn";
import { logger } from "../../../../helpers/logger";
const PIN = "1234";
test.describe("Para Modal - Email + PIN Authentication", () => {
let originalEnv: Record<string, string | undefined>;
test.beforeEach(() => {
// Store original env
originalEnv = { ...process.env };
// Override env vars for this test
process.env.VITE_PARA_API_KEY =
originalEnv.PARA_ENVIRONMENT === "SANDBOX"
? process.env.PARA_API_KEY_BASIC_LOGIN_SANDBOX
: process.env.PARA_API_KEY_BASIC_LOGIN_BETA;
});
test.afterEach(() => {
// Restore original env
Object.keys(process.env).forEach((key) => {
if (originalEnv[key] !== undefined) {
process.env[key] = originalEnv[key];
} else {
delete process.env[key];
}
});
});
test("happy path - create and login with email and basic login", async ({
browser,
}) => {
// ===== PHASE 1: User Creation with Fresh Context =====
const createContext = await browser.newContext({
permissions: ["clipboard-write", "clipboard-read"],
storageState: { cookies: [], origins: [] },
locale: "en-US",
timezoneId: "America/New_York",
httpCredentials: undefined,
extraHTTPHeaders: {},
});
const createPage = await createContext.newPage();
await webauthn.setIsUserVerifyingPlatformAuthenticatorAvailable(createPage);
const createParaModalPage = new ParaModalExamplePage(createPage);
await createParaModalPage.visit();
const { emailOrPhone, credential, clipboardText } =
await createParaModalPage.createUser({
context: createContext,
isRecoverySecretEnabled: true,
usePhoneNumber: false, // Use email
pin: PIN,
});
// Verify wallet is connected by checking for the address display (with extended timeout)
await expect(
createParaModalPage.page.getByTestId("account-address-display")
).toBeVisible({ timeout: 15000 });
expect(clipboardText).toHaveLength(64);
expect(/^[0-9a-f]+$/.test(clipboardText)).toBeTruthy();
expect(credential).toBeUndefined();
// Get the connected wallet address (displayed in truncated format)
const addressElement = await createParaModalPage.page.getByTestId(
"account-address-display"
);
const createAddressText = await addressElement.textContent();
// Test message signing in creation context
logger.logStep("Testing message signing...");
const testMessage = "Hello Para E2E Test with Email + Passkey!";
const signature = await createParaModalPage.signMessage(testMessage);
expect(signature).toBeTruthy();
expect(signature.length).toBeGreaterThan(0);
expect(signature).toMatch(/^[a-fA-F0-9]+$/);
// Logout in creation context
await createParaModalPage.logout();
// Close the creation context completely
logger.logStep("Closing creation context and clearing all state...");
await createContext.close();
// Add a pause between user creation and login to ensure complete state cleanup
logger.logWait(
"Waiting 3 seconds between user creation and login phases..."
);
await new Promise((resolve) => setTimeout(resolve, 3000));
// ===== PHASE 2: Login with Completely Fresh Context =====
logger.logStep("Creating fresh context for login test...");
const loginContext = await browser.newContext({
permissions: ["clipboard-write", "clipboard-read"],
storageState: { cookies: [], origins: [] },
locale: "en-US",
timezoneId: "America/New_York",
httpCredentials: undefined,
extraHTTPHeaders: {},
});
const loginPage = await loginContext.newPage();
await webauthn.setIsUserVerifyingPlatformAuthenticatorAvailable(loginPage);
const loginParaModalPage = new ParaModalExamplePage(loginPage);
await loginParaModalPage.visit();
// Test login with the same user credentials in fresh context
logger.logStep("Testing login with existing account in fresh context...");
await loginParaModalPage.login({
context: loginContext,
credential,
emailOrPhone,
pin: PIN,
});
// Verify same address after login in fresh context (with extended timeout)
await expect(
loginParaModalPage.page.getByTestId("account-address-display")
).toBeVisible({ timeout: 15000 });
const loginAddressElement = await loginParaModalPage.page.getByTestId(
"account-address-display"
);
const loginAddressText = await loginAddressElement.textContent();
expect(loginAddressText).toBe(createAddressText);
logger.logStep("React Vite E2E test completed successfully", true);
// Cleanup: delete test user
await loginParaModalPage.cleanupTestUser();
// Cleanup: ensure login context is properly closed
await loginContext.close();
});
});