From 26955bb331e2511ae595699b0dcede16f1b47e70 Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Fri, 15 Sep 2023 17:07:22 -0400 Subject: [PATCH] chore: fix up tests for globals, hooks, localization --- test/.eslintrc.cjs | 1 + test/globals/int.spec.ts | 2 +- test/hooks/int.spec.ts | 4 ++- test/localization/int.spec.ts | 57 +++++++++++++++++++---------------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/test/.eslintrc.cjs b/test/.eslintrc.cjs index 865656a50..cbda3d2e7 100644 --- a/test/.eslintrc.cjs +++ b/test/.eslintrc.cjs @@ -32,6 +32,7 @@ module.exports = { { files: ['**/int.spec.ts'], rules: { + '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-use-before-define': 'off', 'jest/prefer-strict-equal': 'off', diff --git a/test/globals/int.spec.ts b/test/globals/int.spec.ts index 34f27767a..5cf171194 100644 --- a/test/globals/int.spec.ts +++ b/test/globals/int.spec.ts @@ -70,7 +70,7 @@ describe('globals', () => { describe('local', () => { it('should save empty json objects', async () => { - const createdJSON = await payload.updateGlobal({ + const createdJSON: any = await payload.updateGlobal({ slug, data: { json: { diff --git a/test/hooks/int.spec.ts b/test/hooks/int.spec.ts index 2a7207a04..03b6c60fc 100644 --- a/test/hooks/int.spec.ts +++ b/test/hooks/int.spec.ts @@ -1,3 +1,5 @@ +import type { NestedAfterReadHook } from './payload-types' + import payload from '../../packages/payload/src' import { AuthenticationError } from '../../packages/payload/src/errors' import { devUser, regularUser } from '../credentials' @@ -77,7 +79,7 @@ describe('Hooks', () => { }) it('should save data generated with afterRead hooks in nested field structures', async () => { - const document = await payload.create({ + const document: NestedAfterReadHook = await payload.create({ collection: nestedAfterReadHooksSlug, data: { text: 'ok', diff --git a/test/localization/int.spec.ts b/test/localization/int.spec.ts index 29597c3a5..c685e2cf8 100644 --- a/test/localization/int.spec.ts +++ b/test/localization/int.spec.ts @@ -17,10 +17,10 @@ import { relationSpanishTitle, relationSpanishTitle2, relationshipLocalizedSlug, - withLocalizedRelSlug, - withRequiredLocalizedFields, spanishLocale, spanishTitle, + withLocalizedRelSlug, + withRequiredLocalizedFields, } from './shared' const collection = localizedPostsSlug @@ -36,6 +36,7 @@ describe('Localization', () => { ;({ serverURL } = await initPayloadTest({ __dirname, init: { local: false } })) config = await configPromise + // @ts-expect-error Force typing post1 = await payload.create({ collection, data: { @@ -43,6 +44,7 @@ describe('Localization', () => { }, }) + // @ts-expect-error Force typing postWithLocalizedData = await payload.create({ collection, data: { @@ -89,7 +91,7 @@ describe('Localization', () => { expect(updated.title).toEqual(spanishTitle) - const localized = await payload.findByID({ + const localized: any = await payload.findByID({ collection, id: post1.id, locale: 'all', @@ -111,7 +113,7 @@ describe('Localization', () => { expect(updated.title).toEqual(englishTitle) - const localizedFallback = await payload.findByID({ + const localizedFallback: any = await payload.findByID({ collection, id: post1.id, locale: 'all', @@ -131,6 +133,7 @@ describe('Localization', () => { }, }) + // @ts-expect-error Force typing localizedPost = await payload.update({ collection, id, @@ -171,7 +174,7 @@ describe('Localization', () => { }) it('all locales', async () => { - const localized = await payload.findByID({ + const localized: any = await payload.findByID({ collection, locale: 'all', id: localizedPost.id, @@ -191,8 +194,8 @@ describe('Localization', () => { }, }) - expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id); - }); + expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id) + }) it('by localized field value - alternate locale', async () => { const result = await payload.find({ @@ -205,8 +208,8 @@ describe('Localization', () => { }, }) - expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id); - }); + expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id) + }) it('by localized field value - opposite locale???', async () => { const result = await payload.find({ @@ -219,10 +222,10 @@ describe('Localization', () => { }, }) - expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id); - }); - }); - }); + expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id) + }) + }) + }) describe('Localized Relationship', () => { let localizedRelation: LocalizedPost @@ -243,6 +246,7 @@ describe('Localization', () => { }, }) + // @ts-expect-error Force typing withRelationship = await payload.create({ collection: withLocalizedRelSlug, data: { @@ -304,15 +308,16 @@ describe('Localization', () => { it('populates relationships with all locales', async () => { // the relationship fields themselves are localized on this collection - const result = await payload.find({ + const result: any = await payload.find({ collection: relationshipLocalizedSlug, locale: 'all', depth: 1, }) - expect((result.docs[0].relationship as any).en.id).toBeDefined() - expect((result.docs[0].relationshipHasMany as any).en[0].id).toBeDefined() - expect((result.docs[0].relationMultiRelationTo as any).en.value.id).toBeDefined() - expect((result.docs[0].relationMultiRelationToHasMany as any).en[0].value.id).toBeDefined() + + expect(result.docs[0].relationship.en.id).toBeDefined() + expect(result.docs[0].relationshipHasMany.en[0].id).toBeDefined() + expect(result.docs[0].relationMultiRelationTo.en.value.id).toBeDefined() + expect(result.docs[0].relationMultiRelationToHasMany.en[0].value.id).toBeDefined() expect(result.docs[0].arrayField.en[0].nestedRelation.id).toBeDefined() }) }) @@ -328,7 +333,7 @@ describe('Localization', () => { }, }) - expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id); + expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id) // Second relationship const result2 = await payload.find({ @@ -340,8 +345,8 @@ describe('Localization', () => { }, }) - expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id); - }); + expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id) + }) it('specific locale', async () => { const result = await payload.find({ @@ -395,7 +400,7 @@ describe('Localization', () => { }, }) - expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id); + expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id) // First relationship - spanish const result2 = await queryRelation({ @@ -404,7 +409,7 @@ describe('Localization', () => { }, }) - expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id); + expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id) // Second relationship - english const result3 = await queryRelation({ @@ -413,7 +418,7 @@ describe('Localization', () => { }, }) - expect(result3.docs.map(({ id }) => id)).toContain(withRelationship.id); + expect(result3.docs.map(({ id }) => id)).toContain(withRelationship.id) // Second relationship - spanish const result4 = await queryRelation({ @@ -509,7 +514,7 @@ describe('Localization', () => { describe('Localized - arrays with nested localized fields', () => { it('should allow moving rows and retain existing row locale data', async () => { - const globalArray = await payload.findGlobal({ + const globalArray: any = await payload.findGlobal({ slug: 'global-array', }) @@ -753,7 +758,7 @@ async function createLocalizedPost(data: { [spanishLocale]: string } }): Promise { - const localizedRelation = await payload.create({ + const localizedRelation: any = await payload.create({ collection, data: { title: data.title.en,