fix permission + simplify test

This commit is contained in:
Pierre Noël 2022-08-12 16:01:52 +02:00
parent 35a13433f0
commit c84ad063bb
2 changed files with 16 additions and 19 deletions

View File

@ -29,7 +29,7 @@ module.exports = {
const entityManager = getService('entity-manager'); const entityManager = getService('entity-manager');
const permissionChecker = getService('permission-checker').create({ const permissionChecker = getService('permission-checker').create({
userAbility, userAbility,
model: sourceModel, model,
}); });
if (permissionChecker.cannot.read()) { if (permissionChecker.cannot.read()) {

View File

@ -61,6 +61,15 @@ const shopModel = {
pluralName: 'shops', pluralName: 'shops',
}; };
const createEntry = async (uid, data) => {
const { body } = await rq({
method: 'POST',
url: `/content-manager/collection-types/${uid}`,
body: data,
});
return body;
};
describe('Relations', () => { describe('Relations', () => {
const builder = createTestBuilder(); const builder = createTestBuilder();
@ -74,28 +83,16 @@ describe('Relations', () => {
strapi = await createStrapiInstance(); strapi = await createStrapiInstance();
rq = await createAuthRequest({ strapi }); rq = await createAuthRequest({ strapi });
const { body: createdProduct1 } = await rq({ const createdProduct1 = await createEntry('api::product.product', { name: 'Skate' });
method: 'POST', const createdProduct2 = await createEntry('api::product.product', { name: 'Candle' });
url: '/content-manager/collection-types/api::product.product',
body: { name: 'Skate' },
});
const { body: createdProduct2 } = await rq({
method: 'POST',
url: '/content-manager/collection-types/api::product.product',
body: { name: 'Candle' },
});
data.products.push(createdProduct1); data.products.push(createdProduct1);
data.products.push(createdProduct2); data.products.push(createdProduct2);
const { body: createdShop } = await rq({ const createdShop = await createEntry('api::shop.shop', {
method: 'POST',
url: '/content-manager/collection-types/api::shop.shop',
body: {
name: 'Cazotte Shop', name: 'Cazotte Shop',
products: [createdProduct1.id], products: [createdProduct1.id],
myCompo: { compoProducts: [createdProduct2.id] }, myCompo: { compoProducts: [createdProduct2.id] },
},
}); });
data.shops.push(createdShop); data.shops.push(createdShop);