chore: builds rows on init, refactors preferences for documents

This commit is contained in:
Jarrod Flesch
2023-06-07 22:21:08 -04:00
parent 551f1bd09f
commit 87554e9b16
22 changed files with 221 additions and 220 deletions

View File

@@ -6,7 +6,7 @@ export default buildConfig({
slug: 'arrays',
fields: [
{
name: 'array',
name: 'arrayOfFields',
type: 'array',
fields: [
{
@@ -18,6 +18,21 @@ export default buildConfig({
type: 'text',
name: 'optional',
},
{
name: 'innerArrayOfFields',
type: 'array',
fields: [
{
type: 'text',
name: 'required',
required: true,
},
{
type: 'text',
name: 'optional',
},
],
},
],
},
],

View File

@@ -24,7 +24,7 @@ describe('array-update', () => {
const doc = await payload.create({
collection,
data: {
array: [
arrayOfFields: [
{
required: 'a required field here',
optional: originalText,
@@ -37,7 +37,7 @@ describe('array-update', () => {
},
});
const arrayWithExistingValues = [...doc.array];
const arrayWithExistingValues = [...doc.arrayOfFields];
const updatedText = 'this is some new text for the first item in array';
@@ -50,11 +50,11 @@ describe('array-update', () => {
id: doc.id,
collection,
data: {
array: arrayWithExistingValues,
arrayOfFields: arrayWithExistingValues,
},
});
expect(updatedDoc.array?.[0]).toMatchObject({
expect(updatedDoc.arrayOfFields?.[0]).toMatchObject({
required: updatedText,
optional: originalText,
});
@@ -71,7 +71,7 @@ describe('array-update', () => {
const doc = await payload.create({
collection,
data: {
array: [
arrayOfFields: [
{
required: 'a required field here',
optional: 'some optional text',
@@ -85,13 +85,13 @@ describe('array-update', () => {
id: doc.id,
collection,
data: {
array: [
arrayOfFields: [
{
required: updatedText,
},
{
id: doc.array?.[1].id,
required: doc.array?.[1].required as string,
id: doc.arrayOfFields?.[1].id,
required: doc.arrayOfFields?.[1].required as string,
// NOTE - not passing optional field. It should persist
// because we're passing ID
},
@@ -99,9 +99,9 @@ describe('array-update', () => {
},
});
expect(updatedDoc.array?.[0].required).toStrictEqual(updatedText);
expect(updatedDoc.array?.[0].optional).toBeUndefined();
expect(updatedDoc.arrayOfFields?.[0].required).toStrictEqual(updatedText);
expect(updatedDoc.arrayOfFields?.[0].optional).toBeUndefined();
expect(updatedDoc.array?.[1]).toMatchObject(secondArrayItem);
expect(updatedDoc.arrayOfFields?.[1]).toMatchObject(secondArrayItem);
});
});