use data format + init e2e tests

This commit is contained in:
Pierre Noël 2022-10-07 20:33:30 +02:00
parent 29d567198c
commit 8f73a1d761
3 changed files with 139 additions and 2 deletions

View File

@ -261,6 +261,10 @@ module.exports = {
return ctx.forbidden(); return ctx.forbidden();
} }
return entityManager.getNumberOfDraftRelations(id, model); const number = await entityManager.getNumberOfDraftRelations(id, model);
return {
data: number,
};
}, },
}; };

View File

@ -195,6 +195,10 @@ module.exports = {
return ctx.forbidden(); return ctx.forbidden();
} }
return entityManager.getNumberOfDraftRelations(entity.id, model); const number = await entityManager.getNumberOfDraftRelations(entity.id, model);
return {
data: number,
};
}, },
}; };

View File

@ -0,0 +1,129 @@
'use strict';
const { createStrapiInstance } = require('../../../../../../test/helpers/strapi');
const { createTestBuilder } = require('../../../../../../test/helpers/builder');
const { createAuthRequest } = require('../../../../../../test/helpers/request');
const builder = createTestBuilder();
let strapi;
let rq;
const product = {
displayName: 'Product',
singularName: 'product',
pluralName: 'products',
description: '',
collectionName: '',
attributes: {
name: {
type: 'string',
required: true,
},
categoriesdp: {
type: 'relation',
relation: 'oneToMany',
target: 'api::categorydp.categorydp',
targetAttribute: 'product',
},
categories: {
type: 'relation',
relation: 'oneToMany',
target: 'api::category.category',
targetAttribute: 'product',
},
compo: {
component: 'default.compo',
type: 'component',
},
comporep: {
component: 'default.compo',
type: 'component',
},
dz: {
components: ['default.compo'],
type: 'dynamiczone',
},
},
};
const categoryDP = {
displayName: 'Category Draft & Publish',
singularName: 'categorydp',
pluralName: 'categoriesdp',
draftAndPublish: true,
attributes: {
name: {
type: 'string',
unique: true,
},
},
};
const category = {
displayName: 'Category',
singularName: 'category',
pluralName: 'categories',
attributes: {
name: {
type: 'string',
unique: true,
},
},
};
const compo = {
displayName: 'compo',
attributes: {
name: {
type: 'string',
required: true,
},
categoriesdp: {
type: 'relation',
relation: 'oneToMany',
target: 'api::categorydp.categorydp',
targetAttribute: 'product',
},
categories: {
type: 'relation',
relation: 'oneToMany',
target: 'api::category.category',
targetAttribute: 'product',
},
},
};
describe('CM API - Basic', () => {
beforeAll(async () => {
await builder
.addContentTypes([categoryDP, category])
.addComponent(compo)
.addContentTypes([product])
.build();
strapi = await createStrapiInstance();
rq = await createAuthRequest({ strapi });
});
afterAll(async () => {
await strapi.destroy();
await builder.cleanup();
});
test('Return 0 when no relations are set', async () => {
const { body: product } = await rq({
method: 'POST',
url: '/content-manager/collection-types/api::product.product',
body: {
name: 'Pizza',
},
});
const { body } = await rq({
method: 'GET',
url: `/content-manager/collection-types/api::product.product/${product.id}/actions/numberOfDraftRelations`,
});
expect(body.data).toBe(0);
});
});