Files
payload/test/versions/seed.ts
Alessio Gravili 17f7b94555 chore: improve test suites, upgrade jest and playwright, add debug utilities for lexical (#4011)
* feat(richtext-lexical): 'bottom' position value for plugins

* feat: TestRecorderFeature

* chore: restructuring to seed and clear db before each test

* chore: make sure all tests pass

* chore: make sure indexes are created in seed.ts - this fixes one erroring test

* chore: speed up test runs through db snapshots

* chore: support drizzle when resetting db

* chore: simplify seeding process, by moving boilerplate db reset / snapshot logic into a wrapper function

* chore: add new seeding process to admin test suite

* chore(deps): upgrade jest and playwright

* chore: make sure mongoose-specific tests are not skipped

* chore: fix point test, which was depending on another test (that's bad!)

* chore: fix incorrect import

* chore: remove unnecessary comments

* chore: clearly label lexicalE2E test file as todo

* chore: simplify seed logic

* chore: move versions test suite to new seed system
2023-11-06 16:38:40 +01:00

87 lines
2.1 KiB
TypeScript

import { type Payload } from '../../packages/payload/src'
import { devUser } from '../credentials'
import { seedDB } from '../helpers/seed'
import { titleToDelete } from './shared'
import { collectionSlugs, draftCollectionSlug } from './slugs'
export async function clearAndSeedEverything(_payload: Payload) {
return await seedDB({
snapshotKey: 'versionsTest',
shouldResetDB: true,
collectionSlugs,
_payload,
seedFunction: async (_payload) => {
const blocksField = [
{
blockType: 'block',
localized: 'text',
text: 'text',
},
]
await Promise.all([
_payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
}),
_payload.create({
collection: draftCollectionSlug,
data: {
blocksField,
description: 'Description',
radio: 'test',
title: 'Draft Title',
},
draft: true,
}),
])
const { id: manyDraftsID } = await _payload.create({
collection: draftCollectionSlug,
data: {
blocksField,
description: 'Description',
radio: 'test',
title: 'Title With Many Versions',
},
draft: true,
})
for (let i = 0; i < 10; i++) {
await _payload.update({
id: manyDraftsID,
collection: draftCollectionSlug,
data: {
title: `Title With Many Versions ${i + 2}`,
},
})
}
await _payload.create({
collection: draftCollectionSlug,
data: {
_status: 'published',
blocksField,
description: 'Description',
radio: 'test',
title: 'Published Title',
},
draft: false,
})
await _payload.create({
collection: draftCollectionSlug,
data: {
blocksField,
description: 'Description',
title: titleToDelete,
},
draft: true,
})
},
})
}