chore: merge
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import path from 'path'
|
||||
|
||||
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync'
|
||||
import { createSlate } from '../../packages/richtext-slate/src'
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
import AfterDashboard from './components/AfterDashboard'
|
||||
@@ -114,9 +115,11 @@ export default buildConfigWithDefaults({
|
||||
{
|
||||
name: 'richText',
|
||||
type: 'richText',
|
||||
admin: {
|
||||
elements: ['relationship'],
|
||||
},
|
||||
editor: createSlate({
|
||||
admin: {
|
||||
elements: ['relationship'],
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
type: 'ui',
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import payload from '../../../packages/payload/src'
|
||||
import { devUser } from '../../credentials'
|
||||
import { initPayloadTest } from '../../helpers/configHelpers'
|
||||
@@ -21,9 +19,9 @@ describe('Remove token from auth responses', () => {
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await mongoose.connection.dropDatabase()
|
||||
await mongoose.connection.close()
|
||||
await payload.mongoMemoryServer.stop()
|
||||
if (typeof payload.db.destroy === 'function') {
|
||||
await payload.db.destroy(payload)
|
||||
}
|
||||
})
|
||||
|
||||
it('should not include token in response from /login', async () => {
|
||||
|
||||
@@ -2,13 +2,13 @@ import path from 'path'
|
||||
|
||||
import type { Config, SanitizedConfig } from '../packages/payload/src/config/types'
|
||||
|
||||
// import viteBundler from '../packages/bundler-vite/src'
|
||||
import webpackBundler from '../packages/bundler-webpack/src'
|
||||
// import { viteBundler } from '../packages/bundler-vite/src'
|
||||
import { webpackBundler } from '../packages/bundler-webpack/src'
|
||||
import { mongooseAdapter } from '../packages/db-mongodb/src/index'
|
||||
import { postgresAdapter } from '../packages/db-postgres/src/index'
|
||||
import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build'
|
||||
|
||||
// process.env.PAYLOAD_DATABASE = 'postgres'
|
||||
import { createSlate } from '../packages/richtext-slate/src'
|
||||
|
||||
const databaseAdapters = {
|
||||
mongoose: mongooseAdapter({
|
||||
@@ -25,6 +25,7 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
|
||||
const [name] = process.argv.slice(2)
|
||||
|
||||
const config: Config = {
|
||||
editor: createSlate({}),
|
||||
telemetry: false,
|
||||
rateLimit: {
|
||||
window: 15 * 60 * 100, // 15min default,
|
||||
@@ -74,6 +75,10 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
|
||||
__dirname,
|
||||
'../packages/db-mongodb/src/mock.js',
|
||||
),
|
||||
[path.resolve(__dirname, '../packages/bundler-webpack/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/bundler-webpack/src/mocks/emptyModule.js',
|
||||
),
|
||||
'@payloadcms/db-mongodb': path.resolve(__dirname, '../packages/db-mongodb/src/mock'),
|
||||
'@payloadcms/db-postgres': path.resolve(__dirname, '../packages/db-postgres/src/mock'),
|
||||
react: path.resolve(__dirname, '../packages/payload/node_modules/react'),
|
||||
|
||||
@@ -25,12 +25,14 @@ describe('collections-rest', () => {
|
||||
|
||||
// Wait for indexes to be created,
|
||||
// as we need them to query by point
|
||||
await new Promise((resolve, reject) => {
|
||||
payload.db.collections[pointSlug].ensureIndexes(function (err) {
|
||||
if (err) reject(err)
|
||||
resolve(true)
|
||||
if (payload.db.name === 'mongoose') {
|
||||
await new Promise((resolve, reject) => {
|
||||
payload.db.collections[pointSlug].ensureIndexes(function (err) {
|
||||
if (err) reject(err)
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -116,11 +118,12 @@ describe('collections-rest', () => {
|
||||
})
|
||||
|
||||
const description = 'updated'
|
||||
const { status, docs } = await client.updateMany<Post>({
|
||||
const { status, docs, errors } = await client.updateMany({
|
||||
where: { title: { equals: 'title' } },
|
||||
data: { description },
|
||||
})
|
||||
|
||||
expect(errors).toHaveLength(0)
|
||||
expect(status).toEqual(200)
|
||||
expect(docs[0].title).toEqual('title') // Check was not modified
|
||||
expect(docs[0].description).toEqual(description)
|
||||
@@ -870,162 +873,164 @@ describe('collections-rest', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('near', () => {
|
||||
const point = [10, 20]
|
||||
const [lat, lng] = point
|
||||
it('should return a document near a point', async () => {
|
||||
const near = `${lat + 0.01}, ${lng + 0.01}, 10000`
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
near,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should not return a point far away', async () => {
|
||||
const near = `${lng + 1}, ${lat - 1}, 5000`
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
near,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should sort find results by nearest distance', async () => {
|
||||
// creating twice as many records as we are querying to get a random sample
|
||||
await mapAsync([...Array(10)], async () => {
|
||||
// setTimeout used to randomize the creation timestamp
|
||||
setTimeout(async () => {
|
||||
await payload.create({
|
||||
collection: pointSlug,
|
||||
data: {
|
||||
// only randomize longitude to make distance comparison easy
|
||||
point: [Math.random(), 0],
|
||||
},
|
||||
})
|
||||
}, Math.random())
|
||||
})
|
||||
|
||||
const { result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
// querying large enough range to include all docs
|
||||
point: { near: '0, 0, 100000, 0' },
|
||||
},
|
||||
limit: 5,
|
||||
})
|
||||
const { docs } = result
|
||||
let previous = 0
|
||||
docs.forEach(({ point: coordinates }) => {
|
||||
// the next document point should always be greater than the one before
|
||||
expect(previous).toBeLessThanOrEqual(coordinates[0])
|
||||
;[previous] = coordinates
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('within', () => {
|
||||
type Point = [number, number]
|
||||
const polygon: Point[] = [
|
||||
[9.0, 19.0], // bottom-left
|
||||
[9.0, 21.0], // top-left
|
||||
[11.0, 21.0], // top-right
|
||||
[11.0, 19.0], // bottom-right
|
||||
[9.0, 19.0], // back to starting point to close the polygon
|
||||
]
|
||||
it('should return a document with the point inside the polygon', async () => {
|
||||
// There should be 1 total points document populated by default with the point [10, 20]
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
within: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon],
|
||||
if (['mongoose'].includes(process.env.PAYLOAD_DATABASE)) {
|
||||
describe('near', () => {
|
||||
const point = [10, 20]
|
||||
const [lat, lng] = point
|
||||
it('should return a document near a point', async () => {
|
||||
const near = `${lat + 0.01}, ${lng + 0.01}, 10000`
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
near,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should not return a document with the point outside a smaller polygon', async () => {
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
within: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon.map((vertex) => vertex.map((coord) => coord * 0.1))], // Reduce polygon to 10% of its size
|
||||
it('should not return a point far away', async () => {
|
||||
const near = `${lng + 1}, ${lat - 1}, 5000`
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
near,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
it('should sort find results by nearest distance', async () => {
|
||||
// creating twice as many records as we are querying to get a random sample
|
||||
await mapAsync([...Array(10)], async () => {
|
||||
// setTimeout used to randomize the creation timestamp
|
||||
setTimeout(async () => {
|
||||
await payload.create({
|
||||
collection: pointSlug,
|
||||
data: {
|
||||
// only randomize longitude to make distance comparison easy
|
||||
point: [Math.random(), 0],
|
||||
},
|
||||
})
|
||||
}, Math.random())
|
||||
})
|
||||
|
||||
const { result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
// querying large enough range to include all docs
|
||||
point: { near: '0, 0, 100000, 0' },
|
||||
},
|
||||
limit: 5,
|
||||
})
|
||||
const { docs } = result
|
||||
let previous = 0
|
||||
docs.forEach(({ point: coordinates }) => {
|
||||
// the next document point should always be greater than the one before
|
||||
expect(previous).toBeLessThanOrEqual(coordinates[0])
|
||||
;[previous] = coordinates
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('intersects', () => {
|
||||
type Point = [number, number]
|
||||
const polygon: Point[] = [
|
||||
[9.0, 19.0], // bottom-left
|
||||
[9.0, 21.0], // top-left
|
||||
[11.0, 21.0], // top-right
|
||||
[11.0, 19.0], // bottom-right
|
||||
[9.0, 19.0], // back to starting point to close the polygon
|
||||
]
|
||||
|
||||
it('should return a document with the point intersecting the polygon', async () => {
|
||||
// There should be 1 total points document populated by default with the point [10, 20]
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
intersects: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon],
|
||||
describe('within', () => {
|
||||
type Point = [number, number]
|
||||
const polygon: Point[] = [
|
||||
[9.0, 19.0], // bottom-left
|
||||
[9.0, 21.0], // top-left
|
||||
[11.0, 21.0], // top-right
|
||||
[11.0, 19.0], // bottom-right
|
||||
[9.0, 19.0], // back to starting point to close the polygon
|
||||
]
|
||||
it('should return a document with the point inside the polygon', async () => {
|
||||
// There should be 1 total points document populated by default with the point [10, 20]
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
within: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should not return a document with the point not intersecting a smaller polygon', async () => {
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
intersects: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon.map((vertex) => vertex.map((coord) => coord * 0.1))], // Reduce polygon to 10% of its size
|
||||
it('should not return a document with the point outside a smaller polygon', async () => {
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
within: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon.map((vertex) => vertex.map((coord) => coord * 0.1))], // Reduce polygon to 10% of its size
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('intersects', () => {
|
||||
type Point = [number, number]
|
||||
const polygon: Point[] = [
|
||||
[9.0, 19.0], // bottom-left
|
||||
[9.0, 21.0], // top-left
|
||||
[11.0, 21.0], // top-right
|
||||
[11.0, 19.0], // bottom-right
|
||||
[9.0, 19.0], // back to starting point to close the polygon
|
||||
]
|
||||
|
||||
it('should return a document with the point intersecting the polygon', async () => {
|
||||
// There should be 1 total points document populated by default with the point [10, 20]
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
intersects: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
it('should not return a document with the point not intersecting a smaller polygon', async () => {
|
||||
const { status, result } = await client.find({
|
||||
slug: pointSlug,
|
||||
query: {
|
||||
point: {
|
||||
intersects: {
|
||||
type: 'Polygon',
|
||||
coordinates: [polygon.map((vertex) => vertex.map((coord) => coord * 0.1))], // Reduce polygon to 10% of its size
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(result.docs).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
it('or', async () => {
|
||||
const post1 = await createPost({ title: 'post1' })
|
||||
|
||||
@@ -4,38 +4,38 @@ import type { CodeField } from '../../payload-types'
|
||||
const Code: CollectionConfig = {
|
||||
fields: [
|
||||
{
|
||||
name: 'javascript',
|
||||
admin: {
|
||||
language: 'javascript',
|
||||
},
|
||||
name: 'javascript',
|
||||
type: 'code',
|
||||
},
|
||||
{
|
||||
name: 'typescript',
|
||||
admin: {
|
||||
language: 'typescript',
|
||||
},
|
||||
name: 'typescript',
|
||||
type: 'code',
|
||||
},
|
||||
{
|
||||
name: 'json',
|
||||
admin: {
|
||||
language: 'json',
|
||||
},
|
||||
name: 'json',
|
||||
type: 'code',
|
||||
},
|
||||
{
|
||||
name: 'html',
|
||||
admin: {
|
||||
language: 'html',
|
||||
},
|
||||
name: 'html',
|
||||
type: 'code',
|
||||
},
|
||||
{
|
||||
name: 'css',
|
||||
admin: {
|
||||
language: 'css',
|
||||
},
|
||||
name: 'css',
|
||||
type: 'code',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { createSlate } from '../../../../packages/richtext-slate/src'
|
||||
import { loremIpsum } from './loremIpsum'
|
||||
|
||||
const RichTextFields: CollectionConfig = {
|
||||
@@ -51,143 +52,151 @@ const RichTextFields: CollectionConfig = {
|
||||
{
|
||||
name: 'richText',
|
||||
type: 'richText',
|
||||
required: true,
|
||||
admin: {
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'textAlign',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
link: {
|
||||
fields: [
|
||||
{
|
||||
name: 'rel',
|
||||
label: 'Rel Attribute',
|
||||
type: 'select',
|
||||
hasMany: true,
|
||||
options: ['noopener', 'noreferrer', 'nofollow'],
|
||||
admin: {
|
||||
description:
|
||||
'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
|
||||
},
|
||||
},
|
||||
editor: createSlate({
|
||||
admin: {
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'textAlign',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
link: {
|
||||
fields: [
|
||||
{
|
||||
name: 'rel',
|
||||
label: 'Rel Attribute',
|
||||
type: 'select',
|
||||
hasMany: true,
|
||||
options: ['noopener', 'noreferrer', 'nofollow'],
|
||||
admin: {
|
||||
description:
|
||||
'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'richTextCustomFields',
|
||||
type: 'richText',
|
||||
admin: {
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
link: {
|
||||
fields: ({ defaultFields }) => {
|
||||
return [
|
||||
...defaultFields,
|
||||
{
|
||||
label: 'Custom',
|
||||
name: 'customLinkField',
|
||||
type: 'text',
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
editor: createSlate({
|
||||
admin: {
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
link: {
|
||||
fields: ({ defaultFields }) => {
|
||||
return [
|
||||
...defaultFields,
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
label: 'Custom',
|
||||
name: 'customLinkField',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
]
|
||||
},
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: 'richTextReadOnly',
|
||||
type: 'richText',
|
||||
admin: {
|
||||
readOnly: true,
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
link: {
|
||||
fields: [
|
||||
{
|
||||
name: 'rel',
|
||||
label: 'Rel Attribute',
|
||||
type: 'select',
|
||||
hasMany: true,
|
||||
options: ['noopener', 'noreferrer', 'nofollow'],
|
||||
admin: {
|
||||
description:
|
||||
'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
|
||||
},
|
||||
},
|
||||
},
|
||||
editor: createSlate({
|
||||
admin: {
|
||||
elements: [
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'ul',
|
||||
'ol',
|
||||
'indent',
|
||||
'link',
|
||||
'relationship',
|
||||
'upload',
|
||||
],
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
link: {
|
||||
fields: [
|
||||
{
|
||||
name: 'rel',
|
||||
label: 'Rel Attribute',
|
||||
type: 'select',
|
||||
hasMany: true,
|
||||
options: ['noopener', 'noreferrer', 'nofollow'],
|
||||
admin: {
|
||||
description:
|
||||
'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
upload: {
|
||||
collections: {
|
||||
uploads: {
|
||||
fields: [
|
||||
{
|
||||
name: 'caption',
|
||||
type: 'richText',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: 'blocks',
|
||||
|
||||
5
test/fields/collections/Tabs/constants.ts
Normal file
5
test/fields/collections/Tabs/constants.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const tabsSlug = 'tabs-fields'
|
||||
|
||||
export const namedTabText = 'Some text in a named tab'
|
||||
export const namedTabDefaultValue = 'default text inside of a named tab'
|
||||
export const localizedTextValue = 'localized text'
|
||||
@@ -3,12 +3,7 @@ import type { CollectionConfig } from '../../../../packages/payload/src/collecti
|
||||
|
||||
import { blocksField, blocksFieldSeedData } from '../Blocks'
|
||||
import { UIField } from './UIField'
|
||||
|
||||
export const tabsSlug = 'tabs-fields'
|
||||
|
||||
export const namedTabText = 'Some text in a named tab'
|
||||
export const namedTabDefaultValue = 'default text inside of a named tab'
|
||||
export const localizedTextValue = 'localized text'
|
||||
import { localizedTextValue, namedTabDefaultValue, namedTabText, tabsSlug } from './constants'
|
||||
|
||||
const TabsFields: CollectionConfig = {
|
||||
slug: tabsSlug,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { jsonDoc } from './collections/JSON'
|
||||
import { numberDoc } from './collections/Number'
|
||||
import { pointFieldsSlug } from './collections/Point'
|
||||
import { relationshipFieldsSlug } from './collections/Relationship'
|
||||
import { tabsSlug } from './collections/Tabs'
|
||||
import { tabsSlug } from './collections/Tabs/constants'
|
||||
import { textDoc, textFieldsSlug } from './collections/Text'
|
||||
|
||||
const { afterEach, beforeAll, describe } = test
|
||||
@@ -1029,7 +1029,9 @@ describe('fields', () => {
|
||||
test('should display formatted date in useAsTitle', async () => {
|
||||
await page.goto(url.list)
|
||||
await page.locator('.row-1 .cell-default a').click()
|
||||
await expect(page.locator('.collection-edit .doc-header__title.render-title')).toContainText('August')
|
||||
await expect(page.locator('.collection-edit .doc-header__title.render-title')).toContainText(
|
||||
'August',
|
||||
)
|
||||
})
|
||||
|
||||
test('should clear date', async () => {
|
||||
|
||||
@@ -21,13 +21,13 @@ import {
|
||||
} from './collections/Group'
|
||||
import { defaultNumber, numberDoc } from './collections/Number'
|
||||
import { pointDoc } from './collections/Point'
|
||||
import { tabsDoc } from './collections/Tabs'
|
||||
import {
|
||||
localizedTextValue,
|
||||
namedTabDefaultValue,
|
||||
namedTabText,
|
||||
tabsDoc,
|
||||
tabsSlug,
|
||||
} from './collections/Tabs'
|
||||
} from './collections/Tabs/constants'
|
||||
import { defaultText } from './collections/Text'
|
||||
|
||||
let client
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const LocalizedArrays: CollectionConfig = {
|
||||
slug: 'localized-arrays',
|
||||
@@ -16,4 +16,4 @@ export const LocalizedArrays: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const LocalizedBlocks: CollectionConfig = {
|
||||
slug: 'localized-blocks',
|
||||
@@ -36,4 +36,4 @@ export const LocalizedBlocks: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const LocalizedGroups: CollectionConfig = {
|
||||
slug: 'localized-groups',
|
||||
@@ -19,4 +19,4 @@ export const LocalizedGroups: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const Pages: CollectionConfig = {
|
||||
slug: 'pages',
|
||||
@@ -24,4 +24,4 @@ export const Pages: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const People: CollectionConfig = {
|
||||
slug: 'people',
|
||||
@@ -8,4 +8,4 @@ export const People: CollectionConfig = {
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types'
|
||||
|
||||
export const Posts: CollectionConfig = {
|
||||
slug: 'posts',
|
||||
@@ -149,4 +149,4 @@ export const Posts: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
import type { PayloadRequest } from 'payload/types';
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults';
|
||||
import { LocalizedArrays } from './collections/LocalizedArrays';
|
||||
import { LocalizedBlocks } from './collections/LocalizedBlocks';
|
||||
import { LocalizedGroups } from './collections/LocalizedGroups';
|
||||
import { Pages } from './collections/Pages';
|
||||
import { People } from './collections/People';
|
||||
import { Posts } from './collections/Posts';
|
||||
import { MainMenu } from './globals/MainMenu';
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { LocalizedArrays } from './collections/LocalizedArrays'
|
||||
import { LocalizedBlocks } from './collections/LocalizedBlocks'
|
||||
import { LocalizedGroups } from './collections/LocalizedGroups'
|
||||
import { Pages } from './collections/Pages'
|
||||
import { People } from './collections/People'
|
||||
import { Posts } from './collections/Posts'
|
||||
import { MainMenu } from './globals/MainMenu'
|
||||
|
||||
const config = buildConfigWithDefaults({
|
||||
collections: [
|
||||
LocalizedArrays,
|
||||
LocalizedBlocks,
|
||||
LocalizedGroups,
|
||||
Pages,
|
||||
People,
|
||||
Posts,
|
||||
],
|
||||
globals: [
|
||||
MainMenu,
|
||||
],
|
||||
collections: [LocalizedArrays, LocalizedBlocks, LocalizedGroups, Pages, People, Posts],
|
||||
globals: [MainMenu],
|
||||
localization: {
|
||||
locales: ['en', 'es'],
|
||||
defaultLocale: 'en',
|
||||
@@ -33,9 +24,9 @@ const config = buildConfigWithDefaults({
|
||||
// password: devUser.password,
|
||||
// },
|
||||
// });
|
||||
const req = {} as PayloadRequest;
|
||||
const req = {} as PayloadRequest
|
||||
|
||||
req.transactionID = await payload.db.beginTransaction();
|
||||
req.transactionID = await payload.db.beginTransaction()
|
||||
|
||||
const page1 = await payload.create({
|
||||
req,
|
||||
@@ -53,8 +44,7 @@ const config = buildConfigWithDefaults({
|
||||
},
|
||||
})
|
||||
|
||||
await payload.db.commitTransaction(req.transactionID);
|
||||
|
||||
await payload.db.commitTransaction(req.transactionID)
|
||||
|
||||
const findResult = await payload.find({
|
||||
collection: 'pages',
|
||||
@@ -73,7 +63,7 @@ const config = buildConfigWithDefaults({
|
||||
},
|
||||
})
|
||||
|
||||
req.transactionID = await payload.db.beginTransaction();
|
||||
req.transactionID = await payload.db.beginTransaction()
|
||||
|
||||
const person2 = await payload.create({
|
||||
req,
|
||||
@@ -167,7 +157,7 @@ const config = buildConfigWithDefaults({
|
||||
],
|
||||
},
|
||||
})
|
||||
await payload.db.commitTransaction(req.transactionID);
|
||||
await payload.db.commitTransaction(req.transactionID)
|
||||
await payload.update({
|
||||
collection: 'posts',
|
||||
id: post.id,
|
||||
@@ -249,38 +239,42 @@ const config = buildConfigWithDefaults({
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const text = 'block';
|
||||
})
|
||||
const text = 'block'
|
||||
const blockDoc = await payload.create({
|
||||
collection: 'localized-blocks',
|
||||
data: {
|
||||
title: 'titled',
|
||||
layout: [{
|
||||
blockType: 'text',
|
||||
text,
|
||||
}],
|
||||
}
|
||||
layout: [
|
||||
{
|
||||
blockType: 'text',
|
||||
text,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const nope = await payload.create({
|
||||
collection: 'localized-blocks',
|
||||
data: {
|
||||
title: 'titled',
|
||||
layout: [{
|
||||
blockType: 'text',
|
||||
text: 'should not be found',
|
||||
}],
|
||||
}
|
||||
layout: [
|
||||
{
|
||||
blockType: 'text',
|
||||
text: 'should not be found',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const query = await payload.find({
|
||||
collection: 'localized-blocks',
|
||||
where: {
|
||||
'layout.text': { equals: text }
|
||||
}
|
||||
'layout.text': { equals: text },
|
||||
},
|
||||
})
|
||||
|
||||
console.log({ query });
|
||||
console.log({ query })
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GlobalConfig } from '../../../src/globals/config/types';
|
||||
import type { GlobalConfig } from '../../../src/globals/config/types'
|
||||
|
||||
export const MainMenu: GlobalConfig = {
|
||||
slug: 'main-menu',
|
||||
@@ -24,4 +24,4 @@ export const MainMenu: GlobalConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import payload from '../../src';
|
||||
import { initPayloadTest } from '../helpers/configHelpers';
|
||||
import payload from '../../packages/payload/src'
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
|
||||
describe('Postgres', () => {
|
||||
beforeAll(async () => {
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true';
|
||||
await initPayloadTest({ __dirname, init: { local: false } });
|
||||
});
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||
await initPayloadTest({ __dirname, init: { local: false } })
|
||||
})
|
||||
|
||||
describe('complex docs', () => {
|
||||
let post;
|
||||
let page1;
|
||||
let page2;
|
||||
let person1;
|
||||
let person2;
|
||||
let post
|
||||
let page1
|
||||
let page2
|
||||
let person1
|
||||
let person2
|
||||
|
||||
beforeAll(async () => {
|
||||
page1 = await payload.create({
|
||||
@@ -23,7 +23,7 @@ describe('Postgres', () => {
|
||||
title: 'abc',
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
page2 = await payload.create({
|
||||
collection: 'pages',
|
||||
@@ -33,25 +33,25 @@ describe('Postgres', () => {
|
||||
title: 'def',
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
person1 = await payload.create({
|
||||
collection: 'people',
|
||||
data: {
|
||||
fullName: 'Dan Ribbens',
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
person2 = await payload.create({
|
||||
collection: 'people',
|
||||
data: {
|
||||
fullName: 'Elliot DeNolf',
|
||||
},
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('creates a complex doc', async () => {
|
||||
const postTitleEN = 'hello';
|
||||
const postTitleEN = 'hello'
|
||||
|
||||
post = await payload.create({
|
||||
collection: 'posts',
|
||||
@@ -134,23 +134,23 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(post.title).toEqual(postTitleEN);
|
||||
expect(post.myBlocks[0].localizedText).toStrictEqual('hello in english');
|
||||
expect(post.relationHasOne).toStrictEqual(page1.id);
|
||||
expect(post.relationHasOnePoly.value).toStrictEqual(person1.id);
|
||||
expect(post.relationHasMany[0]).toStrictEqual(page1.id);
|
||||
expect(post.relationHasMany[1]).toStrictEqual(page2.id);
|
||||
expect(post.relationHasManyPoly[0].value).toStrictEqual(person1.id);
|
||||
expect(post.relationHasManyPoly[1].value).toStrictEqual(page2.id);
|
||||
});
|
||||
expect(post.title).toEqual(postTitleEN)
|
||||
expect(post.myBlocks[0].localizedText).toStrictEqual('hello in english')
|
||||
expect(post.relationHasOne).toStrictEqual(page1.id)
|
||||
expect(post.relationHasOnePoly.value).toStrictEqual(person1.id)
|
||||
expect(post.relationHasMany[0]).toStrictEqual(page1.id)
|
||||
expect(post.relationHasMany[1]).toStrictEqual(page2.id)
|
||||
expect(post.relationHasManyPoly[0].value).toStrictEqual(person1.id)
|
||||
expect(post.relationHasManyPoly[1].value).toStrictEqual(page2.id)
|
||||
})
|
||||
|
||||
it('adds locale to existing doc', async () => {
|
||||
const titleES = 'hello es';
|
||||
const arrayTitle1 = 'hello 1 spanish';
|
||||
const arrayTitle2 = 'hello 2 spanish';
|
||||
const blockLocalizedText = 'my block in spanish';
|
||||
const titleES = 'hello es'
|
||||
const arrayTitle1 = 'hello 1 spanish'
|
||||
const arrayTitle2 = 'hello 2 spanish'
|
||||
const blockLocalizedText = 'my block in spanish'
|
||||
|
||||
const updatedPost = await payload.update({
|
||||
collection: 'posts',
|
||||
@@ -192,23 +192,23 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updatedPost.title).toStrictEqual(titleES);
|
||||
expect(updatedPost.number).toStrictEqual(1000);
|
||||
expect(updatedPost.myArray[0].subField).toStrictEqual(arrayTitle1);
|
||||
expect(updatedPost.myArray[1].subField).toStrictEqual(arrayTitle2);
|
||||
expect(updatedPost.myBlocks[0].localizedText).toStrictEqual(blockLocalizedText);
|
||||
expect(updatedPost.relationHasOne).toStrictEqual(page2.id);
|
||||
expect(updatedPost.relationHasOnePoly.value).toStrictEqual(person2.id);
|
||||
expect(updatedPost.relationHasMany[0]).toStrictEqual(page2.id);
|
||||
expect(updatedPost.relationHasMany[1]).toStrictEqual(page1.id);
|
||||
expect(updatedPost.relationHasManyPoly[0].value).toStrictEqual(page1.id);
|
||||
expect(updatedPost.relationHasManyPoly[1].value).toStrictEqual(person1.id);
|
||||
});
|
||||
expect(updatedPost.title).toStrictEqual(titleES)
|
||||
expect(updatedPost.number).toStrictEqual(1000)
|
||||
expect(updatedPost.myArray[0].subField).toStrictEqual(arrayTitle1)
|
||||
expect(updatedPost.myArray[1].subField).toStrictEqual(arrayTitle2)
|
||||
expect(updatedPost.myBlocks[0].localizedText).toStrictEqual(blockLocalizedText)
|
||||
expect(updatedPost.relationHasOne).toStrictEqual(page2.id)
|
||||
expect(updatedPost.relationHasOnePoly.value).toStrictEqual(person2.id)
|
||||
expect(updatedPost.relationHasMany[0]).toStrictEqual(page2.id)
|
||||
expect(updatedPost.relationHasMany[1]).toStrictEqual(page1.id)
|
||||
expect(updatedPost.relationHasManyPoly[0].value).toStrictEqual(page1.id)
|
||||
expect(updatedPost.relationHasManyPoly[1].value).toStrictEqual(person1.id)
|
||||
})
|
||||
|
||||
it('updates original locale', async () => {
|
||||
const updatedTitle = 'hello 3';
|
||||
const updatedTitle = 'hello 3'
|
||||
|
||||
const updatedPost = await payload.update({
|
||||
collection: 'posts',
|
||||
@@ -295,42 +295,42 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updatedPost.title).toStrictEqual(updatedTitle);
|
||||
expect(updatedPost.myArray[0].subField).toStrictEqual('hello 1 updated');
|
||||
expect(updatedPost.myArray[1].subField).toStrictEqual('hello 2 updated');
|
||||
expect(updatedPost.myBlocks[0].localizedText).toStrictEqual('hello in english updated');
|
||||
});
|
||||
expect(updatedPost.title).toStrictEqual(updatedTitle)
|
||||
expect(updatedPost.myArray[0].subField).toStrictEqual('hello 1 updated')
|
||||
expect(updatedPost.myArray[1].subField).toStrictEqual('hello 2 updated')
|
||||
expect(updatedPost.myBlocks[0].localizedText).toStrictEqual('hello in english updated')
|
||||
})
|
||||
|
||||
it('retrieves doc in all locales', async () => {
|
||||
const postAllLocales = await payload.findByID({
|
||||
collection: 'posts',
|
||||
id: post.id,
|
||||
locale: 'all',
|
||||
});
|
||||
})
|
||||
|
||||
expect(postAllLocales.title.en).toStrictEqual('hello 3');
|
||||
expect(postAllLocales.title.es).toStrictEqual('hello es');
|
||||
expect(postAllLocales.number.en).toStrictEqual(1338);
|
||||
expect(postAllLocales.number.es).toStrictEqual(1000);
|
||||
expect(postAllLocales.myBlocks[0].localizedText.en).toStrictEqual('hello in english updated');
|
||||
expect(postAllLocales.myArray[0].subField.es).toStrictEqual('hello 1 spanish');
|
||||
expect(postAllLocales.title.en).toStrictEqual('hello 3')
|
||||
expect(postAllLocales.title.es).toStrictEqual('hello es')
|
||||
expect(postAllLocales.number.en).toStrictEqual(1338)
|
||||
expect(postAllLocales.number.es).toStrictEqual(1000)
|
||||
expect(postAllLocales.myBlocks[0].localizedText.en).toStrictEqual('hello in english updated')
|
||||
expect(postAllLocales.myArray[0].subField.es).toStrictEqual('hello 1 spanish')
|
||||
|
||||
expect(postAllLocales.relationHasOne.en).toStrictEqual(page2.id);
|
||||
expect(postAllLocales.relationHasOnePoly.en.value).toStrictEqual(person2.id);
|
||||
expect(postAllLocales.relationHasMany.en[0]).toStrictEqual(page2.id);
|
||||
expect(postAllLocales.relationHasMany.en[1]).toStrictEqual(page1.id);
|
||||
expect(postAllLocales.relationHasManyPoly.en[0].value).toStrictEqual(page2.id);
|
||||
expect(postAllLocales.relationHasManyPoly.en[1].value).toStrictEqual(person2.id);
|
||||
expect(postAllLocales.relationHasOne.en).toStrictEqual(page2.id)
|
||||
expect(postAllLocales.relationHasOnePoly.en.value).toStrictEqual(person2.id)
|
||||
expect(postAllLocales.relationHasMany.en[0]).toStrictEqual(page2.id)
|
||||
expect(postAllLocales.relationHasMany.en[1]).toStrictEqual(page1.id)
|
||||
expect(postAllLocales.relationHasManyPoly.en[0].value).toStrictEqual(page2.id)
|
||||
expect(postAllLocales.relationHasManyPoly.en[1].value).toStrictEqual(person2.id)
|
||||
|
||||
expect(postAllLocales.relationHasOne.es).toStrictEqual(page2.id);
|
||||
expect(postAllLocales.relationHasOnePoly.es.value).toStrictEqual(person2.id);
|
||||
expect(postAllLocales.relationHasMany.es[0]).toStrictEqual(page2.id);
|
||||
expect(postAllLocales.relationHasMany.es[1]).toStrictEqual(page1.id);
|
||||
expect(postAllLocales.relationHasManyPoly.es[0].value).toStrictEqual(page1.id);
|
||||
expect(postAllLocales.relationHasManyPoly.es[1].value).toStrictEqual(person1.id);
|
||||
});
|
||||
expect(postAllLocales.relationHasOne.es).toStrictEqual(page2.id)
|
||||
expect(postAllLocales.relationHasOnePoly.es.value).toStrictEqual(person2.id)
|
||||
expect(postAllLocales.relationHasMany.es[0]).toStrictEqual(page2.id)
|
||||
expect(postAllLocales.relationHasMany.es[1]).toStrictEqual(page1.id)
|
||||
expect(postAllLocales.relationHasManyPoly.es[0].value).toStrictEqual(page1.id)
|
||||
expect(postAllLocales.relationHasManyPoly.es[1].value).toStrictEqual(person1.id)
|
||||
})
|
||||
|
||||
// it('queries complex docs', async () => {
|
||||
// const query = await payload.find({
|
||||
@@ -369,68 +369,68 @@ describe('Postgres', () => {
|
||||
const { docs: people } = await payload.find({
|
||||
collection: 'people',
|
||||
sort: 'fullName',
|
||||
});
|
||||
expect(people[0].fullName).toEqual('Dan Ribbens');
|
||||
expect(people[1].fullName).toEqual('Elliot DeNolf');
|
||||
});
|
||||
})
|
||||
expect(people[0].fullName).toEqual('Dan Ribbens')
|
||||
expect(people[1].fullName).toEqual('Elliot DeNolf')
|
||||
})
|
||||
|
||||
it('sort desc', async () => {
|
||||
const { docs: people } = await payload.find({
|
||||
collection: 'people',
|
||||
sort: '-fullName',
|
||||
});
|
||||
expect(people[0].fullName).toEqual('Elliot DeNolf');
|
||||
expect(people[1].fullName).toEqual('Dan Ribbens');
|
||||
});
|
||||
})
|
||||
expect(people[0].fullName).toEqual('Elliot DeNolf')
|
||||
expect(people[1].fullName).toEqual('Dan Ribbens')
|
||||
})
|
||||
|
||||
it('sort localized asc', async () => {
|
||||
const { docs: pages } = await payload.find({
|
||||
collection: 'pages',
|
||||
sort: 'slug',
|
||||
});
|
||||
expect(pages[0].slug).toEqual('first');
|
||||
expect(pages[1].slug).toEqual('second');
|
||||
});
|
||||
})
|
||||
expect(pages[0].slug).toEqual('first')
|
||||
expect(pages[1].slug).toEqual('second')
|
||||
})
|
||||
|
||||
it('sort nested localized field asc', async () => {
|
||||
const { docs: pages } = await payload.find({
|
||||
collection: 'pages',
|
||||
sort: 'meta.title',
|
||||
});
|
||||
expect(pages[0].slug).toEqual('first');
|
||||
expect(pages[1].slug).toEqual('second');
|
||||
});
|
||||
})
|
||||
expect(pages[0].slug).toEqual('first')
|
||||
expect(pages[1].slug).toEqual('second')
|
||||
})
|
||||
|
||||
it('sort nested localized field desc', async () => {
|
||||
const { docs: pages } = await payload.find({
|
||||
collection: 'pages',
|
||||
sort: '-meta.title',
|
||||
});
|
||||
expect(pages[0].slug).toEqual('second');
|
||||
expect(pages[1].slug).toEqual('first');
|
||||
});
|
||||
})
|
||||
expect(pages[0].slug).toEqual('second')
|
||||
expect(pages[1].slug).toEqual('first')
|
||||
})
|
||||
|
||||
it('sort localized desc', async () => {
|
||||
const { docs: pages } = await payload.find({
|
||||
collection: 'posts',
|
||||
sort: '-slug',
|
||||
});
|
||||
expect(pages[0].tableName).toEqual('second');
|
||||
expect(pages[1].tableName).toEqual('first');
|
||||
});
|
||||
})
|
||||
expect(pages[0].tableName).toEqual('second')
|
||||
expect(pages[1].tableName).toEqual('first')
|
||||
})
|
||||
it('find where', async () => {
|
||||
const { docs: people } = await payload.find({
|
||||
collection: 'people',
|
||||
where: {
|
||||
fullName: { equals: 'Dan Ribbens' },
|
||||
},
|
||||
});
|
||||
expect(people).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
})
|
||||
expect(people).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('localized arrays', () => {
|
||||
let localizedArray;
|
||||
let localizedArray
|
||||
|
||||
it('creates localized array', async () => {
|
||||
localizedArray = await payload.create({
|
||||
@@ -445,11 +445,11 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(localizedArray.array[0].text).toStrictEqual('hello in english');
|
||||
expect(localizedArray.array[1].text).toStrictEqual('hello 2 in english');
|
||||
});
|
||||
expect(localizedArray.array[0].text).toStrictEqual('hello in english')
|
||||
expect(localizedArray.array[1].text).toStrictEqual('hello 2 in english')
|
||||
})
|
||||
|
||||
it('adds localized rows', async () => {
|
||||
const updated = await payload.update({
|
||||
@@ -466,28 +466,28 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updated.array[0].text).toStrictEqual('hello in spanish');
|
||||
expect(updated.array[1].text).toStrictEqual('hello 2 in spanish');
|
||||
});
|
||||
expect(updated.array[0].text).toStrictEqual('hello in spanish')
|
||||
expect(updated.array[1].text).toStrictEqual('hello 2 in spanish')
|
||||
})
|
||||
|
||||
it('retrieves array field in all locales', async () => {
|
||||
const retrievedArray = await payload.findByID({
|
||||
collection: 'localized-arrays',
|
||||
id: localizedArray.id,
|
||||
locale: 'all',
|
||||
});
|
||||
})
|
||||
|
||||
expect(retrievedArray.array.en[0].text).toStrictEqual('hello in english');
|
||||
expect(retrievedArray.array.en[1].text).toStrictEqual('hello 2 in english');
|
||||
expect(retrievedArray.array.es[0].text).toStrictEqual('hello in spanish');
|
||||
expect(retrievedArray.array.es[1].text).toStrictEqual('hello 2 in spanish');
|
||||
});
|
||||
});
|
||||
expect(retrievedArray.array.en[0].text).toStrictEqual('hello in english')
|
||||
expect(retrievedArray.array.en[1].text).toStrictEqual('hello 2 in english')
|
||||
expect(retrievedArray.array.es[0].text).toStrictEqual('hello in spanish')
|
||||
expect(retrievedArray.array.es[1].text).toStrictEqual('hello 2 in spanish')
|
||||
})
|
||||
})
|
||||
|
||||
describe('localized blocks', () => {
|
||||
let localizedBlocks;
|
||||
let localizedBlocks
|
||||
|
||||
it('creates localized blocks', async () => {
|
||||
localizedBlocks = await payload.create({
|
||||
@@ -505,11 +505,11 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(localizedBlocks.layout[0].text).toStrictEqual('hello in english');
|
||||
expect(localizedBlocks.layout[1].number).toStrictEqual(1337);
|
||||
});
|
||||
expect(localizedBlocks.layout[0].text).toStrictEqual('hello in english')
|
||||
expect(localizedBlocks.layout[1].number).toStrictEqual(1337)
|
||||
})
|
||||
|
||||
it('adds localized blocks', async () => {
|
||||
const updated = await payload.update({
|
||||
@@ -529,28 +529,28 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updated.layout[0].text).toStrictEqual('hello in spanish');
|
||||
expect(updated.layout[1].number).toStrictEqual(1338);
|
||||
});
|
||||
expect(updated.layout[0].text).toStrictEqual('hello in spanish')
|
||||
expect(updated.layout[1].number).toStrictEqual(1338)
|
||||
})
|
||||
|
||||
it('retrieves blocks field in all locales', async () => {
|
||||
const retrievedBlocks = await payload.findByID({
|
||||
collection: 'localized-blocks',
|
||||
id: localizedBlocks.id,
|
||||
locale: 'all',
|
||||
});
|
||||
})
|
||||
|
||||
expect(retrievedBlocks.layout.en[0].text).toStrictEqual('hello in english');
|
||||
expect(retrievedBlocks.layout.en[1].number).toStrictEqual(1337);
|
||||
expect(retrievedBlocks.layout.es[0].text).toStrictEqual('hello in spanish');
|
||||
expect(retrievedBlocks.layout.es[1].number).toStrictEqual(1338);
|
||||
});
|
||||
});
|
||||
expect(retrievedBlocks.layout.en[0].text).toStrictEqual('hello in english')
|
||||
expect(retrievedBlocks.layout.en[1].number).toStrictEqual(1337)
|
||||
expect(retrievedBlocks.layout.es[0].text).toStrictEqual('hello in spanish')
|
||||
expect(retrievedBlocks.layout.es[1].number).toStrictEqual(1338)
|
||||
})
|
||||
})
|
||||
|
||||
describe('localized group', () => {
|
||||
let localizedGroup;
|
||||
let localizedGroup
|
||||
|
||||
it('creates localized group', async () => {
|
||||
localizedGroup = await payload.create({
|
||||
@@ -561,11 +561,11 @@ describe('Postgres', () => {
|
||||
number: 123,
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(localizedGroup.group.text).toStrictEqual('en');
|
||||
expect(localizedGroup.group.number).toStrictEqual(123);
|
||||
});
|
||||
expect(localizedGroup.group.text).toStrictEqual('en')
|
||||
expect(localizedGroup.group.number).toStrictEqual(123)
|
||||
})
|
||||
|
||||
it('adds localized group', async () => {
|
||||
const updated = await payload.update({
|
||||
@@ -578,28 +578,28 @@ describe('Postgres', () => {
|
||||
number: 456,
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updated.group.text).toStrictEqual('es');
|
||||
expect(updated.group.number).toStrictEqual(456);
|
||||
});
|
||||
expect(updated.group.text).toStrictEqual('es')
|
||||
expect(updated.group.number).toStrictEqual(456)
|
||||
})
|
||||
|
||||
it('retrieves group field in all locales', async () => {
|
||||
const retrievedGroup = await payload.findByID({
|
||||
collection: 'localized-groups',
|
||||
id: localizedGroup.id,
|
||||
locale: 'all',
|
||||
});
|
||||
})
|
||||
|
||||
expect(retrievedGroup.group.en.text).toStrictEqual('en');
|
||||
expect(retrievedGroup.group.en.number).toStrictEqual(123);
|
||||
expect(retrievedGroup.group.es.text).toStrictEqual('es');
|
||||
expect(retrievedGroup.group.es.number).toStrictEqual(456);
|
||||
});
|
||||
});
|
||||
expect(retrievedGroup.group.en.text).toStrictEqual('en')
|
||||
expect(retrievedGroup.group.en.number).toStrictEqual(123)
|
||||
expect(retrievedGroup.group.es.text).toStrictEqual('es')
|
||||
expect(retrievedGroup.group.es.number).toStrictEqual(456)
|
||||
})
|
||||
})
|
||||
|
||||
describe('globals', () => {
|
||||
let mainMenu;
|
||||
let mainMenu
|
||||
it('creates global', async () => {
|
||||
mainMenu = await payload.updateGlobal({
|
||||
slug: 'main-menu',
|
||||
@@ -615,13 +615,13 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(mainMenu.title).toStrictEqual('hello in english');
|
||||
expect(mainMenu.nonLocalizedField).toStrictEqual('hello');
|
||||
expect(mainMenu.array[0].localizedText).toStrictEqual('row 1 en');
|
||||
expect(mainMenu.array[1].localizedText).toStrictEqual('row 2 en');
|
||||
});
|
||||
expect(mainMenu.title).toStrictEqual('hello in english')
|
||||
expect(mainMenu.nonLocalizedField).toStrictEqual('hello')
|
||||
expect(mainMenu.array[0].localizedText).toStrictEqual('row 1 en')
|
||||
expect(mainMenu.array[1].localizedText).toStrictEqual('row 2 en')
|
||||
})
|
||||
|
||||
it('adds locale to global', async () => {
|
||||
const updated = await payload.updateGlobal({
|
||||
@@ -640,27 +640,27 @@ describe('Postgres', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
expect(updated.title).toStrictEqual('hello in spanish');
|
||||
expect(updated.nonLocalizedField).toStrictEqual('hello');
|
||||
expect(updated.array[0].localizedText).toStrictEqual('row 1 es');
|
||||
expect(updated.array[1].localizedText).toStrictEqual('row 2 es');
|
||||
});
|
||||
expect(updated.title).toStrictEqual('hello in spanish')
|
||||
expect(updated.nonLocalizedField).toStrictEqual('hello')
|
||||
expect(updated.array[0].localizedText).toStrictEqual('row 1 es')
|
||||
expect(updated.array[1].localizedText).toStrictEqual('row 2 es')
|
||||
})
|
||||
|
||||
it('retrieves global in all locales', async () => {
|
||||
const retrieved = await payload.findGlobal({
|
||||
slug: 'main-menu',
|
||||
locale: 'all',
|
||||
});
|
||||
})
|
||||
|
||||
expect(retrieved.title.en).toStrictEqual('hello in english');
|
||||
expect(retrieved.title.es).toStrictEqual('hello in spanish');
|
||||
expect(retrieved.nonLocalizedField).toStrictEqual('hello');
|
||||
expect(retrieved.array[0].localizedText.en).toStrictEqual('row 1 en');
|
||||
expect(retrieved.array[1].localizedText.en).toStrictEqual('row 2 en');
|
||||
expect(retrieved.array[0].localizedText.es).toStrictEqual('row 1 es');
|
||||
expect(retrieved.array[1].localizedText.es).toStrictEqual('row 2 es');
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(retrieved.title.en).toStrictEqual('hello in english')
|
||||
expect(retrieved.title.es).toStrictEqual('hello in spanish')
|
||||
expect(retrieved.nonLocalizedField).toStrictEqual('hello')
|
||||
expect(retrieved.array[0].localizedText.en).toStrictEqual('row 1 en')
|
||||
expect(retrieved.array[1].localizedText.en).toStrictEqual('row 2 en')
|
||||
expect(retrieved.array[0].localizedText.es).toStrictEqual('row 1 es')
|
||||
expect(retrieved.array[1].localizedText.es).toStrictEqual('row 2 es')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { randomBytes } from 'crypto';
|
||||
import { randomBytes } from 'crypto'
|
||||
|
||||
import type {
|
||||
ChainedRelation,
|
||||
@@ -7,12 +7,12 @@ import type {
|
||||
Director,
|
||||
Post,
|
||||
Relation,
|
||||
} from './payload-types';
|
||||
} from './payload-types'
|
||||
|
||||
import payload from '../../packages/payload/src';
|
||||
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync';
|
||||
import { initPayloadTest } from '../helpers/configHelpers';
|
||||
import { RESTClient } from '../helpers/rest';
|
||||
import payload from '../../packages/payload/src'
|
||||
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync'
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
import { RESTClient } from '../helpers/rest'
|
||||
import config, {
|
||||
chainedRelSlug,
|
||||
customIdNumberSlug,
|
||||
@@ -20,7 +20,7 @@ import config, {
|
||||
defaultAccessRelSlug,
|
||||
relationSlug,
|
||||
slug,
|
||||
} from './config';
|
||||
} from './config'
|
||||
|
||||
let client: RESTClient
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import FormData from 'form-data';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { promisify } from 'util';
|
||||
import FormData from 'form-data'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { promisify } from 'util'
|
||||
|
||||
import payload from '../../packages/payload/src';
|
||||
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath';
|
||||
import { initPayloadTest } from '../helpers/configHelpers';
|
||||
import { RESTClient } from '../helpers/rest';
|
||||
import configPromise from './config';
|
||||
import { enlargeSlug, mediaSlug, reduceSlug, relationSlug } from './shared';
|
||||
import payload from '../../packages/payload/src'
|
||||
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath'
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
import { RESTClient } from '../helpers/rest'
|
||||
import configPromise from './config'
|
||||
import { enlargeSlug, mediaSlug, reduceSlug, relationSlug } from './shared'
|
||||
|
||||
const stat = promisify(fs.stat)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user