From ace032ef897dc55131c6cf7cb80dc1a652940748 Mon Sep 17 00:00:00 2001 From: Jarrod Flesch Date: Mon, 6 Mar 2023 16:07:07 -0500 Subject: [PATCH] fix: minimize not set to false on all field type schemas --- src/mongoose/buildSchema.ts | 8 ++++++- test/fields/collections/JSON/index.tsx | 3 +++ test/fields/int.spec.ts | 31 +++++--------------------- test/globals/int.spec.ts | 13 ----------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/mongoose/buildSchema.ts b/src/mongoose/buildSchema.ts index d89c95f516..74c2a33fb8 100644 --- a/src/mongoose/buildSchema.ts +++ b/src/mongoose/buildSchema.ts @@ -335,6 +335,7 @@ const fieldToSchemaMap: Record = { options: { _id: false, id: false, + minimize: false, }, disableUnique: buildSchemaOptions.disableUnique, draftsEnabled: buildSchemaOptions.draftsEnabled, @@ -364,7 +365,11 @@ const fieldToSchemaMap: Record = { config, field.fields, { - options: { _id: false, id: false }, + options: { + _id: false, + id: false, + minimize: false, + }, allowIDField: true, disableUnique: buildSchemaOptions.disableUnique, draftsEnabled: buildSchemaOptions.draftsEnabled, @@ -388,6 +393,7 @@ const fieldToSchemaMap: Record = { options: { _id: false, id: false, + minimize: false, }, disableUnique: buildSchemaOptions.disableUnique, draftsEnabled: buildSchemaOptions.draftsEnabled, diff --git a/test/fields/collections/JSON/index.tsx b/test/fields/collections/JSON/index.tsx index 2f33199eab..451c26453d 100644 --- a/test/fields/collections/JSON/index.tsx +++ b/test/fields/collections/JSON/index.tsx @@ -10,6 +10,9 @@ type JSONField = { const JSON: CollectionConfig = { slug: 'json-fields', + versions: { + maxPerDoc: 1, + }, fields: [ { name: 'json', diff --git a/test/fields/int.spec.ts b/test/fields/int.spec.ts index 98590b7f69..9f3ea9fd84 100644 --- a/test/fields/int.spec.ts +++ b/test/fields/int.spec.ts @@ -529,7 +529,7 @@ describe('Fields', () => { }); it('should save empty json objects', async () => { - const createdJSON = await payload.create({ + const jsonFieldsDoc = await payload.create({ collection: 'json-fields', data: { json: { @@ -538,30 +538,11 @@ describe('Fields', () => { }, }); - expect(createdJSON.json.state).toEqual({}); - }); + expect(jsonFieldsDoc.json.state).toEqual({}); - it('should save empty json objects via REST', async () => { - const jsonClient = new RESTClient(config, { serverURL, defaultSlug: 'json-fields' }); - await jsonClient.login(); - - const { doc: ogDoc } = await jsonClient.create({ - auth: true, - data: { - json: { - empty: {}, - state: { - foo: 'bar', - }, - }, - }, - }); - - expect(ogDoc.json.empty).toEqual({}); - - const { doc } = await jsonClient.update({ - auth: true, - id: ogDoc.id, + const updatedJsonFieldsDoc = await payload.update({ + collection: 'json-fields', + id: jsonFieldsDoc.id, data: { json: { state: {}, @@ -569,7 +550,7 @@ describe('Fields', () => { }, }); - expect(doc.json.state).toEqual({}); + expect(updatedJsonFieldsDoc.json.state).toEqual({}); }); }); diff --git a/test/globals/int.spec.ts b/test/globals/int.spec.ts index 46a8e9978c..7bd009e208 100644 --- a/test/globals/int.spec.ts +++ b/test/globals/int.spec.ts @@ -57,19 +57,6 @@ describe('globals', () => { expect(doc.array).toMatchObject(array); expect(doc.id).toBeDefined(); }); - - it('should save empty json objects', async () => { - const { doc } = await client.updateGlobal({ - slug, - data: { - json: { - state: {}, - }, - }, - }); - - expect(doc.json.state).toEqual({}); - }); }); describe('local', () => {