diff --git a/packages/strapi-hook-mongoose/lib/mount-models.js b/packages/strapi-hook-mongoose/lib/mount-models.js index 1f47e8515c..9b1c7f4425 100644 --- a/packages/strapi-hook-mongoose/lib/mount-models.js +++ b/packages/strapi-hook-mongoose/lib/mount-models.js @@ -347,10 +347,10 @@ const createOnFetchPopulateFn = ({ ) { this._mongooseOptions.populate[name].path = `${name}.ref`; } else { - this._mongooseOptions.populate[name] = { + _.set(this._mongooseOptions, ['populate', name], { path: `${name}.ref`, _docs: {}, - }; + }); } }); diff --git a/packages/strapi-hook-mongoose/lib/queries.js b/packages/strapi-hook-mongoose/lib/queries.js index d07a828d2d..9279fac51b 100644 --- a/packages/strapi-hook-mongoose/lib/queries.js +++ b/packages/strapi-hook-mongoose/lib/queries.js @@ -267,9 +267,10 @@ module.exports = ({ model, modelKey, strapi }) => { const relations = pickRelations(values); const data = omitExernalValues(values); + // update groups first in case it fails don't update the entity + await updateGroups(entry, values); // Update entry with no-relational data. await entry.updateOne(data); - await updateGroups(entry, values); // Update relational data and return the entry. return model.updateRelations(Object.assign(params, { values: relations })); diff --git a/packages/strapi-plugin-content-manager/test/groups/repeatable-min-max.test.e2e.js b/packages/strapi-plugin-content-manager/test/groups/repeatable-min-max.test.e2e.js index f5a83ad94a..5483e6bc3c 100644 --- a/packages/strapi-plugin-content-manager/test/groups/repeatable-min-max.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/groups/repeatable-min-max.test.e2e.js @@ -227,7 +227,10 @@ describe.each([ const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); } ); @@ -307,12 +310,18 @@ describe.each([ }); expect(updateRes.statusCode).toBe(200); - expect(updateRes.body).toEqual(res.body); + expect(updateRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); }); test('Throws when not enough items', async () => { diff --git a/packages/strapi-plugin-content-manager/test/groups/repeatable-not-required.test.e2e.js b/packages/strapi-plugin-content-manager/test/groups/repeatable-not-required.test.e2e.js index 6e6fba03b0..32a8b94a51 100644 --- a/packages/strapi-plugin-content-manager/test/groups/repeatable-not-required.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/groups/repeatable-not-required.test.e2e.js @@ -197,7 +197,10 @@ describe.each([ const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); } ); @@ -277,12 +280,18 @@ describe.each([ }); expect(updateRes.statusCode).toBe(200); - expect(updateRes.body).toEqual(res.body); + expect(updateRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); }); test('Removes previous groups if empty array sent', async () => { diff --git a/packages/strapi-plugin-content-manager/test/groups/repeatable-required.test.e2e.js b/packages/strapi-plugin-content-manager/test/groups/repeatable-required.test.e2e.js index 6391589213..c9922f9759 100644 --- a/packages/strapi-plugin-content-manager/test/groups/repeatable-required.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/groups/repeatable-required.test.e2e.js @@ -196,7 +196,10 @@ describe.each([ const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); } ); @@ -276,12 +279,18 @@ describe.each([ }); expect(updateRes.statusCode).toBe(200); - expect(updateRes.body).toEqual(res.body); + expect(updateRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); }); test('Removes previous groups if empty array sent', async () => { diff --git a/packages/strapi-plugin-content-manager/test/groups/single-not-required.test.e2e.js b/packages/strapi-plugin-content-manager/test/groups/single-not-required.test.e2e.js index 4f89dd96cb..b9465bb799 100644 --- a/packages/strapi-plugin-content-manager/test/groups/single-not-required.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/groups/single-not-required.test.e2e.js @@ -153,7 +153,10 @@ describe.each([ const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); } ); @@ -171,12 +174,18 @@ describe.each([ }); expect(updateRes.statusCode).toBe(200); - expect(updateRes.body).toEqual(res.body); + expect(updateRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); }); test('Removes previous group if null sent', async () => { diff --git a/packages/strapi-plugin-content-manager/test/groups/single-required.test.e2e.js b/packages/strapi-plugin-content-manager/test/groups/single-required.test.e2e.js index f05c9180c1..27003624dd 100644 --- a/packages/strapi-plugin-content-manager/test/groups/single-required.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/groups/single-required.test.e2e.js @@ -151,7 +151,10 @@ describe.each([ const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); } ); @@ -169,12 +172,18 @@ describe.each([ }); expect(updateRes.statusCode).toBe(200); - expect(updateRes.body).toEqual(res.body); + expect(updateRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); const getRes = await rq.get(`/${res.body.id}`); expect(getRes.statusCode).toBe(200); - expect(getRes.body).toEqual(res.body); + expect(getRes.body).toMatchObject({ + id: res.body.id, + field: res.body.field, + }); }); test('Throws if group is null', async () => {