mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2405] Added new service to get all process definition versions (#3023)
This commit is contained in:
committed by
Eugenio Romano
parent
caab70e021
commit
6aca2a2761
@@ -341,6 +341,65 @@ describe('ProcessService', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('process definition versions', () => {
|
||||
|
||||
let getProcessDefinitionVersions: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
getProcessDefinitionVersions = spyOn(alfrescoApi.activiti.processApi, 'getProcessDefinitions')
|
||||
.and
|
||||
.returnValue(Promise.resolve({ data: [ fakeProcessDef, fakeProcessDef ] }));
|
||||
});
|
||||
|
||||
it('should return the correct number of process defs', async(() => {
|
||||
service.getProcessDefinitionVersions().subscribe((defs) => {
|
||||
expect(defs.length).toBe(2);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return the correct process def data', async(() => {
|
||||
service.getProcessDefinitionVersions().subscribe((defs) => {
|
||||
expect(defs[0].id).toBe(fakeProcessDef.id);
|
||||
expect(defs[0].key).toBe(fakeProcessDef.key);
|
||||
expect(defs[0].name).toBe(fakeProcessDef.name);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call API with correct parameters when no appId provided', () => {
|
||||
service.getProcessDefinitionVersions();
|
||||
expect(getProcessDefinitionVersions).toHaveBeenCalledWith({});
|
||||
});
|
||||
|
||||
it('should call API with correct parameters when appId provided', () => {
|
||||
const appId = 1;
|
||||
service.getProcessDefinitionVersions(appId);
|
||||
expect(getProcessDefinitionVersions).toHaveBeenCalledWith({
|
||||
appDefinitionId: appId
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass on any error that is returned by the API', async(() => {
|
||||
getProcessDefinitionVersions = getProcessDefinitionVersions.and.returnValue(Promise.reject(mockError));
|
||||
service.getProcessDefinitionVersions().subscribe(
|
||||
() => {},
|
||||
(res) => {
|
||||
expect(res).toBe(mockError);
|
||||
}
|
||||
);
|
||||
}));
|
||||
|
||||
it('should return a default error if no data is returned by the API', async(() => {
|
||||
getProcessDefinitionVersions = getProcessDefinitionVersions.and.returnValue(Promise.reject(null));
|
||||
service.getProcessDefinitionVersions().subscribe(
|
||||
() => {},
|
||||
(res) => {
|
||||
expect(res).toBe('Server error');
|
||||
}
|
||||
);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('process instance tasks', () => {
|
||||
|
||||
const processId = '1001';
|
||||
|
@@ -101,6 +101,17 @@ export class ProcessService {
|
||||
.catch(err => this.handleProcessError(err));
|
||||
}
|
||||
|
||||
getProcessDefinitionVersions(appId?: number): Observable<ProcessDefinitionRepresentation[]> {
|
||||
const opts = appId ? { appDefinitionId: appId } : {};
|
||||
|
||||
return Observable.fromPromise(
|
||||
this.alfrescoApiService.getInstance().activiti.processApi.getProcessDefinitions(opts)
|
||||
)
|
||||
.map(this.extractData)
|
||||
.map(processDefs => processDefs.map((pd) => new ProcessDefinitionRepresentation(pd)))
|
||||
.catch(err => this.handleProcessError(err));
|
||||
}
|
||||
|
||||
startProcess(processDefinitionId: string, name: string, outcome?: string, startFormValues?: FormValues, variables?: ProcessInstanceVariable[]): Observable<ProcessInstance> {
|
||||
let startRequest: any = {
|
||||
name: name,
|
||||
|
Reference in New Issue
Block a user