chore: add e2e tests for creating first user (#6027)
This commit is contained in:
@@ -216,29 +216,31 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
custom: 'Hello, world!',
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
if (process.env.SKIP_ON_INIT !== 'true') {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
custom: 'Hello, world!',
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import { devUser } from 'credentials.js'
|
||||
import path from 'path'
|
||||
import { wait } from 'payload/utilities'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
|
||||
import type { PayloadTestSDK } from '../helpers/sdk/index.js'
|
||||
import type { Config } from './payload-types.js'
|
||||
|
||||
import { initPageConsoleErrorCatch, login, saveDocAndAssert } from '../helpers.js'
|
||||
import { initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
||||
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
||||
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
||||
@@ -19,25 +21,37 @@ const dirname = path.dirname(filename)
|
||||
|
||||
let payload: PayloadTestSDK<Config>
|
||||
|
||||
/**
|
||||
* TODO: Auth
|
||||
* create first user
|
||||
* unlock
|
||||
* log out
|
||||
*/
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
const createFirstUser = async ({ page, serverURL }: { page: Page; serverURL: string }) => {
|
||||
await page.goto(serverURL + '/admin/create-first-user')
|
||||
await page.locator('#field-email').fill(devUser.email)
|
||||
await page.locator('#field-password').fill(devUser.password)
|
||||
await page.locator('#field-confirm-password').fill(devUser.password)
|
||||
await page.locator('#field-custom').fill('Hello, world!')
|
||||
|
||||
await wait(500)
|
||||
|
||||
await page.locator('.form-submit > button').click()
|
||||
|
||||
await expect
|
||||
.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT })
|
||||
.not.toContain('create-first-user')
|
||||
}
|
||||
|
||||
describe('auth', () => {
|
||||
let page: Page
|
||||
let url: AdminUrlUtil
|
||||
let serverURL: string
|
||||
let apiURL: string
|
||||
|
||||
// Allows for testing create-first-user
|
||||
process.env.SKIP_ON_INIT = 'true'
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
|
||||
apiURL = `${serverURL}/api`
|
||||
@@ -47,11 +61,22 @@ describe('auth', () => {
|
||||
page = await context.newPage()
|
||||
initPageConsoleErrorCatch(page)
|
||||
|
||||
//await delayNetwork({ context, page, delay: 'Slow 4G' })
|
||||
await createFirstUser({ page, serverURL })
|
||||
|
||||
await login({
|
||||
page,
|
||||
serverURL,
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: 'api-keys',
|
||||
data: {
|
||||
apiKey: uuid(),
|
||||
enableAPIKey: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -383,9 +383,11 @@ describe('fields - relationship', () => {
|
||||
})
|
||||
|
||||
await page.goto(url.create)
|
||||
|
||||
// wait for relationship options to load
|
||||
const relationFilterOptionsReq = page.waitForResponse(/api\/relation-filter-true/)
|
||||
// select relationshipMany field that relies on siblingData field above
|
||||
await page.locator('#field-relationshipManyFiltered .rs__control').click()
|
||||
await relationFilterOptionsReq
|
||||
|
||||
const options = page.locator('#field-relationshipManyFiltered .rs__menu')
|
||||
await expect(options).toContainText('truth')
|
||||
|
||||
Reference in New Issue
Block a user