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 598634f59fc..5c9aa7363d4 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 39f4fb88cf7..5bf7089bdcb 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'),