From 96012b26b7eb0d98fa3315fdb8940e42e851f0d3 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 4 Apr 2024 18:00:37 -0400 Subject: [PATCH] chore: properly isolates req in parallel requests --- packages/payload/src/auth/getAccessResults.ts | 22 +- .../queryValidation/validateSearchParams.ts | 12 +- test/admin/config.ts | 4 +- test/admin/seed.ts | 188 +++++++++--------- 4 files changed, 102 insertions(+), 124 deletions(-) diff --git a/packages/payload/src/auth/getAccessResults.ts b/packages/payload/src/auth/getAccessResults.ts index f0afa60413..010b58b35b 100644 --- a/packages/payload/src/auth/getAccessResults.ts +++ b/packages/payload/src/auth/getAccessResults.ts @@ -1,8 +1,8 @@ import type { AllOperations, PayloadRequest } from '../types/index.js' import type { Permissions } from './types.js' -import { createLocalReq } from '../utilities/createLocalReq.js' import { getEntityPolicies } from '../utilities/getEntityPolicies.js' +import isolateObjectProperty from '../utilities/isolateObjectProperty.js' type GetAccessResultsArgs = { req: PayloadRequest @@ -50,15 +50,7 @@ export async function getAccessResults({ req }: GetAccessResultsArgs): Promise

{ if (process.env.SEED_IN_CONFIG_ONINIT !== 'false') { - await clearAndSeedEverything(payload) + await seed(payload) } }, }) diff --git a/test/admin/seed.ts b/test/admin/seed.ts index b691b12a65..d3d818010c 100644 --- a/test/admin/seed.ts +++ b/test/admin/seed.ts @@ -14,102 +14,104 @@ import { usersCollectionSlug, } from './slugs.js' -export async function clearAndSeedEverything(_payload: Payload, parallel: boolean = false) { +export const seed = async (_payload) => { + await executePromises( + [ + () => + _payload.create({ + collection: usersCollectionSlug, + data: { + email: devUser.email, + password: devUser.password, + }, + depth: 0, + overrideAccess: true, + }), + ...[...Array(11)].map( + () => () => + _payload.create({ + collection: postsCollectionSlug, + data: { + title: 'Title', + description: 'Description', + }, + depth: 0, + overrideAccess: true, + }), + ), + () => + _payload.create({ + collection: customViews1CollectionSlug, + data: { + title: 'Custom View', + }, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: customViews2CollectionSlug, + data: { + title: 'Custom View', + }, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: geoCollectionSlug, + data: { + point: [7, -7], + }, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: geoCollectionSlug, + data: { + point: [5, -5], + }, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: noApiViewCollectionSlug, + data: {}, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: 'customIdTab', + data: { + id: customIdCollectionId, + title: 'Hello world title', + }, + depth: 0, + overrideAccess: true, + }), + () => + _payload.create({ + collection: 'customIdRow', + data: { + id: customIdCollectionId, + title: 'Hello world title', + }, + depth: 0, + overrideAccess: true, + }), + ], + false, + ) +} + +export async function clearAndSeedEverything(_payload: Payload) { return await seedDB({ snapshotKey: 'adminTest', collectionSlugs, _payload, - seedFunction: async (_payload) => { - await executePromises( - [ - () => - _payload.create({ - collection: usersCollectionSlug, - data: { - email: devUser.email, - password: devUser.password, - }, - depth: 0, - overrideAccess: true, - }), - ...[...Array(11)].map( - () => () => - _payload.create({ - collection: postsCollectionSlug, - data: { - title: 'Title', - description: 'Description', - }, - depth: 0, - overrideAccess: true, - }), - ), - () => - _payload.create({ - collection: customViews1CollectionSlug, - data: { - title: 'Custom View', - }, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: customViews2CollectionSlug, - data: { - title: 'Custom View', - }, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: geoCollectionSlug, - data: { - point: [7, -7], - }, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: geoCollectionSlug, - data: { - point: [5, -5], - }, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: noApiViewCollectionSlug, - data: {}, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: 'customIdTab', - data: { - id: customIdCollectionId, - title: 'Hello world title', - }, - depth: 0, - overrideAccess: true, - }), - () => - _payload.create({ - collection: 'customIdRow', - data: { - id: customIdCollectionId, - title: 'Hello world title', - }, - depth: 0, - overrideAccess: true, - }), - ], - parallel, - ) - }, + seedFunction: seed, }) }