mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
fix(review-workflow): rework stages methods naming
Fixes the integration tests
This commit is contained in:
parent
f607a61607
commit
94808bc221
@ -27,7 +27,7 @@ module.exports = {
|
|||||||
const { populate } = ctx.query;
|
const { populate } = ctx.query;
|
||||||
|
|
||||||
const workflowService = getService('workflows');
|
const workflowService = getService('workflows');
|
||||||
const data = await workflowService.findOne(id, populate);
|
const data = await workflowService.findById(id, { populate });
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data,
|
data,
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { merge } = require('lodash/fp');
|
const { getService } = require('../../../utils');
|
||||||
const { getService, mapObject } = require('../../../utils');
|
|
||||||
|
|
||||||
function sanitizeStageQuery(query = {}) {
|
|
||||||
return mapObject(query, {
|
|
||||||
pick: ['workflow_id', 'stage_id', 'populate'],
|
|
||||||
rename: { workflow_id: 'workflowId', stage_id: 'id' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
@ -16,17 +8,17 @@ module.exports = {
|
|||||||
* @param {import('koa').BaseContext} ctx - koa context
|
* @param {import('koa').BaseContext} ctx - koa context
|
||||||
*/
|
*/
|
||||||
async find(ctx) {
|
async find(ctx) {
|
||||||
const query = sanitizeStageQuery(merge(ctx.query, ctx.params));
|
const { id } = ctx.params;
|
||||||
|
const { populate } = ctx.query;
|
||||||
const stagesService = getService('stages');
|
const stagesService = getService('stages');
|
||||||
|
|
||||||
const results = await stagesService.find({
|
const data = await stagesService.find({
|
||||||
workflowId: query.workflowId,
|
workflowId: id,
|
||||||
populate: query.populate,
|
populate,
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
results,
|
data,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -34,13 +26,13 @@ module.exports = {
|
|||||||
* @param {import('koa').BaseContext} ctx - koa context
|
* @param {import('koa').BaseContext} ctx - koa context
|
||||||
*/
|
*/
|
||||||
async findOne(ctx) {
|
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 stagesService = getService('stages');
|
||||||
|
|
||||||
const data = await stagesService.findOne(query.id, {
|
const data = await stagesService.findById(id, {
|
||||||
workflowId: query.workflowId,
|
workflowId,
|
||||||
populate: query.populate,
|
populate,
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
|||||||
@ -179,7 +179,7 @@ module.exports = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/review-workflows/workflows/:workflow_id/stages/:stage_id',
|
path: '/review-workflows/workflows/:workflow_id/stages/:id',
|
||||||
handler: 'stages.findOne',
|
handler: 'stages.findOne',
|
||||||
config: {
|
config: {
|
||||||
middlewares: [enableFeatureMiddleware('review-workflows')],
|
middlewares: [enableFeatureMiddleware('review-workflows')],
|
||||||
|
|||||||
@ -11,7 +11,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return strapi.entityService.findMany(STAGE_MODEL_UID, params);
|
return strapi.entityService.findMany(STAGE_MODEL_UID, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
findOne(id, { workflowId, populate }) {
|
findById(id, { workflowId, populate }) {
|
||||||
const params = {
|
const params = {
|
||||||
filter: { workflow: workflowId },
|
filter: { workflow: workflowId },
|
||||||
populate,
|
populate,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
return strapi.entityService.findMany(WORKFLOW_MODEL_UID, opts);
|
return strapi.entityService.findMany(WORKFLOW_MODEL_UID, opts);
|
||||||
},
|
},
|
||||||
|
|
||||||
findById(id) {
|
findById(id, opts) {
|
||||||
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, {});
|
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, opts);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -95,16 +95,25 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Get workflow stages', () => {
|
describe('Get workflow stages', () => {
|
||||||
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
|
test("It shouldn't be available for public", async () => {
|
||||||
const rq = requests[type];
|
const res = await requests.public.get('/admin/review-workflows/workflows?populate=stages');
|
||||||
const res = await rq.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) {
|
if (hasRW) {
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
expect(Array.isArray(res.body.results)).toBeTruthy();
|
expect(Array.isArray(res.body.data)).toBeTruthy();
|
||||||
expect(res.body.results).toHaveLength(1);
|
expect(res.body.data).toHaveLength(1);
|
||||||
expect(res.body.results[0].stages).toHaveLength(1);
|
expect(res.body.data[0].stages).toHaveLength(1);
|
||||||
expect(res.body.results[0].stages[0]).toEqual(defaultStage);
|
expect(res.body.data[0].stages[0]).toEqual(defaultStage);
|
||||||
} else {
|
} else {
|
||||||
expect(res.status).toBe(404);
|
expect(res.status).toBe(404);
|
||||||
expect(Array.isArray(res.body)).toBeFalsy();
|
expect(Array.isArray(res.body)).toBeFalsy();
|
||||||
@ -113,14 +122,27 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Get stages', () => {
|
describe('Get stages', () => {
|
||||||
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
|
test("It shouldn't be available for public", async () => {
|
||||||
const rq = requests[type];
|
const res = await requests.public.get(
|
||||||
const res = await rq.get(`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages`);
|
`/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) {
|
if (hasRW) {
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
expect(Array.isArray(res.body.results)).toBeTruthy();
|
expect(Array.isArray(res.body.data)).toBeTruthy();
|
||||||
expect(res.body.results).toHaveLength(1);
|
expect(res.body.data).toHaveLength(1);
|
||||||
} else {
|
} else {
|
||||||
expect(res.status).toBe(404);
|
expect(res.status).toBe(404);
|
||||||
expect(Array.isArray(res.body)).toBeFalsy();
|
expect(Array.isArray(res.body)).toBeFalsy();
|
||||||
@ -129,9 +151,20 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Get stage by id', () => {
|
describe('Get stage by id', () => {
|
||||||
test.each(Object.keys(requests))('It should be available for everyone (%s)', async (type) => {
|
test("It shouldn't be available for public", async () => {
|
||||||
const rq = requests[type];
|
const res = await requests.public.get(
|
||||||
const res = await rq.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}`
|
`/admin/review-workflows/workflows/${defaultWorkflow.id}/stages/${defaultStage.id}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a test suite only if the condition is true
|
* Execute a test suite only if the condition is true
|
||||||
|
* @return Jest.Describe
|
||||||
*/
|
*/
|
||||||
const describeOnCondition = (bool) => (bool ? describe : describe.skip);
|
const describeOnCondition = (bool) => (bool ? describe : describe.skip);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user