chore: remove async seeding from auth and fields-relationship test suites

This commit is contained in:
Alessio Gravili
2024-04-02 13:25:12 -04:00
parent 4ff7619356
commit dc33d96a54
3 changed files with 54 additions and 27 deletions

View File

@@ -1,4 +1,3 @@
import { mapAsync } from 'payload/utilities'
import { v4 as uuid } from 'uuid'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
@@ -226,14 +225,20 @@ export default buildConfigWithDefaults({
},
})
await mapAsync([...Array(2)], async () => {
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,
},
})
},
})

View File

@@ -2,7 +2,6 @@ import type { CollectionConfig } from 'payload/types'
import type { FilterOptionsProps } from 'payload/types'
import { withMergedProps } from '@payloadcms/ui/elements/withMergedProps'
import { mapAsync } from 'payload/utilities'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
@@ -334,6 +333,8 @@ export default buildConfigWithDefaults({
email: devUser.email,
password: devUser.password,
},
depth: 0,
overrideAccess: true,
})
// Create docs to relate to
const { id: relationOneDocId } = await payload.create({
@@ -341,29 +342,36 @@ export default buildConfigWithDefaults({
data: {
name: relationOneSlug,
},
depth: 0,
overrideAccess: true,
})
const relationOneIDs: string[] = []
await mapAsync([...Array(11)], async () => {
for (let i = 0; i < 11; i++) {
const doc = await payload.create({
collection: relationOneSlug,
data: {
name: relationOneSlug,
},
depth: 0,
overrideAccess: true,
})
relationOneIDs.push(doc.id)
})
}
const relationTwoIDs: string[] = []
await mapAsync([...Array(11)], async () => {
for (let i = 0; i < 11; i++) {
const doc = await payload.create({
collection: relationTwoSlug,
data: {
name: relationTwoSlug,
},
depth: 0,
overrideAccess: true,
})
relationTwoIDs.push(doc.id)
})
}
// Existing relationships
const { id: restrictedDocId } = await payload.create({
@@ -371,13 +379,16 @@ export default buildConfigWithDefaults({
data: {
name: 'relation-restricted',
},
depth: 0,
overrideAccess: true,
})
const relationsWithTitle: string[] = []
await mapAsync(['relation-title', 'word boundary search'], async (title) => {
for (const title of ['relation-title', 'word boundary search']) {
const { id } = await payload.create({
collection: relationWithTitleSlug,
depth: 0,
overrideAccess: true,
data: {
name: title,
meta: {
@@ -386,19 +397,24 @@ export default buildConfigWithDefaults({
},
})
relationsWithTitle.push(id)
})
}
await payload.create({
collection: slug,
depth: 0,
overrideAccess: true,
data: {
relationship: relationOneDocId,
relationshipRestricted: restrictedDocId,
relationshipWithTitle: relationsWithTitle[0],
},
})
await mapAsync([...Array(11)], async () => {
for (let i = 0; i < 11; i++) {
await payload.create({
collection: slug,
depth: 0,
overrideAccess: true,
data: {
relationship: relationOneDocId,
relationshipHasManyMultiple: relationOneIDs.map((id) => ({
@@ -408,13 +424,15 @@ export default buildConfigWithDefaults({
relationshipRestricted: restrictedDocId,
},
})
})
}
await mapAsync([...Array(15)], async () => {
for (let i = 0; i < 15; i++) {
const relationOneID = relationOneIDs[Math.floor(Math.random() * 10)]
const relationTwoID = relationTwoIDs[Math.floor(Math.random() * 10)]
await payload.create({
collection: slug,
depth: 0,
overrideAccess: true,
data: {
relationship: relationOneDocId,
relationshipHasMany: [relationOneID],
@@ -423,20 +441,25 @@ export default buildConfigWithDefaults({
relationshipRestricted: restrictedDocId,
},
})
})
;[...Array(15)].forEach((_, i) => {
void payload.create({
}
for (let i = 0; i < 15; i++) {
await payload.create({
collection: collection1Slug,
depth: 0,
overrideAccess: true,
data: {
name: `relationship-test ${i}`,
},
})
void payload.create({
await payload.create({
collection: collection2Slug,
depth: 0,
overrideAccess: true,
data: {
name: `relationship-test ${i}`,
},
})
})
}
},
})

View File

@@ -27,7 +27,6 @@ import {
relationWithTitleSlug,
slug,
} from './collectionSlugs.js'
import config from './config.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -48,7 +47,7 @@ describe('fields - relationship', () => {
let serverURL: string
beforeAll(async ({ browser }) => {
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
url = new AdminUrlUtil(serverURL, slug)