Skip to content

Commit

Permalink
feat(edit-content) add test
Browse files Browse the repository at this point in the history
  • Loading branch information
oidacra committed Nov 14, 2024
1 parent 7e0593f commit 1f9d81b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<DotCMSWorkflowActions>}
*/
getWorkFlowActions(contentTypeName: string): Observable<DotCMSWorkflowActions[]> {
return this.httpClient
.get<
DotCMSResponse<
{
scheme: DotCMSWorkflow;
action: DotCMSWorkflowAction;
firstStep: DotCMSWorkflowStep;
}[]
>
DotCMSResponse<DotCMSWorkflowActions[]>
>(`${this.BASE_URL}/defaultactions/contenttype/${contentTypeName}`)
.pipe(
pluck('entity'),
Expand Down

0 comments on commit 1f9d81b

Please sign in to comment.