mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 01:17:28 +00:00
test: test update
This commit is contained in:
parent
4f7f540599
commit
d7b86fae3b
@ -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),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user