mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 14:59:07 +00:00
fix stages tests
This commit is contained in:
parent
7efabcaf46
commit
b5a1c49e31
@ -69,6 +69,8 @@ const servicesMock = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const queryUpdateMock = jest.fn(() => true);
|
||||||
|
|
||||||
const strapiMock = {
|
const strapiMock = {
|
||||||
query: jest.fn(() => ({
|
query: jest.fn(() => ({
|
||||||
findOne: jest.fn(() => workflowMock),
|
findOne: jest.fn(() => workflowMock),
|
||||||
@ -78,7 +80,30 @@ const strapiMock = {
|
|||||||
return servicesMock[serviceName];
|
return servicesMock[serviceName];
|
||||||
}),
|
}),
|
||||||
db: {
|
db: {
|
||||||
transaction: jest.fn((func) => func()),
|
transaction: jest.fn((func) => func({})),
|
||||||
|
query: jest.fn(() => ({
|
||||||
|
updateMany: queryUpdateMock,
|
||||||
|
})),
|
||||||
|
metadata: {
|
||||||
|
get: () => ({
|
||||||
|
attributes: {
|
||||||
|
strapi_reviewWorkflows_stage: {
|
||||||
|
joinColumn: {
|
||||||
|
name: 'strapi_reviewWorkflows_stage_id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
contentTypes: {
|
||||||
|
'api::shop.shop': {
|
||||||
|
kind: 'collectionType',
|
||||||
|
collectionName: 'shop',
|
||||||
|
options: {
|
||||||
|
reviewWorkflows: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,12 +190,10 @@ describe('Review workflows - Stages service', () => {
|
|||||||
expect(entityServiceMock.delete).toBeCalled();
|
expect(entityServiceMock.delete).toBeCalled();
|
||||||
|
|
||||||
// Here we are only deleting the stage containing related IDs 1 & 2
|
// Here we are only deleting the stage containing related IDs 1 & 2
|
||||||
for (let i = 0; i < 2; i += 1) {
|
expect(queryUpdateMock).toBeCalledWith({
|
||||||
expect(entityServiceMock.update).toBeCalledWith(relatedUID, i + 1, {
|
data: { strapi_reviewWorkflows_stage_id: 3 },
|
||||||
data: { strapi_reviewWorkflows_stage: 3 },
|
where: { strapi_reviewWorkflows_stage_id: 4 },
|
||||||
populate: ['strapi_reviewWorkflows_stage'],
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(servicesMock['admin::workflows'].update).toBeCalled();
|
expect(servicesMock['admin::workflows'].update).toBeCalled();
|
||||||
expect(servicesMock['admin::workflows'].update).toBeCalledWith(workflowMock.id, {
|
expect(servicesMock['admin::workflows'].update).toBeCalledWith(workflowMock.id, {
|
||||||
@ -189,10 +212,10 @@ describe('Review workflows - Stages service', () => {
|
|||||||
expect(entityServiceMock.delete).toBeCalled();
|
expect(entityServiceMock.delete).toBeCalled();
|
||||||
|
|
||||||
// Here we are deleting all stages and expecting all entities to be moved to the new stage
|
// Here we are deleting all stages and expecting all entities to be moved to the new stage
|
||||||
for (let i = 0; i < 3; i += 1) {
|
for (const stage of workflowMock.stages) {
|
||||||
expect(entityServiceMock.update).toBeCalledWith(relatedUID, i + 1, {
|
expect(queryUpdateMock).toBeCalledWith({
|
||||||
data: { strapi_reviewWorkflows_stage: newStageID },
|
data: { strapi_reviewWorkflows_stage_id: newStageID },
|
||||||
populate: ['strapi_reviewWorkflows_stage'],
|
where: { strapi_reviewWorkflows_stage_id: stage.id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user