test: test update

This commit is contained in:
Marc-Roig 2023-04-12 12:22:25 +02:00
parent 4f7f540599
commit d7b86fae3b

View File

@ -1,6 +1,7 @@
'use strict';
const { decorator } = require('../entity-service-decorator')();
const { omit } = require('lodash/fp');
jest.mock('../../../utils');
@ -77,4 +78,71 @@ describe('Entity service decorator', () => {
});
});
});
describe('Update', () => {
test('Calls original update for non review workflow content types', async () => {
const entry = {
id: 1,
};
const defaultService = {
update: jest.fn(() => Promise.resolve(entry)),
};
const service = decorator(defaultService);
const id = 1;
const input = { data: { title: 'title ' } };
await service.update('non-rw-model', id, input);
expect(defaultService.update).toHaveBeenCalledWith('non-rw-model', id, input);
});
test('Assigns a stage to new review workflow entity', async () => {
const entry = {
id: 1,
};
const defaultService = {
update: jest.fn(() => Promise.resolve(entry)),
};
const service = decorator(defaultService);
const id = 1;
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: 1 } };
await service.update('test-model', id, input);
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
...input,
data: {
...input.data,
strapi_reviewWorkflows_stage: 1,
},
});
});
test('Can not assign a null stage to new review workflow entity', async () => {
const entry = {
id: 1,
};
const defaultService = {
update: jest.fn(() => Promise.resolve(entry)),
};
const service = decorator(defaultService);
const id = 1;
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: null } };
await service.update('test-model', id, input);
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
...input,
data: {
...omit('strapi_reviewWorkflows_stage', input.data),
},
});
});
});
});