From 1c9ba5b51261662ae2270698c80d43a4371d9c05 Mon Sep 17 00:00:00 2001 From: Jarrod Flesch Date: Sat, 17 Feb 2024 01:00:48 -0500 Subject: [PATCH] passing relationships int tests --- .../src/routes/rest/collections/updateByID.ts | 53 +++--- packages/payload/src/utilities/isNumber.ts | 2 +- test/helpers/NextRESTClient.ts | 10 +- test/plugin-cloud-storage/int.spec.ts | 13 +- test/plugin-cloud/int.spec.ts | 13 +- test/plugin-form-builder/int.spec.ts | 14 +- test/plugin-nested-docs/int.spec.ts | 14 +- test/plugin-redirects/int.spec.ts | 16 +- test/plugin-search/collections/Pages.ts | 2 +- test/plugin-search/collections/Posts.ts | 2 +- test/plugin-search/collections/Users.ts | 2 +- test/plugin-search/int.spec.ts | 16 +- test/plugin-search/seed/index.ts | 2 +- test/plugin-sentry/int.spec.ts | 13 +- test/plugin-seo/int.spec.ts | 14 +- test/plugin-stripe/int.spec.ts | 12 +- test/plugins/int.spec.ts | 17 +- test/relationships/config.ts | 20 +-- test/relationships/int.spec.ts | 163 ++++++++++++------ test/relationships/shared.ts | 8 + 20 files changed, 252 insertions(+), 154 deletions(-) create mode 100644 test/relationships/shared.ts diff --git a/packages/next/src/routes/rest/collections/updateByID.ts b/packages/next/src/routes/rest/collections/updateByID.ts index 7569c8fb0..3eda6deff 100644 --- a/packages/next/src/routes/rest/collections/updateByID.ts +++ b/packages/next/src/routes/rest/collections/updateByID.ts @@ -10,39 +10,28 @@ export const updateByID: CollectionRouteHandlerWithID = async ({ req, collection const autosave = searchParams.get('autosave') === 'true' const draft = searchParams.get('draft') === 'true' - try { - const doc = await updateByIDOperation({ - id, - autosave, - collection, - data: req.data, - depth: isNumber(depth) ? Number(depth) : undefined, - draft, - req, - }) + const doc = await updateByIDOperation({ + id, + autosave, + collection, + data: req.data, + depth: isNumber(depth) ? Number(depth) : undefined, + draft, + req, + }) - let message = req.t('general:updatedSuccessfully') + let message = req.t('general:updatedSuccessfully') - if (draft) message = req.t('version:draftSavedSuccessfully') - if (autosave) message = req.t('version:autosavedSuccessfully') + if (draft) message = req.t('version:draftSavedSuccessfully') + if (autosave) message = req.t('version:autosavedSuccessfully') - return Response.json( - { - message, - doc, - }, - { - status: httpStatus.OK, - }, - ) - } catch (error) { - return Response.json( - { - message: error.message, - }, - { - status: error.status || httpStatus.INTERNAL_SERVER_ERROR, - }, - ) - } + return Response.json( + { + message, + doc, + }, + { + status: httpStatus.OK, + }, + ) } diff --git a/packages/payload/src/utilities/isNumber.ts b/packages/payload/src/utilities/isNumber.ts index 0f7553aba..d4f676a91 100644 --- a/packages/payload/src/utilities/isNumber.ts +++ b/packages/payload/src/utilities/isNumber.ts @@ -1,5 +1,5 @@ export function isNumber(value: unknown): value is number { - if (typeof value === 'string' && value.trim() === '') { + if (value === null || value === undefined || (typeof value === 'string' && value.trim() === '')) { return false } diff --git a/test/helpers/NextRESTClient.ts b/test/helpers/NextRESTClient.ts index 0dc9ef66b..bfc505603 100644 --- a/test/helpers/NextRESTClient.ts +++ b/test/helpers/NextRESTClient.ts @@ -17,6 +17,7 @@ import { devUser } from '../credentials' type ValidPath = `/${string}` type RequestQuery = { query?: { + depth?: number fallbackLocale?: string limit?: number locale?: string @@ -27,15 +28,10 @@ type RequestQuery = { } function generateQueryString(query: RequestQuery['query'], params: ParsedQs): string { - const { where, limit, page, sort, ...rest } = params || {} - const whereFilter = query?.where || where return QueryString.stringify( { - ...(rest || {}), - ...(whereFilter ? { where: whereFilter } : {}), - limit: query?.limit || limit || undefined, - page: query?.page || page || undefined, - sort: query?.sort || sort || undefined, + ...(params || {}), + ...(query || {}), }, { addQueryPrefix: true, diff --git a/test/plugin-cloud-storage/int.spec.ts b/test/plugin-cloud-storage/int.spec.ts index 924c79e67..92b5e3eee 100644 --- a/test/plugin-cloud-storage/int.spec.ts +++ b/test/plugin-cloud-storage/int.spec.ts @@ -1,8 +1,15 @@ -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' -describe('plugin-cloud-storage', () => { +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload + +describe('@payloadcms/plugin-cloud-storage', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) describe('tests', () => { diff --git a/test/plugin-cloud/int.spec.ts b/test/plugin-cloud/int.spec.ts index 73cb1d72a..cebffc47a 100644 --- a/test/plugin-cloud/int.spec.ts +++ b/test/plugin-cloud/int.spec.ts @@ -1,8 +1,15 @@ -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' -describe('Nested Docs', () => { +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload + +describe('@payloadcms/plugin-cloud', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) describe('tests', () => { diff --git a/test/plugin-form-builder/int.spec.ts b/test/plugin-form-builder/int.spec.ts index 4b5a8b7af..2e0fba1ff 100644 --- a/test/plugin-form-builder/int.spec.ts +++ b/test/plugin-form-builder/int.spec.ts @@ -1,14 +1,18 @@ +import type { Payload } from '../../packages/payload/src' import type { Form } from './payload-types' -import payload from '../../packages/payload/src' -import { initPayloadTest } from '../helpers/configHelpers' +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' import { formSubmissionsSlug, formsSlug } from './shared' -describe('Form Builder Plugin', () => { - let form: Form +let payload: Payload +let form: Form +describe('@payloadcms/plugin-form-builder', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) const formConfig: Omit = { title: 'Test Form', diff --git a/test/plugin-nested-docs/int.spec.ts b/test/plugin-nested-docs/int.spec.ts index ad40e00f1..4351c0e80 100644 --- a/test/plugin-nested-docs/int.spec.ts +++ b/test/plugin-nested-docs/int.spec.ts @@ -1,9 +1,15 @@ -import payload from '../../packages/payload/src' -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' -describe('Nested Docs', () => { +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload + +describe('@payloadcms/plugin-nested-docs', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) describe('seed', () => { diff --git a/test/plugin-redirects/int.spec.ts b/test/plugin-redirects/int.spec.ts index de42b9062..6a7228573 100644 --- a/test/plugin-redirects/int.spec.ts +++ b/test/plugin-redirects/int.spec.ts @@ -1,12 +1,18 @@ -import payload from '../../packages/payload/src' -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' +import type { Page } from './payload-types' + +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' import { pagesSlug } from './shared' -describe('Redirects Plugin', () => { - let page: Page +let payload: Payload +let page: Page +describe('@payloadcms/plugin-redirects', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) page = await payload.create({ collection: 'pages', diff --git a/test/plugin-search/collections/Pages.ts b/test/plugin-search/collections/Pages.ts index 8c46ce121..d70712777 100644 --- a/test/plugin-search/collections/Pages.ts +++ b/test/plugin-search/collections/Pages.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types' +import type { CollectionConfig } from 'payload/dist/collections/config/types' import { pagesSlug } from '../shared' diff --git a/test/plugin-search/collections/Posts.ts b/test/plugin-search/collections/Posts.ts index d5491f05f..7da5427fa 100644 --- a/test/plugin-search/collections/Posts.ts +++ b/test/plugin-search/collections/Posts.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types' +import type { CollectionConfig } from 'payload/dist/collections/config/types' import { postsSlug } from '../shared' diff --git a/test/plugin-search/collections/Users.ts b/test/plugin-search/collections/Users.ts index 8bc9d8176..b080611bd 100644 --- a/test/plugin-search/collections/Users.ts +++ b/test/plugin-search/collections/Users.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types' +import type { CollectionConfig } from 'payload/dist/collections/config/types' export const Users: CollectionConfig = { slug: 'users', diff --git a/test/plugin-search/int.spec.ts b/test/plugin-search/int.spec.ts index aaa364388..046c3738a 100644 --- a/test/plugin-search/int.spec.ts +++ b/test/plugin-search/int.spec.ts @@ -1,10 +1,16 @@ -import payload from '../../packages/payload/src' -import wait from '../../packages/payload/src/utilities/wait' -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' -describe('Search Plugin', () => { +import { getPayload } from '../../packages/payload/src' +import wait from '../../packages/payload/src/utilities/wait' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload + +describe('@payloadcms/plugin-search', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) it('should add a search collection', async () => { diff --git a/test/plugin-search/seed/index.ts b/test/plugin-search/seed/index.ts index 51ea8f0fc..0624709d7 100644 --- a/test/plugin-search/seed/index.ts +++ b/test/plugin-search/seed/index.ts @@ -1,4 +1,4 @@ -import type { Payload } from '../../../packages/payload/src' +import type { Payload } from 'payload' import type { PayloadRequest } from '../../../packages/payload/types' export const seed = async (payload: Payload): Promise => { diff --git a/test/plugin-sentry/int.spec.ts b/test/plugin-sentry/int.spec.ts index 9f3aa676f..00a2caf18 100644 --- a/test/plugin-sentry/int.spec.ts +++ b/test/plugin-sentry/int.spec.ts @@ -1,8 +1,15 @@ -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' -describe('plugin-sentry', () => { +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload + +describe('@payloadcms/plugin-sentry', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) describe('tests', () => { diff --git a/test/plugin-seo/int.spec.ts b/test/plugin-seo/int.spec.ts index 84cc9f13b..b737d648f 100644 --- a/test/plugin-seo/int.spec.ts +++ b/test/plugin-seo/int.spec.ts @@ -1,12 +1,17 @@ import path from 'path' -import payload from '../../packages/payload/src' +import type { Payload } from '../../packages/payload/src' + +import { getPayload } from '../../packages/payload/src' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath' -import { initPayloadTest } from '../helpers/configHelpers' import removeFiles from '../helpers/removeFiles' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' import { mediaSlug } from './shared' -describe('SEO Plugin', () => { +let payload: Payload + +describe('@payloadcms/plugin-seo', () => { let page = null let mediaDoc = null @@ -14,7 +19,8 @@ describe('SEO Plugin', () => { const uploadsDir = path.resolve(__dirname, './media') removeFiles(path.normalize(uploadsDir)) - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) // Create image const filePath = path.resolve(__dirname, './image-1.jpg') diff --git a/test/plugin-stripe/int.spec.ts b/test/plugin-stripe/int.spec.ts index 105ef17bd..8960e8e9a 100644 --- a/test/plugin-stripe/int.spec.ts +++ b/test/plugin-stripe/int.spec.ts @@ -1,9 +1,15 @@ -import payload from '../../packages/payload/src' -import { initPayloadTest } from '../helpers/configHelpers' +import type { Payload } from '../../packages/payload/src' + +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' + +let payload: Payload describe('Stripe Plugin', () => { beforeAll(async () => { - await initPayloadTest({ __dirname, init: { local: true } }) + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) it('should create products', async () => { diff --git a/test/plugins/int.spec.ts b/test/plugins/int.spec.ts index 564eb44e1..46d5b0d2b 100644 --- a/test/plugins/int.spec.ts +++ b/test/plugins/int.spec.ts @@ -1,18 +1,15 @@ -import payload from '../../packages/payload/src' -import { initPayloadTest } from '../helpers/configHelpers' -import { RESTClient } from '../helpers/rest' +import type { Payload } from '../../packages/payload/src' + +import { getPayload } from '../../packages/payload/src' +import { startMemoryDB } from '../startMemoryDB' import configPromise, { pagesSlug } from './config' -require('isomorphic-fetch') - -let client +let payload: Payload describe('Collections - Plugins', () => { beforeAll(async () => { - const { serverURL } = await initPayloadTest({ __dirname, init: { local: false } }) - const config = await configPromise - client = new RESTClient(config, { serverURL, defaultSlug: pagesSlug }) - await client.login() + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) }) it('created pages collection', async () => { diff --git a/test/relationships/config.ts b/test/relationships/config.ts index 46b48f145..4387091ea 100644 --- a/test/relationships/config.ts +++ b/test/relationships/config.ts @@ -2,6 +2,15 @@ import type { CollectionConfig } from '../../packages/payload/src/collections/co import { buildConfigWithDefaults } from '../buildConfigWithDefaults' import { devUser } from '../credentials' +import { + chainedRelSlug, + customIdNumberSlug, + customIdSlug, + defaultAccessRelSlug, + polymorphicRelationshipsSlug, + relationSlug, + slug, +} from './shared' const openAccess = { create: () => true, @@ -36,14 +45,6 @@ const collectionWithName = (collectionSlug: string): CollectionConfig => { } } -export const slug = 'posts' -export const relationSlug = 'relation' -export const defaultAccessRelSlug = 'strict-access' -export const chainedRelSlug = 'chained' -export const customIdSlug = 'custom-id' -export const customIdNumberSlug = 'custom-id-number' -export const polymorphicRelationshipsSlug = 'polymorphic-relationships' - export default buildConfigWithDefaults({ collections: [ { @@ -202,6 +203,7 @@ export default buildConfigWithDefaults({ ], }, { + slug: 'movieReviews', fields: [ { name: 'movieReviewer', @@ -231,8 +233,6 @@ export default buildConfigWithDefaults({ type: 'radio', }, ], - - slug: 'movieReviews', }, { slug: polymorphicRelationshipsSlug, diff --git a/test/relationships/int.spec.ts b/test/relationships/int.spec.ts index d55336e82..340eaf1ed 100644 --- a/test/relationships/int.spec.ts +++ b/test/relationships/int.spec.ts @@ -1,5 +1,6 @@ import { randomBytes } from 'crypto' +import type { Payload } from '../../packages/payload/src' import type { PayloadRequest } from '../../packages/payload/src/types' import type { ChainedRelation, @@ -10,28 +11,34 @@ import type { Relation, } from './payload-types' -import payload from '../../packages/payload/src' +import { getPayload } from '../../packages/payload/src' import { mapAsync } from '../../packages/payload/src/utilities/mapAsync' -import { initPayloadTest } from '../helpers/configHelpers' -import { RESTClient } from '../helpers/rest' -import config, { +import { NextRESTClient } from '../helpers/NextRESTClient' +import { startMemoryDB } from '../startMemoryDB' +import configPromise from './config' +import { chainedRelSlug, customIdNumberSlug, customIdSlug, defaultAccessRelSlug, + polymorphicRelationshipsSlug, relationSlug, slug, -} from './config' + usersSlug, +} from './shared' -let client: RESTClient +let restClient: NextRESTClient +let payload: Payload +let token: string type EasierChained = { id: string; relation: EasierChained } describe('Relationships', () => { beforeAll(async () => { - const { serverURL } = await initPayloadTest({ __dirname, init: { local: false } }) - client = new RESTClient(config, { serverURL, defaultSlug: slug }) - await client.login() + const config = await startMemoryDB(configPromise) + payload = await getPayload({ config }) + restClient = new NextRESTClient(payload.config) + ;({ token } = await restClient.login({ slug: usersSlug }).then((res) => res.json())) }) afterAll(async () => { @@ -146,43 +153,51 @@ describe('Relationships', () => { }) it('should prevent an unauthorized population of strict access', async () => { - const { doc } = await client.findByID({ id: post.id, auth: false }) + const doc = await restClient.GET(`/${slug}/${post.id}`).then((res) => res.json()) expect(doc.defaultAccessRelation).toEqual(defaultAccessRelation.id) }) it('should populate strict access when authorized', async () => { - const { doc } = await client.findByID({ id: post.id }) + const doc = await restClient + .GET(`/${slug}/${post.id}`, { + headers: { + Authorization: `JWT ${token}`, + }, + }) + .then((res) => res.json()) expect(doc.defaultAccessRelation).toEqual(defaultAccessRelation) }) it('should use filterOptions to limit relationship options', async () => { - const { doc } = await client.findByID({ id: post.id }) + const doc = await restClient.GET(`/${slug}/${post.id}`).then((res) => res.json()) expect(doc.filteredRelation).toMatchObject({ id: filteredRelation.id }) - await client.update({ - id: filteredRelation.id, - slug: relationSlug, - data: { disableRelation: true }, + await restClient.PATCH(`/${relationSlug}/${filteredRelation.id}`, { + body: JSON.stringify({ + disableRelation: true, + }), }) - const { doc: docAfterUpdatingRel } = await client.findByID({ id: post.id }) + const updatedDoc = await restClient.GET(`/${slug}/${post.id}`).then((res) => res.json()) // No change to existing relation - expect(docAfterUpdatingRel.filteredRelation).toMatchObject({ id: filteredRelation.id }) + expect(updatedDoc.filteredRelation).toMatchObject({ id: filteredRelation.id }) // Attempt to update post with a now filtered relation - const { status, errors } = await client.update({ - id: post.id, - data: { filteredRelation: filteredRelation.id }, + const response = await restClient.PATCH(`/${slug}/${post.id}`, { + body: JSON.stringify({ + filteredRelation: filteredRelation.id, + }), }) + const result = await response.json() - expect(errors?.[0]).toMatchObject({ + expect(result.errors?.[0]).toMatchObject({ name: 'ValidationError', message: expect.any(String), data: expect.anything(), }) - expect(status).toEqual(400) + expect(response.status).toEqual(400) }) it('should count totalDocs correctly when using or in where query and relation contains hasMany relationship fields', async () => { @@ -254,13 +269,25 @@ describe('Relationships', () => { describe('Custom ID', () => { it('should query a custom id relation', async () => { - const { doc } = await client.findByID({ id: post.id }) - expect(doc?.customIdRelation).toMatchObject({ id: generatedCustomId }) + const { customIdRelation } = await restClient + .GET(`/${slug}/${post.id}`, { + headers: { + Authorization: `JWT ${token}`, + }, + }) + .then((res) => res.json()) + expect(customIdRelation).toMatchObject({ id: generatedCustomId }) }) it('should query a custom id number relation', async () => { - const { doc } = await client.findByID({ id: post.id }) - expect(doc?.customIdNumberRelation).toMatchObject({ id: generatedCustomIdNumber }) + const { customIdNumberRelation } = await restClient + .GET(`/${slug}/${post.id}`, { + headers: { + Authorization: `JWT ${token}`, + }, + }) + .then((res) => res.json()) + expect(customIdNumberRelation).toMatchObject({ id: generatedCustomIdNumber }) }) it('should validate the format of text id relationships', async () => { @@ -284,22 +311,30 @@ describe('Relationships', () => { }) it('should allow update removing a relationship', async () => { - const result = await client.update({ - slug, - id: post.id, - data: { - relationField: null, + const response = await restClient.PATCH(`/${slug}/${post.id}`, { + headers: { + Authorization: `JWT ${token}`, }, + body: JSON.stringify({ + customIdRelation: null, + }), }) + const doc = await response.json() - expect(result.status).toEqual(200) - expect(result.doc.relationField).toBeFalsy() + expect(response.status).toEqual(200) + expect(doc.relationField).toBeFalsy() }) }) describe('depth', () => { it('should populate to depth', async () => { - const { doc } = await client.findByID({ id: post.id, options: { depth: 2 } }) + const doc = await restClient + .GET(`/${slug}/${post.id}`, { + query: { + depth: 2, + }, + }) + .then((res) => res.json()) const depth0 = doc?.chainedRelation as EasierChained expect(depth0.id).toEqual(chained.id) expect(depth0.relation.id).toEqual(chained2.id) @@ -308,12 +343,24 @@ describe('Relationships', () => { }) it('should only populate ID if depth 0', async () => { - const { doc } = await client.findByID({ id: post.id, options: { depth: 0 } }) + const doc = await restClient + .GET(`/${slug}/${post.id}`, { + query: { + depth: 0, + }, + }) + .then((res) => res.json()) expect(doc?.chainedRelation).toEqual(chained.id) }) it('should respect maxDepth at field level', async () => { - const { doc } = await client.findByID({ id: post.id, options: { depth: 1 } }) + const doc = await restClient + .GET(`/${slug}/${post.id}`, { + query: { + depth: 1, + }, + }) + .then((res) => res.json()) expect(doc?.maxDepthRelation).toEqual(relation.id) expect(doc?.maxDepthRelation).not.toHaveProperty('name') // should not affect other fields @@ -573,7 +620,7 @@ describe('Relationships', () => { }, }) await payload.create({ - collection: 'polymorphic-relationships', + collection: polymorphicRelationshipsSlug, data: { polymorphic: { value: movie.id, @@ -582,25 +629,31 @@ describe('Relationships', () => { }, }) - const query = await client.find({ - slug: 'polymorphic-relationships', - query: { - and: [ - { - 'polymorphic.value': { - equals: movie.id, - }, + const result = await restClient + .GET(`/${polymorphicRelationshipsSlug}`, { + query: { + where: { + and: [ + { + 'polymorphic.value': { + equals: movie.id, + }, + }, + { + 'polymorphic.relationTo': { + equals: 'movies', + }, + }, + ], }, - { - 'polymorphic.relationTo': { - equals: 'movies', - }, - }, - ], - }, - }) + }, + headers: { + Authorization: `JWT ${token}`, + }, + }) + .then((res) => res.json()) - expect(query.result.docs).toHaveLength(1) + expect(result.docs).toHaveLength(1) }) }) }) diff --git a/test/relationships/shared.ts b/test/relationships/shared.ts new file mode 100644 index 000000000..c9350d680 --- /dev/null +++ b/test/relationships/shared.ts @@ -0,0 +1,8 @@ +export const usersSlug = 'users' +export const slug = 'posts' +export const relationSlug = 'relation' +export const defaultAccessRelSlug = 'strict-access' +export const chainedRelSlug = 'chained' +export const customIdSlug = 'custom-id' +export const customIdNumberSlug = 'custom-id-number' +export const polymorphicRelationshipsSlug = 'polymorphic-relationships'