- Upgrades eslint from v8 to v9 - Upgrades all other eslint packages. We will have to do a new full-project lint, as new rules have been added - Upgrades husky from v8 to v9 - Upgrades lint-staged from v14 to v15 - Moves the old .eslintrc.cjs file format to the new eslint.config.js flat file format. Previously, we were very specific regarding which rules are applied to which files. Now that `extends` is no longer a thing, I have to use deepMerge & imports instead. This is rather uncommon and is not a documented pattern - e.g. typescript-eslint docs want us to add the default typescript-eslint rules to the top-level & then disable it in files using the disable-typechecked config. However, I hate this opt-out approach. The way I did it here adds a lot of clarity as to which rules are applied to which files, and is pretty easy to read. Much less black magic ## .eslintignore These files are no longer supported (see https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files). I moved the entries to the ignores property in the eslint config. => one less file in each package folder!
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import type { Post, Relation } from './payload-types.js'
|
|
|
|
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
|
import configPromise from './config.js'
|
|
|
|
describe('Relationship Object IDs Plugin', () => {
|
|
let relations: Relation[]
|
|
let posts: Post[]
|
|
let payload: Payload
|
|
|
|
beforeAll(async () => {
|
|
;({ payload } = await initPayloadInt(configPromise))
|
|
})
|
|
|
|
it('seeds data accordingly', async () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const relationsQuery = await payload.find({
|
|
collection: 'relations',
|
|
sort: 'createdAt',
|
|
})
|
|
|
|
relations = relationsQuery.docs
|
|
|
|
const postsQuery = await payload.find({
|
|
collection: 'posts',
|
|
sort: 'createdAt',
|
|
})
|
|
|
|
posts = postsQuery.docs
|
|
|
|
expect(relationsQuery.totalDocs).toStrictEqual(2)
|
|
expect(postsQuery.totalDocs).toStrictEqual(2)
|
|
}
|
|
})
|
|
|
|
it('stores relations as object ids', async () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const docs = await payload.db.collections.relations.find()
|
|
expect(typeof docs[0].hasOne).toBe('object')
|
|
expect(typeof docs[0].hasOnePoly.value).toBe('object')
|
|
expect(typeof docs[0].hasMany[0]).toBe('object')
|
|
expect(typeof docs[0].hasManyPoly[0].value).toBe('object')
|
|
expect(typeof docs[0].upload).toBe('object')
|
|
}
|
|
})
|
|
|
|
it('can query by relationship id', async () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const { totalDocs } = await payload.find({
|
|
collection: 'relations',
|
|
where: {
|
|
hasOne: {
|
|
equals: posts[0].id,
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(totalDocs).toStrictEqual(1)
|
|
}
|
|
})
|
|
|
|
it('populates relations', () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const populatedPostTitle =
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
typeof relations[0].hasOne === 'object' ? relations[0].hasOne.title : undefined
|
|
expect(populatedPostTitle).toBeDefined()
|
|
|
|
const populatedUploadFilename =
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
typeof relations[0].upload === 'object' ? relations[0].upload.filename : undefined
|
|
|
|
expect(populatedUploadFilename).toBeDefined()
|
|
}
|
|
})
|
|
|
|
it('can query by nested property', async () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const { totalDocs } = await payload.find({
|
|
collection: 'relations',
|
|
where: {
|
|
'hasOne.title': {
|
|
equals: 'post 1',
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(totalDocs).toStrictEqual(1)
|
|
}
|
|
})
|
|
|
|
it('can query using the "in" operator', async () => {
|
|
// eslint-disable-next-line jest/no-conditional-in-test
|
|
if (payload.db.name === 'mongoose') {
|
|
const { totalDocs } = await payload.find({
|
|
collection: 'relations',
|
|
where: {
|
|
hasMany: {
|
|
in: [posts[0].id],
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(totalDocs).toStrictEqual(1)
|
|
}
|
|
})
|
|
})
|