mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-46507 Next Task Endpoint (#11943)
This commit is contained in:
@@ -480,6 +480,63 @@ describe('Task Cloud Service', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('nextTask', () => {
|
||||
const appName = 'task-app';
|
||||
const nextTaskResponse = {
|
||||
entry: {
|
||||
appName: 'task-app',
|
||||
id: 'next-task-id',
|
||||
name: 'Next Task',
|
||||
status: 'CREATED',
|
||||
assignee: null
|
||||
}
|
||||
};
|
||||
|
||||
it('should return the next task details when called with a valid appName', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(nextTaskResponse));
|
||||
|
||||
service.nextTask(appName).subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toBe('next-task-id');
|
||||
expect(res.appName).toBe('task-app');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the API without strategy when strategy is not provided', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(nextTaskResponse));
|
||||
|
||||
service.nextTask(appName).subscribe(() => {
|
||||
const [url, options] = requestSpy.calls.mostRecent().args;
|
||||
expect(url).toContain('/rb/v1/tasks/next');
|
||||
expect(options?.queryParams?.strategy).toBeUndefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass strategy query param when strategy is provided', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(nextTaskResponse));
|
||||
|
||||
service.nextTask(appName, 'FIFO').subscribe(() => {
|
||||
const [url, options] = requestSpy.calls.mostRecent().args;
|
||||
expect(url).toContain('/rb/v1/tasks/next');
|
||||
expect(options?.queryParams?.strategy).toBe('FIFO');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit dataChangesDetected$ when next task is returned', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(nextTaskResponse));
|
||||
const dataChangeSpy = jasmine.createSpy('dataChangesDetected$');
|
||||
service.dataChangesDetected$.subscribe(dataChangeSpy);
|
||||
|
||||
service.nextTask(appName).subscribe(() => {
|
||||
expect(dataChangeSpy).toHaveBeenCalledWith(nextTaskResponse);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('wasTaskCompletedByCurrentUser', () => {
|
||||
it('should return true when task was completed by current user', () => {
|
||||
const completedTaskByCurrentUser = {
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { CardViewArrayItem, TranslationService } from '@alfresco/adf-core';
|
||||
import { throwError, Observable, of, Subject } from 'rxjs';
|
||||
import { Observable, of, Subject, throwError } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import {
|
||||
TaskDetailsCloudModel,
|
||||
StartTaskCloudResponseModel,
|
||||
TASK_ASSIGNED_STATE,
|
||||
TASK_CLAIM_PERMISSION,
|
||||
TASK_COMPLETED_STATE,
|
||||
TASK_CREATED_STATE,
|
||||
TASK_RELEASE_PERMISSION,
|
||||
TASK_COMPLETED_STATE
|
||||
TaskDetailsCloudModel
|
||||
} from '../models/task-details-cloud.model';
|
||||
import { BaseCloudService } from '../../services/base-cloud.service';
|
||||
import { StartTaskCloudRequestModel } from '../models/start-task-cloud-request.model';
|
||||
@@ -130,6 +130,26 @@ export class TaskCloudService extends BaseCloudService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next recommended task to process.
|
||||
*
|
||||
* @param appName Name of the app
|
||||
* @param strategy The task identification strategy
|
||||
* @returns Details of the returned task
|
||||
*/
|
||||
nextTask(appName: string, strategy?: string): Observable<TaskDetailsCloudModel> {
|
||||
if (!appName || appName === '') {
|
||||
return throwError(() => 'AppName not configured');
|
||||
}
|
||||
|
||||
return this.post(`${this.getBasePath(appName)}/rb/v1/tasks/next`, null, strategy ? { strategy } : null).pipe(
|
||||
map((res: any) => {
|
||||
this.dataChangesDetected$.next(res);
|
||||
return res.entry;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Claims a task for an assignee.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user