chore: optimize test seed payload.create calls and run them in parallel to reduce MongoDB errors

This commit is contained in:
Alessio Gravili
2024-03-25 23:58:55 -04:00
parent 8a5a08cbe1
commit 56f9c88251
4 changed files with 258 additions and 209 deletions

View File

@@ -1,14 +1,14 @@
import { type Payload } from 'payload'
import { devUser } from '../credentials.js'
import { executePromises } from '../helpers/executePromises.js'
import { seedDB } from '../helpers/seed.js'
import { titleToDelete } from './shared.js'
import { collectionSlugs, draftCollectionSlug } from './slugs.js'
export async function clearAndSeedEverything(_payload: Payload) {
export async function clearAndSeedEverything(_payload: Payload, parallel: boolean = false) {
return await seedDB({
snapshotKey: 'versionsTest',
shouldResetDB: true,
collectionSlugs,
_payload,
seedFunction: async (_payload) => {
@@ -20,25 +20,34 @@ export async function clearAndSeedEverything(_payload: Payload) {
},
]
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,
}),
])
await executePromises(
[
() =>
_payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
depth: 0,
overrideAccess: true,
}),
() =>
_payload.create({
collection: draftCollectionSlug,
data: {
blocksField,
description: 'Description',
radio: 'test',
title: 'Draft Title',
},
depth: 0,
overrideAccess: true,
draft: true,
}),
],
parallel,
)
const { id: manyDraftsID } = await _payload.create({
collection: draftCollectionSlug,
@@ -48,6 +57,8 @@ export async function clearAndSeedEverything(_payload: Payload) {
radio: 'test',
title: 'Title With Many Versions',
},
depth: 0,
overrideAccess: true,
draft: true,
})
@@ -58,6 +69,8 @@ export async function clearAndSeedEverything(_payload: Payload) {
data: {
title: `Title With Many Versions ${i + 2}`,
},
depth: 0,
overrideAccess: true,
})
}
@@ -70,6 +83,8 @@ export async function clearAndSeedEverything(_payload: Payload) {
radio: 'test',
title: 'Published Title',
},
depth: 0,
overrideAccess: true,
draft: false,
})
@@ -80,6 +95,8 @@ export async function clearAndSeedEverything(_payload: Payload) {
description: 'Description',
title: titleToDelete,
},
depth: 0,
overrideAccess: true,
draft: true,
})
},