test: misc test dir type fixes

This commit is contained in:
Elliot DeNolf
2024-03-21 11:51:22 -04:00
parent a3df2ca0ef
commit c1e1cd0596
8 changed files with 23 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
import type { SanitizedConfig } from 'payload/config' import type { SanitizedConfig } from 'payload/config'
import { APIError } from '../../packages/payload/src/errors/index.js' import { APIError } from 'payload/errors'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import AfterOperation from './collections/AfterOperation/index.js' import AfterOperation from './collections/AfterOperation/index.js'
import ChainingHooks from './collections/ChainingHooks/index.js' import ChainingHooks from './collections/ChainingHooks/index.js'

View File

@@ -116,7 +116,7 @@ describe('Hooks', () => {
}) })
it('should save data generated with afterRead hooks in nested field structures', async () => { it('should save data generated with afterRead hooks in nested field structures', async () => {
const document: NestedAfterReadHook = await payload.create({ const document = await payload.create({
collection: nestedAfterReadHooksSlug, collection: nestedAfterReadHooksSlug,
data: { data: {
group: { group: {

View File

@@ -17,7 +17,6 @@ export default function deepMerge<T extends object, R extends object>(target: T,
if (isObject(target) && isObject(source)) { if (isObject(target) && isObject(source)) {
Object.keys(source).forEach((key) => { Object.keys(source).forEach((key) => {
if (isObject(source[key])) { if (isObject(source[key])) {
// @ts-expect-error
if (!(key in target)) { if (!(key in target)) {
Object.assign(output, { [key]: source[key] }) Object.assign(output, { [key]: source[key] })
} else { } else {

View File

@@ -22,27 +22,10 @@ let parentId: string
let draftChildId: string let draftChildId: string
let childId: string let childId: string
type Args = { async function createPage(data: Partial<PayloadPage>): Promise<PayloadPage> {
parent?: string
slug: string
status?: 'draft' | 'published'
title?: string
}
async function createPage({
slug,
title = 'Title page',
parent,
status = 'published',
}: Args): Promise<PayloadPage> {
return payload.create({ return payload.create({
collection: 'pages', collection: 'pages',
data: { data,
title,
slug,
_status: status,
parent,
},
}) as unknown as Promise<PayloadPage> }) as unknown as Promise<PayloadPage>
} }
@@ -65,14 +48,14 @@ describe('Nested Docs Plugin', () => {
}) })
childId = childPage.id childId = childPage.id
const draftParentPage = await createPage({ slug: 'parent-slug-draft', status: 'draft' }) const draftParentPage = await createPage({ slug: 'parent-slug-draft', _status: 'draft' })
draftParentId = draftParentPage.id draftParentId = draftParentPage.id
const draftChildPage = await createPage({ const draftChildPage = await createPage({
slug: 'child-slug-draft', slug: 'child-slug-draft',
title: 'Child page', title: 'Child page',
parent: draftParentId, parent: draftParentId,
status: 'draft', _status: 'draft',
}) })
draftChildId = draftChildPage.id draftChildId = draftChildPage.id
}) })

View File

@@ -52,7 +52,7 @@ describe('SEO Plugin', () => {
}, },
title: 'Test Page', title: 'Test Page',
}, },
})) as unknown as Promise<PayloadPage> })) as unknown as PayloadPage
id = createdPage.id id = createdPage.id
}) })

View File

@@ -64,14 +64,14 @@ describe('Relationships', () => {
const nameToQuery = 'name' const nameToQuery = 'name'
beforeEach(async () => { beforeEach(async () => {
relation = await payload.create<Relation>({ relation = await payload.create({
collection: relationSlug, collection: relationSlug,
data: { data: {
name: nameToQuery, name: nameToQuery,
}, },
}) })
filteredRelation = await payload.create<Relation>({ filteredRelation = await payload.create({
collection: relationSlug, collection: relationSlug,
data: { data: {
name: nameToQuery, name: nameToQuery,
@@ -79,21 +79,21 @@ describe('Relationships', () => {
}, },
}) })
defaultAccessRelation = await payload.create<Relation>({ defaultAccessRelation = await payload.create({
collection: defaultAccessRelSlug, collection: defaultAccessRelSlug,
data: { data: {
name: 'default access', name: 'default access',
}, },
}) })
chained3 = await payload.create<ChainedRelation>({ chained3 = await payload.create({
collection: chainedRelSlug, collection: chainedRelSlug,
data: { data: {
name: 'chain3', name: 'chain3',
}, },
}) })
chained2 = await payload.create<ChainedRelation>({ chained2 = await payload.create({
collection: chainedRelSlug, collection: chainedRelSlug,
data: { data: {
name: 'chain2', name: 'chain2',
@@ -101,7 +101,7 @@ describe('Relationships', () => {
}, },
}) })
chained = await payload.create<ChainedRelation>({ chained = await payload.create({
collection: chainedRelSlug, collection: chainedRelSlug,
data: { data: {
name: 'chain1', name: 'chain1',
@@ -109,7 +109,7 @@ describe('Relationships', () => {
}, },
}) })
chained3 = await payload.update<ChainedRelation>({ chained3 = await payload.update({
id: chained3.id, id: chained3.id,
collection: chainedRelSlug, collection: chainedRelSlug,
data: { data: {
@@ -119,7 +119,7 @@ describe('Relationships', () => {
}) })
generatedCustomId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}` generatedCustomId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`
customIdRelation = await payload.create<CustomIdRelation>({ customIdRelation = await payload.create({
collection: customIdSlug, collection: customIdSlug,
data: { data: {
id: generatedCustomId, id: generatedCustomId,
@@ -128,7 +128,7 @@ describe('Relationships', () => {
}) })
generatedCustomIdNumber = Math.floor(Math.random() * 1_000_000) + 1 generatedCustomIdNumber = Math.floor(Math.random() * 1_000_000) + 1
customIdNumberRelation = await payload.create<CustomIdNumberRelation>({ customIdNumberRelation = await payload.create({
collection: customIdNumberSlug, collection: customIdNumberSlug,
data: { data: {
id: generatedCustomIdNumber, id: generatedCustomIdNumber,
@@ -431,7 +431,7 @@ describe('Relationships', () => {
}, },
}) })
thirdLevelID = thirdLevelDoc.id thirdLevelID = thirdLevelDoc.id as string
const secondLevelDoc = await payload.create({ const secondLevelDoc = await payload.create({
collection: 'chained', collection: 'chained',
@@ -441,7 +441,7 @@ describe('Relationships', () => {
}, },
}) })
secondLevelID = secondLevelDoc.id secondLevelID = secondLevelDoc.id as string
const firstLevelDoc = await payload.create({ const firstLevelDoc = await payload.create({
collection: 'chained', collection: 'chained',
@@ -451,7 +451,7 @@ describe('Relationships', () => {
}, },
}) })
firstLevelID = firstLevelDoc.id firstLevelID = firstLevelDoc.id as string
}) })
it('should allow querying one level deep', async () => { it('should allow querying one level deep', async () => {

View File

@@ -5,7 +5,7 @@ import {
draftCollectionSlug, draftCollectionSlug,
postCollectionSlug, postCollectionSlug,
versionCollectionSlug, versionCollectionSlug,
} from '../slugs' } from '../slugs.js'
const Posts: CollectionConfig = { const Posts: CollectionConfig = {
slug: postCollectionSlug, slug: postCollectionSlug,

View File

@@ -70,7 +70,7 @@ describe('Versions', () => {
title: 'Here is an autosave post in EN', title: 'Here is an autosave post in EN',
}, },
}) })
collectionLocalPostID = autosavePost.id collectionLocalPostID = autosavePost.id as string
await payload.update({ await payload.update({
id: collectionLocalPostID, id: collectionLocalPostID,
@@ -334,7 +334,6 @@ describe('Versions', () => {
draft: true, draft: true,
}) })
// @ts-expect-error
let updatedPost = await payload.update({ let updatedPost = await payload.update({
id: versionedPost.id, id: versionedPost.id,
collection: draftCollectionSlug, collection: draftCollectionSlug,
@@ -350,7 +349,7 @@ describe('Versions', () => {
}, },
draft: true, draft: true,
}) })
// @ts-expect-error
updatedPost = await payload.update({ updatedPost = await payload.update({
id: versionedPost.id, id: versionedPost.id,
collection: draftCollectionSlug, collection: draftCollectionSlug,