tests: updating entity relations does not break other relations

This commit is contained in:
Marc-Roig 2023-07-11 15:37:54 +02:00
parent 43f56d426e
commit ee2cd841c9
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -639,6 +639,61 @@ describe('Relations', () => {
});
});
describe('Update entity relations does not break other relations', () => {
test('Update and disconnect relation does not break other relations', async () => {
// Create 2 entries connected to the same relations
const shops = [];
for (let i = 0; i < 2; i++) {
const createdShop = await createEntry(
'shop',
{
name: 'Cazotte Shop',
products_ow: { connect: [id1] },
products_oo: { connect: [id1] },
products_mo: { connect: [id1] },
products_om: { connect: [id1, id2] },
products_mm: { connect: [id1, id2] },
products_mw: { connect: [id1, id2] },
myCompo: {
compo_products_ow: { connect: [id1] },
compo_products_mw: { connect: [id1, id2] },
},
},
['myCompo']
);
shops.push(createdShop);
}
// Update shop 1 relation order
await updateEntry(
'shop',
shops[0].id,
{
name: 'Cazotte Shop',
products_om: { disconnect: [id2] },
products_mm: { disconnect: [id2] },
products_mw: { disconnect: [id2] },
myCompo: {
id: shops[0].myCompo.id,
compo_products_mw: { disconnect: [id2] },
},
},
[]
);
const updatedShop2 = await strapi.entityService.findOne('api::shop.shop', shops[1].id, {
populate: populateShop,
});
// shop2 relations should be unchanged (content-manager relations are shown in reverse order)
expect(updatedShop2.products_om).toMatchObject([{ id: id2 }, { id: id1 }]);
expect(updatedShop2.products_mm).toMatchObject([{ id: id2 }, { id: id1 }]);
expect(updatedShop2.products_mw).toMatchObject([{ id: id2 }, { id: id1 }]);
expect(updatedShop2.myCompo.compo_products_mw).toMatchObject([{ id: id2 }, { id: id1 }]);
});
});
describe('Reorder an entity relations', () => {
test('Reorder single relation', async () => {
const createdShop = await createEntry(