fix(review-workflow): rework stages methods naming

Fixes the integration tests
This commit is contained in:
nathan-pichon 2023-01-31 12:26:58 +01:00
parent f607a61607
commit 94808bc221
No known key found for this signature in database
7 changed files with 66 additions and 40 deletions

View File

@ -27,7 +27,7 @@ module.exports = {
const { populate } = ctx.query;
const workflowService = getService('workflows');
const data = await workflowService.findOne(id, populate);
const data = await workflowService.findById(id, { populate });
ctx.body = {
data,

View File

@ -1,14 +1,6 @@
'use strict';
const { merge } = require('lodash/fp');
const { getService, mapObject } = require('../../../utils');
function sanitizeStageQuery(query = {}) {
return mapObject(query, {
pick: ['workflow_id', 'stage_id', 'populate'],
rename: { workflow_id: 'workflowId', stage_id: 'id' },
});
}
const { getService } = require('../../../utils');
module.exports = {
/**
@ -16,17 +8,17 @@ module.exports = {
* @param {import('koa').BaseContext} ctx - koa context
*/
async find(ctx) {
const query = sanitizeStageQuery(merge(ctx.query, ctx.params));
const { id } = ctx.params;
const { populate } = ctx.query;
const stagesService = getService('stages');
const results = await stagesService.find({
workflowId: query.workflowId,
populate: query.populate,
const data = await stagesService.find({
workflowId: id,
populate,
});
ctx.body = {
results,
data,
};
},
/**
@ -34,13 +26,13 @@ module.exports = {
* @param {import('koa').BaseContext} ctx - koa context
*/
async findOne(ctx) {
const query = sanitizeStageQuery(merge(ctx.query, ctx.params));
const { id, workflow_id: workflowId } = ctx.params;
const { populate } = ctx.query;
const stagesService = getService('stages');
const data = await stagesService.findOne(query.id, {
workflowId: query.workflowId,
populate: query.populate,
const data = await stagesService.findById(id, {
workflowId,
populate,
});
ctx.body = {

View File

@ -179,7 +179,7 @@ module.exports = [
},
{
method: 'GET',
path: '/review-workflows/workflows/:workflow_id/stages/:stage_id',
path: '/review-workflows/workflows/:workflow_id/stages/:id',
handler: 'stages.findOne',
config: {
middlewares: [enableFeatureMiddleware('review-workflows')],

View File

@ -11,7 +11,7 @@ module.exports = ({ strapi }) => ({
return strapi.entityService.findMany(STAGE_MODEL_UID, params);
},
findOne(id, { workflowId, populate }) {
findById(id, { workflowId, populate }) {
const params = {
filter: { workflow: workflowId },
populate,

View File

@ -7,7 +7,7 @@ module.exports = ({ strapi }) => ({
return strapi.entityService.findMany(WORKFLOW_MODEL_UID, opts);
},
findById(id) {
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, {});
findById(id, opts) {
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, opts);
},
});

View File

@ -95,16 +95,25 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
});
describe('Get workflow stages', () => {
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
const rq = requests[type];
const res = await rq.get('/admin/review-workflows/workflows?populate=stages');
test("It shouldn't be available for public", async () => {
const res = await requests.public.get('/admin/review-workflows/workflows?populate=stages');
if (hasRW) {
expect(res.status).toBe(401);
} else {
expect(res.status).toBe(404);
expect(res.body.data).toBeUndefined();
}
});
test('It should be available for every connected users (admin)', async () => {
const res = await requests.admin.get('/admin/review-workflows/workflows?populate=stages');
if (hasRW) {
expect(res.status).toBe(200);
expect(Array.isArray(res.body.results)).toBeTruthy();
expect(res.body.results).toHaveLength(1);
expect(res.body.results[0].stages).toHaveLength(1);
expect(res.body.results[0].stages[0]).toEqual(defaultStage);
expect(Array.isArray(res.body.data)).toBeTruthy();
expect(res.body.data).toHaveLength(1);
expect(res.body.data[0].stages).toHaveLength(1);
expect(res.body.data[0].stages[0]).toEqual(defaultStage);
} else {
expect(res.status).toBe(404);
expect(Array.isArray(res.body)).toBeFalsy();
@ -113,14 +122,27 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
});
describe('Get stages', () => {
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
const rq = requests[type];
const res = await rq.get(`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages`);
test("It shouldn't be available for public", async () => {
const res = await requests.public.get(
`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages`
);
if (hasRW) {
expect(res.status).toBe(401);
} else {
expect(res.status).toBe(404);
expect(res.body.data).toBeUndefined();
}
});
test('It should be available for every connected users (admin)', async () => {
const res = await requests.admin.get(
`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages`
);
if (hasRW) {
expect(res.status).toBe(200);
expect(Array.isArray(res.body.results)).toBeTruthy();
expect(res.body.results).toHaveLength(1);
expect(Array.isArray(res.body.data)).toBeTruthy();
expect(res.body.data).toHaveLength(1);
} else {
expect(res.status).toBe(404);
expect(Array.isArray(res.body)).toBeFalsy();
@ -129,9 +151,20 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
});
describe('Get stage by id', () => {
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
const rq = requests[type];
const res = await rq.get(
test("It shouldn't be available for public", async () => {
const res = await requests.public.get(
`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages/${defaultStage.id}`
);
if (hasRW) {
expect(res.status).toBe(401);
} else {
expect(res.status).toBe(404);
expect(res.body.data).toBeUndefined();
}
});
test('It should be available for every connected users (admin)', async () => {
const res = await requests.admin.get(
`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages/${defaultStage.id}`
);

View File

@ -2,6 +2,7 @@
/**
* Execute a test suite only if the condition is true
* @return Jest.Describe
*/
const describeOnCondition = (bool) => (bool ? describe : describe.skip);