2024-06-20 19:19:01 +03:00
|
|
|
/** @file Test the login flow. */
|
|
|
|
import * as test from '@playwright/test'
|
|
|
|
|
|
|
|
import * as actions from './actions'
|
2024-07-16 12:55:45 +03:00
|
|
|
import type * as api from './api'
|
2024-06-20 19:19:01 +03:00
|
|
|
|
|
|
|
// =================
|
|
|
|
// === Constants ===
|
|
|
|
// =================
|
|
|
|
|
|
|
|
const EMAIL = 'example.email+1234@testing.org'
|
|
|
|
const NAME = 'a custom user name'
|
|
|
|
const ORGANIZATION_ID = 'some testing organization id'
|
|
|
|
|
|
|
|
// =============
|
|
|
|
// === Tests ===
|
|
|
|
// =============
|
|
|
|
|
|
|
|
// Note: This does not check that the organization ID is sent in the correct format for the backend.
|
|
|
|
// It only checks that the organization ID is sent in certain places.
|
|
|
|
test.test('sign up with organization id', async ({ page }) => {
|
|
|
|
await page.goto('/')
|
|
|
|
await page.waitForLoadState('domcontentloaded')
|
|
|
|
await page.goto(
|
|
|
|
'/registration?' + new URLSearchParams([['organization_id', ORGANIZATION_ID]]).toString()
|
|
|
|
)
|
|
|
|
const api = await actions.mockApi({ page })
|
|
|
|
api.setCurrentUser(null)
|
|
|
|
|
|
|
|
// Sign up
|
|
|
|
await actions.locateEmailInput(page).fill(actions.VALID_EMAIL)
|
|
|
|
await actions.locatePasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateConfirmPasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateRegisterButton(page).click()
|
|
|
|
|
|
|
|
// Log in
|
|
|
|
await actions.locateEmailInput(page).fill(actions.VALID_EMAIL)
|
|
|
|
await actions.locatePasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateLoginButton(page).click()
|
|
|
|
await actions.passTermsAndConditionsDialog({ page })
|
|
|
|
|
|
|
|
// Set username
|
|
|
|
await actions.locateUsernameInput(page).fill('arbitrary username')
|
|
|
|
await actions.locateSetUsernameButton(page).click()
|
|
|
|
|
|
|
|
test
|
|
|
|
.expect(api.currentUser()?.organizationId, 'new user has correct organization id')
|
|
|
|
.toBe(ORGANIZATION_ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
test.test('sign up without organization id', async ({ page }) => {
|
|
|
|
await page.goto('/')
|
|
|
|
await page.waitForLoadState('domcontentloaded')
|
|
|
|
await page.goto('/registration')
|
|
|
|
const api = await actions.mockApi({ page })
|
|
|
|
api.setCurrentUser(null)
|
|
|
|
|
|
|
|
// Sign up
|
|
|
|
await actions.locateEmailInput(page).fill(actions.VALID_EMAIL)
|
|
|
|
await actions.locatePasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateConfirmPasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateRegisterButton(page).click()
|
|
|
|
|
|
|
|
// Log in
|
|
|
|
await actions.locateEmailInput(page).fill(actions.VALID_EMAIL)
|
|
|
|
await actions.locatePasswordInput(page).fill(actions.VALID_PASSWORD)
|
|
|
|
await actions.locateLoginButton(page).click()
|
|
|
|
await actions.passTermsAndConditionsDialog({ page })
|
|
|
|
|
|
|
|
// Set username
|
|
|
|
await actions.locateUsernameInput(page).fill('arbitrary username')
|
|
|
|
await actions.locateSetUsernameButton(page).click()
|
|
|
|
|
|
|
|
test
|
|
|
|
.expect(api.currentUser()?.organizationId, 'new user has correct organization id')
|
|
|
|
.toBe(api.defaultOrganizationId)
|
|
|
|
})
|
|
|
|
|
2024-07-16 12:55:45 +03:00
|
|
|
test.test('sign up flow', ({ page }) => {
|
|
|
|
let api!: api.MockApi
|
|
|
|
return actions
|
|
|
|
.mockAll({
|
|
|
|
page,
|
|
|
|
setupAPI: theApi => {
|
|
|
|
api = theApi
|
|
|
|
theApi.setCurrentUser(null)
|
|
|
|
|
|
|
|
// These values should be different, otherwise the email and name may come from the defaults.
|
|
|
|
test.expect(EMAIL).not.toStrictEqual(theApi.defaultEmail)
|
|
|
|
test.expect(NAME).not.toStrictEqual(theApi.defaultName)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.loginAsNewUser(EMAIL, actions.VALID_PASSWORD)
|
|
|
|
.do(async thePage => {
|
|
|
|
await actions.passTermsAndConditionsDialog({ page: thePage })
|
|
|
|
})
|
|
|
|
.setUsername(NAME)
|
|
|
|
.do(async thePage => {
|
|
|
|
await test.expect(actions.locateUpgradeButton(thePage)).toBeVisible()
|
|
|
|
await test.expect(actions.locateDriveView(thePage)).not.toBeVisible()
|
|
|
|
})
|
|
|
|
.do(() => {
|
|
|
|
// Logged in, and account enabled
|
|
|
|
const currentUser = api.currentUser()
|
|
|
|
test.expect(currentUser).toBeDefined()
|
|
|
|
if (currentUser != null) {
|
|
|
|
// This is required because `UserOrOrganization` is `readonly`.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-restricted-syntax, no-extra-semi
|
|
|
|
;(currentUser as { isEnabled: boolean }).isEnabled = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.openUserMenu()
|
|
|
|
.userMenu.logout()
|
|
|
|
.login(EMAIL, actions.VALID_PASSWORD)
|
|
|
|
.do(async () => {
|
|
|
|
await test.expect(actions.locateNotEnabledStub(page)).not.toBeVisible()
|
|
|
|
await test.expect(actions.locateDriveView(page)).toBeVisible()
|
|
|
|
})
|
|
|
|
.do(() => {
|
|
|
|
test.expect(api.currentUser()?.email, 'new user has correct email').toBe(EMAIL)
|
|
|
|
test.expect(api.currentUser()?.name, 'new user has correct name').toBe(NAME)
|
|
|
|
})
|
|
|
|
})
|