mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
test(review-workflow): add unit test for review workflows service
This commit is contained in:
parent
4f756d166d
commit
dc671f61ce
@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
const reviewWorkflowsServiceFactory = require('../review-workflows/review-workflows');
|
||||
|
||||
const workflowMock = {
|
||||
id: 1,
|
||||
};
|
||||
const stagesMock = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'stage 1',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'stage 2',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'stage 3',
|
||||
},
|
||||
];
|
||||
|
||||
const workflowsServiceMock = {
|
||||
count: jest.fn(() => 0),
|
||||
create: jest.fn(() => workflowMock),
|
||||
};
|
||||
const stagesServiceMock = {
|
||||
count: jest.fn(() => 0),
|
||||
createMany: jest.fn(() => stagesMock),
|
||||
};
|
||||
|
||||
const strapiMock = {
|
||||
service(serviceName) {
|
||||
switch (serviceName) {
|
||||
case 'admin::stages':
|
||||
return stagesServiceMock;
|
||||
case 'admin::workflows':
|
||||
return workflowsServiceMock;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const reviewWorkflowsService = reviewWorkflowsServiceFactory({ strapi: strapiMock });
|
||||
|
||||
describe('Review workflows service', () => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('bootstrap', () => {
|
||||
test('Without stages or workflows in DB', async () => {
|
||||
await reviewWorkflowsService.bootstrap();
|
||||
|
||||
expect(workflowsServiceMock.count).toBeCalled();
|
||||
expect(stagesServiceMock.count).toBeCalled();
|
||||
|
||||
expect(stagesServiceMock.createMany).toBeCalled();
|
||||
expect(workflowsServiceMock.create).toBeCalled();
|
||||
});
|
||||
test('With a workflow in DB', async () => {
|
||||
workflowsServiceMock.count.mockResolvedValue(1);
|
||||
await reviewWorkflowsService.bootstrap();
|
||||
|
||||
expect(workflowsServiceMock.count).toBeCalled();
|
||||
expect(stagesServiceMock.count).toBeCalled();
|
||||
|
||||
expect(stagesServiceMock.createMany).not.toBeCalled();
|
||||
expect(workflowsServiceMock.create).not.toBeCalled();
|
||||
});
|
||||
test('With stages in DB', async () => {
|
||||
stagesServiceMock.count.mockResolvedValue(5);
|
||||
await reviewWorkflowsService.bootstrap();
|
||||
|
||||
expect(workflowsServiceMock.count).toBeCalled();
|
||||
expect(stagesServiceMock.count).toBeCalled();
|
||||
|
||||
expect(stagesServiceMock.createMany).not.toBeCalled();
|
||||
expect(workflowsServiceMock.create).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -2,7 +2,12 @@
|
||||
|
||||
const { getService } = require('../../utils');
|
||||
|
||||
// Map every stage in the array to be ordered in the relation
|
||||
/**
|
||||
* Map every stage in the array to be ordered in the relation
|
||||
* @param {Object[]} stages
|
||||
* @param {number} stages.id
|
||||
* @return {Object[]}
|
||||
*/
|
||||
function buildStagesConnectArray(stages) {
|
||||
return stages.map((stage, index) => {
|
||||
const connect = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user