|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { appConfigs } from '../presets'; |
| 4 | +import { createTestUtils, type FakeUser, testAgainstRunningApps } from '../testUtils'; |
| 5 | + |
| 6 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withCombinedFlow] })('combined sign in flow @nextjs', ({ app }) => { |
| 7 | + test.describe.configure({ mode: 'serial' }); |
| 8 | + |
| 9 | + let fakeUser: FakeUser; |
| 10 | + |
| 11 | + test.beforeAll(async () => { |
| 12 | + const u = createTestUtils({ app }); |
| 13 | + fakeUser = u.services.users.createFakeUser({ |
| 14 | + withPhoneNumber: true, |
| 15 | + withUsername: true, |
| 16 | + }); |
| 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('flows are combined', async ({ page, context }) => { |
| 26 | + const u = createTestUtils({ app, page, context }); |
| 27 | + await u.po.signIn.goTo(); |
| 28 | + |
| 29 | + await expect(u.page.getByText(`Don’t have an account?`)).toBeHidden(); |
| 30 | + }); |
| 31 | + |
| 32 | + test('sign in with email and password', async ({ page, context }) => { |
| 33 | + const u = createTestUtils({ app, page, context }); |
| 34 | + await u.po.signIn.goTo(); |
| 35 | + await u.po.signIn.setIdentifier(fakeUser.email); |
| 36 | + await u.po.signIn.continue(); |
| 37 | + await u.po.signIn.setPassword(fakeUser.password); |
| 38 | + await u.po.signIn.continue(); |
| 39 | + await u.po.expect.toBeSignedIn(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('sign in with email and instant password', async ({ page, context }) => { |
| 43 | + const u = createTestUtils({ app, page, context }); |
| 44 | + await u.po.signIn.goTo(); |
| 45 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 46 | + await u.po.expect.toBeSignedIn(); |
| 47 | + }); |
| 48 | + |
| 49 | + test('sign in with email code', async ({ page, context }) => { |
| 50 | + const u = createTestUtils({ app, page, context }); |
| 51 | + await u.po.signIn.goTo(); |
| 52 | + await u.po.signIn.getIdentifierInput().fill(fakeUser.email); |
| 53 | + await u.po.signIn.continue(); |
| 54 | + await u.po.signIn.getUseAnotherMethodLink().click(); |
| 55 | + await u.po.signIn.getAltMethodsEmailCodeButton().click(); |
| 56 | + await u.po.signIn.enterTestOtpCode(); |
| 57 | + await u.po.expect.toBeSignedIn(); |
| 58 | + }); |
| 59 | + |
| 60 | + test('sign in with phone number and password', async ({ page, context }) => { |
| 61 | + const u = createTestUtils({ app, page, context }); |
| 62 | + await u.po.signIn.goTo(); |
| 63 | + await u.po.signIn.usePhoneNumberIdentifier().click(); |
| 64 | + await u.po.signIn.getIdentifierInput().fill(fakeUser.phoneNumber); |
| 65 | + await u.po.signIn.setPassword(fakeUser.password); |
| 66 | + await u.po.signIn.continue(); |
| 67 | + await u.po.expect.toBeSignedIn(); |
| 68 | + }); |
| 69 | + |
| 70 | + test('sign in only with phone number', async ({ page, context }) => { |
| 71 | + const u = createTestUtils({ app, page, context }); |
| 72 | + const fakeUserWithoutPassword = u.services.users.createFakeUser({ |
| 73 | + fictionalEmail: true, |
| 74 | + withPassword: false, |
| 75 | + withPhoneNumber: true, |
| 76 | + }); |
| 77 | + await u.services.users.createBapiUser(fakeUserWithoutPassword); |
| 78 | + await u.po.signIn.goTo(); |
| 79 | + await u.po.signIn.usePhoneNumberIdentifier().click(); |
| 80 | + await u.po.signIn.getIdentifierInput().fill(fakeUserWithoutPassword.phoneNumber); |
| 81 | + await u.po.signIn.continue(); |
| 82 | + await u.po.signIn.enterTestOtpCode(); |
| 83 | + await u.po.expect.toBeSignedIn(); |
| 84 | + |
| 85 | + await fakeUserWithoutPassword.deleteIfExists(); |
| 86 | + }); |
| 87 | + |
| 88 | + test('sign in with username and password', async ({ page, context }) => { |
| 89 | + const u = createTestUtils({ app, page, context }); |
| 90 | + await u.po.signIn.goTo(); |
| 91 | + await u.po.signIn.getIdentifierInput().fill(fakeUser.username); |
| 92 | + await u.po.signIn.setPassword(fakeUser.password); |
| 93 | + await u.po.signIn.continue(); |
| 94 | + await u.po.expect.toBeSignedIn(); |
| 95 | + }); |
| 96 | + |
| 97 | + test('can reset password', async ({ page, context }) => { |
| 98 | + const u = createTestUtils({ app, page, context }); |
| 99 | + const fakeUserWithPasword = u.services.users.createFakeUser({ |
| 100 | + fictionalEmail: true, |
| 101 | + withPassword: true, |
| 102 | + }); |
| 103 | + await u.services.users.createBapiUser(fakeUserWithPasword); |
| 104 | + |
| 105 | + await u.po.signIn.goTo(); |
| 106 | + await u.po.signIn.getIdentifierInput().fill(fakeUserWithPasword.email); |
| 107 | + await u.po.signIn.continue(); |
| 108 | + await u.po.signIn.getForgotPassword().click(); |
| 109 | + await u.po.signIn.getResetPassword().click(); |
| 110 | + await u.po.signIn.enterTestOtpCode(); |
| 111 | + await u.po.signIn.setPassword(`${fakeUserWithPasword.password}_reset`); |
| 112 | + await u.po.signIn.setPasswordConfirmation(`${fakeUserWithPasword.password}_reset`); |
| 113 | + await u.po.signIn.getResetPassword().click(); |
| 114 | + await u.po.expect.toBeSignedIn(); |
| 115 | + |
| 116 | + await fakeUserWithPasword.deleteIfExists(); |
| 117 | + }); |
| 118 | + |
| 119 | + test('cannot sign in with wrong password', async ({ page, context }) => { |
| 120 | + const u = createTestUtils({ app, page, context }); |
| 121 | + |
| 122 | + await u.po.signIn.goTo(); |
| 123 | + await u.po.signIn.getIdentifierInput().fill(fakeUser.email); |
| 124 | + await u.po.signIn.continue(); |
| 125 | + await u.po.signIn.setPassword('wrong-password'); |
| 126 | + await u.po.signIn.continue(); |
| 127 | + await expect(u.page.getByText(/^password is incorrect/i)).toBeVisible(); |
| 128 | + |
| 129 | + await u.po.expect.toBeSignedOut(); |
| 130 | + }); |
| 131 | + |
| 132 | + test('cannot sign in with wrong password but can sign in with email', async ({ page, context }) => { |
| 133 | + const u = createTestUtils({ app, page, context }); |
| 134 | + |
| 135 | + await u.po.signIn.goTo(); |
| 136 | + await u.po.signIn.getIdentifierInput().fill(fakeUser.email); |
| 137 | + await u.po.signIn.continue(); |
| 138 | + await u.po.signIn.setPassword('wrong-password'); |
| 139 | + await u.po.signIn.continue(); |
| 140 | + |
| 141 | + await expect(u.page.getByText(/^password is incorrect/i)).toBeVisible(); |
| 142 | + |
| 143 | + await u.po.signIn.getUseAnotherMethodLink().click(); |
| 144 | + await u.po.signIn.getAltMethodsEmailCodeButton().click(); |
| 145 | + await u.po.signIn.enterTestOtpCode(); |
| 146 | + |
| 147 | + await u.po.expect.toBeSignedIn(); |
| 148 | + }); |
| 149 | + |
| 150 | + test('access protected page @express', async ({ page, context }) => { |
| 151 | + const u = createTestUtils({ app, page, context }); |
| 152 | + await u.po.signIn.goTo(); |
| 153 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 154 | + await u.po.expect.toBeSignedIn(); |
| 155 | + |
| 156 | + expect(await u.page.locator("data-test-id='protected-api-response'").count()).toEqual(0); |
| 157 | + await u.page.goToRelative('/protected'); |
| 158 | + await u.page.isVisible("data-test-id='protected-api-response'"); |
| 159 | + }); |
| 160 | +}); |
0 commit comments