From 1f9d81b6668beb82b4f211db32b621d01937503f Mon Sep 17 00:00:00 2001 From: Arcadio Quintero Date: Thu, 14 Nov 2024 13:17:21 -0500 Subject: [PATCH] feat(edit-content) add test --- .../dot-workflows-actions.service.spec.ts | 53 +++++++++++++++++++ .../dot-workflows-actions.service.ts | 28 +++++----- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.spec.ts b/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.spec.ts index 598634f59fce..5c9aa7363d45 100644 --- a/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.spec.ts +++ b/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.spec.ts @@ -56,4 +56,57 @@ describe('DotWorkflowsActionsService', () => { entity: mockResponse }); }); + + it('should get workflow actions by content type name', (done) => { + const contentTypeName = 'Blog'; + const mockWorkflowActionsResponse = [ + { + scheme: mockWorkflows[0], + action: mockWorkflowsActions[0], + firstStep: { + id: '123', + name: 'First Step', + creationDate: 0, + enableEscalation: false, + escalationAction: null, + escalationTime: 0, + resolved: false, + schemeId: '123', + myOrder: 0 + } + } + ]; + + spectator.service.getWorkFlowActions(contentTypeName).subscribe((res) => { + expect(res).toEqual(mockWorkflowActionsResponse); + done(); + }); + + spectator + .expectOne( + `/api/v1/workflow/defaultactions/contenttype/${contentTypeName}`, + HttpMethod.GET + ) + .flush({ + entity: mockWorkflowActionsResponse + }); + }); + + it('should return empty array when workflow actions response is null', (done) => { + const contentTypeName = 'Blog'; + + spectator.service.getWorkFlowActions(contentTypeName).subscribe((res) => { + expect(res).toEqual([]); + done(); + }); + + spectator + .expectOne( + `/api/v1/workflow/defaultactions/contenttype/${contentTypeName}`, + HttpMethod.GET + ) + .flush({ + entity: null + }); + }); }); diff --git a/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.ts b/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.ts index 39f4fb88cf71..5bf7089bdcb0 100644 --- a/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.ts +++ b/core-web/libs/data-access/src/lib/dot-workflows-actions/dot-workflows-actions.service.ts @@ -13,6 +13,12 @@ export enum DotRenderMode { EDITING = 'EDITING' } +export interface DotCMSWorkflowActions { + scheme: DotCMSWorkflow; + action: DotCMSWorkflowAction; + firstStep: DotCMSWorkflowStep; +} + @Injectable() export class DotWorkflowsActionsService { private readonly BASE_URL = '/api/v1/workflow'; @@ -76,22 +82,16 @@ export class DotWorkflowsActionsService { return workflow && workflow.id; } - getWorkFlowActions(contentTypeName: string): Observable< - { - scheme: DotCMSWorkflow; - action: DotCMSWorkflowAction; - firstStep: DotCMSWorkflowStep; - }[] - > { + /** + * Returns the workflow actions of the passed content type name + * + * @param {string} contentTypeName + * @returns {Observable} + */ + getWorkFlowActions(contentTypeName: string): Observable { return this.httpClient .get< - DotCMSResponse< - { - scheme: DotCMSWorkflow; - action: DotCMSWorkflowAction; - firstStep: DotCMSWorkflowStep; - }[] - > + DotCMSResponse >(`${this.BASE_URL}/defaultactions/contenttype/${contentTypeName}`) .pipe( pluck('entity'),