chore: fix up tests for globals, hooks, localization
This commit is contained in:
@@ -32,6 +32,7 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
files: ['**/int.spec.ts'],
|
files: ['**/int.spec.ts'],
|
||||||
rules: {
|
rules: {
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||||
'@typescript-eslint/no-use-before-define': 'off',
|
'@typescript-eslint/no-use-before-define': 'off',
|
||||||
'jest/prefer-strict-equal': 'off',
|
'jest/prefer-strict-equal': 'off',
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ describe('globals', () => {
|
|||||||
|
|
||||||
describe('local', () => {
|
describe('local', () => {
|
||||||
it('should save empty json objects', async () => {
|
it('should save empty json objects', async () => {
|
||||||
const createdJSON = await payload.updateGlobal({
|
const createdJSON: any = await payload.updateGlobal({
|
||||||
slug,
|
slug,
|
||||||
data: {
|
data: {
|
||||||
json: {
|
json: {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { NestedAfterReadHook } from './payload-types'
|
||||||
|
|
||||||
import payload from '../../packages/payload/src'
|
import payload from '../../packages/payload/src'
|
||||||
import { AuthenticationError } from '../../packages/payload/src/errors'
|
import { AuthenticationError } from '../../packages/payload/src/errors'
|
||||||
import { devUser, regularUser } from '../credentials'
|
import { devUser, regularUser } from '../credentials'
|
||||||
@@ -77,7 +79,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 = await payload.create({
|
const document: NestedAfterReadHook = await payload.create({
|
||||||
collection: nestedAfterReadHooksSlug,
|
collection: nestedAfterReadHooksSlug,
|
||||||
data: {
|
data: {
|
||||||
text: 'ok',
|
text: 'ok',
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import {
|
|||||||
relationSpanishTitle,
|
relationSpanishTitle,
|
||||||
relationSpanishTitle2,
|
relationSpanishTitle2,
|
||||||
relationshipLocalizedSlug,
|
relationshipLocalizedSlug,
|
||||||
withLocalizedRelSlug,
|
|
||||||
withRequiredLocalizedFields,
|
|
||||||
spanishLocale,
|
spanishLocale,
|
||||||
spanishTitle,
|
spanishTitle,
|
||||||
|
withLocalizedRelSlug,
|
||||||
|
withRequiredLocalizedFields,
|
||||||
} from './shared'
|
} from './shared'
|
||||||
|
|
||||||
const collection = localizedPostsSlug
|
const collection = localizedPostsSlug
|
||||||
@@ -36,6 +36,7 @@ describe('Localization', () => {
|
|||||||
;({ serverURL } = await initPayloadTest({ __dirname, init: { local: false } }))
|
;({ serverURL } = await initPayloadTest({ __dirname, init: { local: false } }))
|
||||||
config = await configPromise
|
config = await configPromise
|
||||||
|
|
||||||
|
// @ts-expect-error Force typing
|
||||||
post1 = await payload.create({
|
post1 = await payload.create({
|
||||||
collection,
|
collection,
|
||||||
data: {
|
data: {
|
||||||
@@ -43,6 +44,7 @@ describe('Localization', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @ts-expect-error Force typing
|
||||||
postWithLocalizedData = await payload.create({
|
postWithLocalizedData = await payload.create({
|
||||||
collection,
|
collection,
|
||||||
data: {
|
data: {
|
||||||
@@ -89,7 +91,7 @@ describe('Localization', () => {
|
|||||||
|
|
||||||
expect(updated.title).toEqual(spanishTitle)
|
expect(updated.title).toEqual(spanishTitle)
|
||||||
|
|
||||||
const localized = await payload.findByID({
|
const localized: any = await payload.findByID({
|
||||||
collection,
|
collection,
|
||||||
id: post1.id,
|
id: post1.id,
|
||||||
locale: 'all',
|
locale: 'all',
|
||||||
@@ -111,7 +113,7 @@ describe('Localization', () => {
|
|||||||
|
|
||||||
expect(updated.title).toEqual(englishTitle)
|
expect(updated.title).toEqual(englishTitle)
|
||||||
|
|
||||||
const localizedFallback = await payload.findByID({
|
const localizedFallback: any = await payload.findByID({
|
||||||
collection,
|
collection,
|
||||||
id: post1.id,
|
id: post1.id,
|
||||||
locale: 'all',
|
locale: 'all',
|
||||||
@@ -131,6 +133,7 @@ describe('Localization', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @ts-expect-error Force typing
|
||||||
localizedPost = await payload.update({
|
localizedPost = await payload.update({
|
||||||
collection,
|
collection,
|
||||||
id,
|
id,
|
||||||
@@ -171,7 +174,7 @@ describe('Localization', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('all locales', async () => {
|
it('all locales', async () => {
|
||||||
const localized = await payload.findByID({
|
const localized: any = await payload.findByID({
|
||||||
collection,
|
collection,
|
||||||
locale: 'all',
|
locale: 'all',
|
||||||
id: localizedPost.id,
|
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 () => {
|
it('by localized field value - alternate locale', async () => {
|
||||||
const result = await payload.find({
|
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 () => {
|
it('by localized field value - opposite locale???', async () => {
|
||||||
const result = await payload.find({
|
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', () => {
|
describe('Localized Relationship', () => {
|
||||||
let localizedRelation: LocalizedPost
|
let localizedRelation: LocalizedPost
|
||||||
@@ -243,6 +246,7 @@ describe('Localization', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @ts-expect-error Force typing
|
||||||
withRelationship = await payload.create({
|
withRelationship = await payload.create({
|
||||||
collection: withLocalizedRelSlug,
|
collection: withLocalizedRelSlug,
|
||||||
data: {
|
data: {
|
||||||
@@ -304,15 +308,16 @@ describe('Localization', () => {
|
|||||||
|
|
||||||
it('populates relationships with all locales', async () => {
|
it('populates relationships with all locales', async () => {
|
||||||
// the relationship fields themselves are localized on this collection
|
// the relationship fields themselves are localized on this collection
|
||||||
const result = await payload.find({
|
const result: any = await payload.find({
|
||||||
collection: relationshipLocalizedSlug,
|
collection: relationshipLocalizedSlug,
|
||||||
locale: 'all',
|
locale: 'all',
|
||||||
depth: 1,
|
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].relationship.en.id).toBeDefined()
|
||||||
expect((result.docs[0].relationMultiRelationTo as any).en.value.id).toBeDefined()
|
expect(result.docs[0].relationshipHasMany.en[0].id).toBeDefined()
|
||||||
expect((result.docs[0].relationMultiRelationToHasMany as any).en[0].value.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()
|
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
|
// Second relationship
|
||||||
const result2 = await payload.find({
|
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 () => {
|
it('specific locale', async () => {
|
||||||
const result = await payload.find({
|
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
|
// First relationship - spanish
|
||||||
const result2 = await queryRelation({
|
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
|
// Second relationship - english
|
||||||
const result3 = await queryRelation({
|
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
|
// Second relationship - spanish
|
||||||
const result4 = await queryRelation({
|
const result4 = await queryRelation({
|
||||||
@@ -509,7 +514,7 @@ describe('Localization', () => {
|
|||||||
|
|
||||||
describe('Localized - arrays with nested localized fields', () => {
|
describe('Localized - arrays with nested localized fields', () => {
|
||||||
it('should allow moving rows and retain existing row locale data', async () => {
|
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',
|
slug: 'global-array',
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -753,7 +758,7 @@ async function createLocalizedPost(data: {
|
|||||||
[spanishLocale]: string
|
[spanishLocale]: string
|
||||||
}
|
}
|
||||||
}): Promise<LocalizedPost> {
|
}): Promise<LocalizedPost> {
|
||||||
const localizedRelation = await payload.create({
|
const localizedRelation: any = await payload.create({
|
||||||
collection,
|
collection,
|
||||||
data: {
|
data: {
|
||||||
title: data.title.en,
|
title: data.title.en,
|
||||||
|
|||||||
Reference in New Issue
Block a user