From d7b86fae3b94e0b53089330d4849fdf17c16ea28 Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Wed, 12 Apr 2023 12:22:25 +0200 Subject: [PATCH] test: test update --- .../entity-service-decorator.test.js | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/packages/core/admin/ee/server/services/review-workflows/__tests__/entity-service-decorator.test.js b/packages/core/admin/ee/server/services/review-workflows/__tests__/entity-service-decorator.test.js index 875ed0fdb6..d5f3ca4f40 100644 --- a/packages/core/admin/ee/server/services/review-workflows/__tests__/entity-service-decorator.test.js +++ b/packages/core/admin/ee/server/services/review-workflows/__tests__/entity-service-decorator.test.js @@ -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), + }, + }); + }); + }); });