|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { appConfigs } from '../presets'; |
| 4 | +import type { FakeUser } from '../testUtils'; |
| 5 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 6 | + |
| 7 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withNeedsClientTrust] })( |
| 8 | + 'client trust flow @generic @nextjs', |
| 9 | + ({ app }) => { |
| 10 | + test.describe.configure({ mode: 'serial' }); |
| 11 | + |
| 12 | + let fakeUser: FakeUser; |
| 13 | + |
| 14 | + test.beforeAll(async () => { |
| 15 | + const u = createTestUtils({ app }); |
| 16 | + fakeUser = u.services.users.createFakeUser(); |
| 17 | + await u.services.users.createBapiUser(fakeUser); |
| 18 | + }); |
| 19 | + |
| 20 | + test.afterAll(async () => { |
| 21 | + await fakeUser.deleteIfExists(); |
| 22 | + await app.teardown(); |
| 23 | + }); |
| 24 | + |
| 25 | + test('sign in with email and password results in needs_client_trust', async ({ page, context }) => { |
| 26 | + const u = createTestUtils({ app, page, context }); |
| 27 | + |
| 28 | + // Sign in with a new device |
| 29 | + await u.po.signIn.goTo(); |
| 30 | + await u.po.signIn.setIdentifier(fakeUser.email); |
| 31 | + await u.po.signIn.continue(); |
| 32 | + await u.po.signIn.setPassword(fakeUser.password); |
| 33 | + await u.po.signIn.continue(); |
| 34 | + |
| 35 | + // After password is correctly entered, should navigate to client-trust route |
| 36 | + // This verifies that the sign-in status is 'needs_client_trust' |
| 37 | + await u.page.waitForURL(/\/sign-in\/client-trust/); |
| 38 | + |
| 39 | + // Should contain the new device verification notice |
| 40 | + await expect(u.page.getByText("You're signing in from a new device.")).toBeVisible(); |
| 41 | + |
| 42 | + // User should not be signed in yet since client trust step is required |
| 43 | + await u.po.expect.toBeSignedOut(); |
| 44 | + |
| 45 | + await u.po.signIn.enterTestOtpCode(); |
| 46 | + await u.po.expect.toBeSignedIn(); |
| 47 | + |
| 48 | + await u.po.userButton.toggleTrigger(); |
| 49 | + await u.po.userButton.waitForPopover(); |
| 50 | + await u.po.userButton.triggerSignOut(); |
| 51 | + |
| 52 | + await u.po.expect.toBeSignedOut(); |
| 53 | + |
| 54 | + await u.po.signIn.goTo(); |
| 55 | + await u.po.signIn.signInWithEmailAndInstantPassword({ |
| 56 | + email: fakeUser.email, |
| 57 | + password: fakeUser.password, |
| 58 | + }); |
| 59 | + |
| 60 | + // Sign in again with a now "known" device |
| 61 | + await u.po.expect.toBeSignedIn(); |
| 62 | + }); |
| 63 | + }, |
| 64 | +); |
0 commit comments