|
| 1 | +import { test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { hash } from '../models/helpers'; |
| 4 | +import { appConfigs } from '../presets'; |
| 5 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 6 | + |
| 7 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasksResetPassword] })( |
| 8 | + 'session tasks after sign-in reset password flow @nextjs', |
| 9 | + ({ app }) => { |
| 10 | + test.describe.configure({ mode: 'parallel' }); |
| 11 | + |
| 12 | + test.afterAll(async () => { |
| 13 | + await app.teardown(); |
| 14 | + }); |
| 15 | + |
| 16 | + test('resolve both reset password and organization selection tasks after sign-in', async ({ page, context }) => { |
| 17 | + const u = createTestUtils({ app, page, context }); |
| 18 | + |
| 19 | + const user = u.services.users.createFakeUser(); |
| 20 | + const createdUser = await u.services.users.createBapiUser(user); |
| 21 | + |
| 22 | + await u.services.users.passwordUntrusted(createdUser.id); |
| 23 | + |
| 24 | + // Performs sign-in |
| 25 | + await u.po.signIn.goTo(); |
| 26 | + await u.po.signIn.setIdentifier(user.email); |
| 27 | + await u.po.signIn.continue(); |
| 28 | + await u.po.signIn.setPassword(user.password); |
| 29 | + await u.po.signIn.continue(); |
| 30 | + |
| 31 | + await u.page.getByRole('textbox', { name: 'code' }).click(); |
| 32 | + await u.page.keyboard.type('424242', { delay: 100 }); |
| 33 | + |
| 34 | + // Redirects back to tasks when accessing protected route by `auth.protect` |
| 35 | + await u.page.goToRelative('/page-protected'); |
| 36 | + |
| 37 | + const newPassword = `${hash()}_testtest`; |
| 38 | + await u.po.sessionTask.resolveResetPasswordTask({ |
| 39 | + newPassword: newPassword, |
| 40 | + confirmPassword: newPassword, |
| 41 | + }); |
| 42 | + |
| 43 | + await u.po.sessionTask.resolveForceOrganizationSelectionTask({ |
| 44 | + name: 'Test Organization', |
| 45 | + }); |
| 46 | + |
| 47 | + // Navigates to after sign-in |
| 48 | + await u.page.waitForAppUrl('/page-protected'); |
| 49 | + |
| 50 | + await u.page.signOut(); |
| 51 | + await u.page.context().clearCookies(); |
| 52 | + |
| 53 | + await user.deleteIfExists(); |
| 54 | + await u.services.organizations.deleteAll(); |
| 55 | + }); |
| 56 | + |
| 57 | + test('sign-in with email and resolve the reset password task', async ({ page, context }) => { |
| 58 | + const u = createTestUtils({ app, page, context }); |
| 59 | + const user = u.services.users.createFakeUser(); |
| 60 | + const createdUser = await u.services.users.createBapiUser(user); |
| 61 | + |
| 62 | + await u.services.users.passwordUntrusted(createdUser.id); |
| 63 | + const fakeOrganization = u.services.organizations.createFakeOrganization(); |
| 64 | + await u.services.organizations.createBapiOrganization({ |
| 65 | + ...fakeOrganization, |
| 66 | + createdBy: createdUser.id, |
| 67 | + }); |
| 68 | + |
| 69 | + // Performs sign-in |
| 70 | + await u.po.signIn.goTo(); |
| 71 | + await u.po.signIn.setIdentifier(user.email); |
| 72 | + await u.po.signIn.continue(); |
| 73 | + await u.po.signIn.setPassword(user.password); |
| 74 | + await u.po.signIn.continue(); |
| 75 | + |
| 76 | + await u.page.getByRole('textbox', { name: 'code' }).fill('424242'); |
| 77 | + |
| 78 | + await u.po.expect.toBeSignedIn(); |
| 79 | + |
| 80 | + // Redirects back to tasks when accessing protected route by `auth.protect` |
| 81 | + await u.page.goToRelative('/page-protected'); |
| 82 | + |
| 83 | + const newPassword = `${hash()}_testtest`; |
| 84 | + await u.po.sessionTask.resolveResetPasswordTask({ |
| 85 | + newPassword: newPassword, |
| 86 | + confirmPassword: newPassword, |
| 87 | + }); |
| 88 | + |
| 89 | + // Navigates to after sign-in |
| 90 | + await u.page.waitForAppUrl('/page-protected'); |
| 91 | + |
| 92 | + await u.page.signOut(); |
| 93 | + await u.page.context().clearCookies(); |
| 94 | + |
| 95 | + await user.deleteIfExists(); |
| 96 | + await u.services.organizations.deleteAll(); |
| 97 | + }); |
| 98 | + }, |
| 99 | +); |
0 commit comments