[AAE-12501] Replace alfresco api client with AdfHttpClient

This commit is contained in:
Amedeo Lepore
2023-03-31 12:12:03 +02:00
parent d3be118680
commit 1aff2d0fce
27 changed files with 359 additions and 446 deletions
@@ -21,19 +21,22 @@ import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders, Htt
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, of, Subject, throwError } from 'rxjs'; import { Observable, of, Subject, throwError } from 'rxjs';
import { catchError, map, takeUntil } from 'rxjs/operators'; import { catchError, map, takeUntil } from 'rxjs/operators';
import { convertObjectToFormData, getQueryParamsWithCustomEncoder, isBlobResponse, isConstructor, isHttpResponseEvent, isHttpUploadProgressEvent, removeNilValues } from './alfresco-api.utils'; import { convertObjectToFormData, getQueryParamsWithCustomEncoder, isBlobResponse, isConstructor, isHttpResponseEvent, isHttpUploadProgressEvent, removeNilValues } from './alfresco-api/alfresco-api.utils';
import { AlfrescoApiParamEncoder } from './alfresco-api.param-encoder'; import { AlfrescoApiParamEncoder } from './alfresco-api/alfresco-api.param-encoder';
import { AlfrescoApiResponseError } from './alfresco-api.response-error'; import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
import { Constructor } from '../types'; import { Constructor } from './types';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AdfHttpClient implements JsApiHttpClient { export class AdfHttpClient implements JsApiHttpClient {
private readonly defaultSecurityOptions = { withCredentials: true, isBpmRequest: false, authentications: {}, defaultHeaders: {} };
constructor(private httpClient: HttpClient) {} constructor(private httpClient: HttpClient) {}
request<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
request<T = any>(url: string, options: RequestOptions, sc: SecurityOptions = this.defaultSecurityOptions, emitters?: JsApiEmitters): Promise<T> {
const body = AdfHttpClient.getBody(options); const body = AdfHttpClient.getBody(options);
const params = getQueryParamsWithCustomEncoder(options.queryParams, new AlfrescoApiParamEncoder()); const params = getQueryParamsWithCustomEncoder(options.queryParams, new AlfrescoApiParamEncoder());
const headers = AdfHttpClient.getHeaders(options); const headers = AdfHttpClient.getHeaders(options);
@@ -55,22 +58,25 @@ export class AdfHttpClient implements JsApiHttpClient {
} }
); );
if(emitters){
return this.requestWithLegacyEventEmitters<T>(request, emitters, options.returnType); return this.requestWithLegacyEventEmitters<T>(request, emitters, options.returnType);
} }
return request.toPromise<T>();
}
post<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> { post<T = any>(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise<T> {
return this.request<T>(url, { ...options, httpMethod: 'POST' }, sc, emitters); return this.request<T>(url, { ...options, httpMethod: 'POST' }, sc, emitters);
} }
put<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> { put<T = any>(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise<T> {
return this.request<T>(url, { ...options, httpMethod: 'PUT' }, sc, emitters); return this.request<T>(url, { ...options, httpMethod: 'PUT' }, sc, emitters);
} }
get<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> { get<T = any>(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise<T> {
return this.request<T>(url, { ...options, httpMethod: 'GET' }, sc, emitters); return this.request<T>(url, { ...options, httpMethod: 'GET' }, sc, emitters);
} }
delete<T = void>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> { delete<T = void>(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise<T> {
return this.request<T>(url, { ...options, httpMethod: 'DELETE' }, sc, emitters); return this.request<T>(url, { ...options, httpMethod: 'DELETE' }, sc, emitters);
} }
@@ -16,9 +16,8 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { Observable, from } from 'rxjs'; import { Observable, from } from 'rxjs';
import { AlfrescoApi } from '@alfresco/js-api'; import { AdfHttpClient } from '@alfresco/adf-core/api';
export const JSON_TYPE = ['application/json']; export const JSON_TYPE = ['application/json'];
@@ -32,25 +31,25 @@ export interface OAuth2RequestParams {
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class OAuth2Service { export class OAuth2Service {
constructor(private alfrescoApiService: AlfrescoApiService) {} constructor(private adfHttpClient: AdfHttpClient) {}
get apiClient(): AlfrescoApi {
return this.alfrescoApiService.getInstance();
}
request<T>(opts: OAuth2RequestParams): Observable<T> { request<T>(opts: OAuth2RequestParams): Observable<T> {
const { httpMethod, url, bodyParam, pathParams, queryParams } = opts;
return from( return from(
this.apiClient.callCustomApiWithoutAuth( this.adfHttpClient.request(
opts.url, url,
opts.httpMethod, {
opts.pathParams, path: url,
opts.queryParams, httpMethod,
{}, pathParams,
{}, queryParams,
opts.bodyParam, headerParams: {},
JSON_TYPE, formParams: {},
JSON_TYPE, bodyParam,
Object contentTypes: JSON_TYPE,
accepts: JSON_TYPE,
returnType: Object
}
) )
); );
} }
@@ -23,18 +23,15 @@ import { AppsProcessCloudService } from './apps-process-cloud.service';
import { fakeApplicationInstance } from '../mock/app-model.mock'; import { fakeApplicationInstance } from '../mock/app-model.mock';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('AppsProcessCloudService', () => { describe('AppsProcessCloudService', () => {
let service: AppsProcessCloudService; let service: AppsProcessCloudService;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
let apiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
const apiMock: any = { const apiMockResponse: any = Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }});
callCustomApiWithoutAuth: () => Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }}),
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
};
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -49,8 +46,8 @@ describe('AppsProcessCloudService', () => {
}); });
beforeEach(() => { beforeEach(() => {
apiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
spyOn(apiService, 'getInstance').and.returnValue(apiMock); spyOn(adfHttpClient, 'request').and.returnValue(apiMockResponse);
service = TestBed.inject(AppsProcessCloudService); service = TestBed.inject(AppsProcessCloudService);
appConfigService = TestBed.inject(AppConfigService); appConfigService = TestBed.inject(AppConfigService);
@@ -18,9 +18,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError, of } from 'rxjs'; import { Observable, from, throwError, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; import { map, catchError } from 'rxjs/operators';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { AlfrescoApi } from '@alfresco/js-api';
import { ApplicationInstanceModel } from '../models/application-instance.model'; import { ApplicationInstanceModel } from '../models/application-instance.model';
import { AdfHttpClient } from '@alfresco/adf-core/api';
import { RequestOptions } from '@alfresco/js-api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AppsProcessCloudService { export class AppsProcessCloudService {
@@ -28,7 +29,7 @@ export class AppsProcessCloudService {
deployedApps: ApplicationInstanceModel[]; deployedApps: ApplicationInstanceModel[];
constructor( constructor(
private apiService: AlfrescoApiService, private adfHttpClient: AdfHttpClient,
private logService: LogService, private logService: LogService,
private appConfigService: AppConfigService) { private appConfigService: AppConfigService) {
this.loadApps(); this.loadApps();
@@ -62,18 +63,28 @@ export class AppsProcessCloudService {
if (status === '') { if (status === '') {
return of([]); return of([]);
} }
const api: AlfrescoApi = this.apiService.getInstance();
const path = this.getApplicationUrl(); const path = this.getApplicationUrl();
const pathParams = {}; const pathParams = {};
const queryParams = { status, roles : role, sort: 'name' }; const queryParams = { status, roles : role, sort: 'name' };
const httpMethod = 'GET';
const headerParams = {}; const headerParams = {};
const formParams = {}; const formParams = {};
const bodyParam = {}; const bodyParam = {};
const contentTypes = ['application/json']; const contentTypes = ['application/json'];
const accepts = ['application/json']; const accepts = ['application/json'];
const requestOptions: RequestOptions = {
path,
pathParams,
queryParams,
headerParams,
formParams,
bodyParam,
contentTypes,
accepts,
httpMethod
};
return from(api.callCustomApiWithoutAuth(path, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, return from(this.adfHttpClient.request(path, requestOptions))
contentTypes, accepts))
.pipe( .pipe(
map((applications: any) => applications.list.entries.map((application) => application.entry)), map((applications: any) => applications.list.entries.map((application) => application.entry)),
catchError((err) => this.handleError(err)) catchError((err) => this.handleError(err))
@@ -17,24 +17,24 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { FormCloudService } from './form-cloud.service'; import { FormCloudService } from './form-cloud.service';
import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; const mockTaskResponseBody = {
const responseBody = {
entry: entry:
{ id: 'id', name: 'name', formKey: 'form-key' } { id: 'id', name: 'name', formKey: 'form-key' }
}; };
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi']); const mockFormResponseBody = { formRepresentation: { id: 'form-id', name: 'task-form', taskId: 'task-id' } };
describe('Form Cloud service', () => { describe('Form Cloud service', () => {
let service: FormCloudService; let service: FormCloudService;
let apiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let requestSpy: jasmine.Spy;
const appName = 'app-name'; const appName = 'app-name';
const taskId = 'task-id'; const taskId = 'task-id';
const processInstanceId = 'process-instance-id'; const processInstanceId = 'process-instance-id';
@@ -48,26 +48,21 @@ describe('Form Cloud service', () => {
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(FormCloudService); service = TestBed.inject(FormCloudService);
apiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
requestSpy = spyOn(adfHttpClient, 'request');
spyOn(apiService, 'getInstance').and.returnValue({
oauth2Auth,
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
} as any);
}); });
describe('Form tests', () => { describe('Form tests', () => {
it('should fetch and parse form', (done) => { it('should fetch and parse form', (done) => {
const formId = 'form-id'; const formId = 'form-id';
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ formRepresentation: { id: formId, name: 'task-form', taskId: 'task-id' } })); requestSpy.and.returnValue(Promise.resolve(mockFormResponseBody));
service.getForm(appName, formId).subscribe((result) => { service.getForm(appName, formId).subscribe((result) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.formRepresentation.id).toBe(formId); expect(result.formRepresentation.id).toBe(formId);
expect(result.formRepresentation.name).toBe('task-form'); expect(result.formRepresentation.name).toBe('task-form');
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/form/v1/forms/${formId}`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/form/v1/forms/${formId}`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
done(); done();
}); });
}); });
@@ -85,21 +80,21 @@ describe('Form Cloud service', () => {
describe('Task tests', () => { describe('Task tests', () => {
it('should fetch and parse task', (done) => { it('should fetch and parse task', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); requestSpy.and.returnValue(Promise.resolve(mockTaskResponseBody));
service.getTask(appName, taskId).subscribe((result) => { service.getTask(appName, taskId).subscribe((result) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.id).toBe(responseBody.entry.id); expect(result.id).toBe('id');
expect(result.name).toBe(responseBody.entry.name); expect(result.name).toBe('name');
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/query/v1/tasks/${taskId}`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/query/v1/tasks/${taskId}`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
done(); done();
}); });
}); });
it('should fetch task variables', (done) => { it('should fetch task variables', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ requestSpy.and.returnValue(Promise.resolve({
list: { list: {
entries: [ entries: [
{ {
@@ -139,14 +134,14 @@ describe('Form Cloud service', () => {
expect(result.length).toBe(1); expect(result.length).toBe(1);
expect(result[0].name).toBe('fakeProperty'); expect(result[0].name).toBe('fakeProperty');
expect(result[0].value).toBe('fakeValue'); expect(result[0].value).toBe('fakeValue');
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/query/v1/tasks/${taskId}/variables`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/query/v1/tasks/${taskId}/variables`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
done(); done();
}); });
}); });
it('should fetch result if the variable value is 0', (done) => { it('should fetch result if the variable value is 0', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ requestSpy.and.returnValue(Promise.resolve({
list: { list: {
entries: [ entries: [
{ {
@@ -191,7 +186,7 @@ describe('Form Cloud service', () => {
}); });
it('should fetch task form flattened', (done) => { it('should fetch task form flattened', (done) => {
spyOn(service, 'getTask').and.returnValue(of(responseBody.entry)); spyOn(service, 'getTask').and.returnValue(of(mockTaskResponseBody.entry));
spyOn(service, 'getForm').and.returnValue(of({ spyOn(service, 'getForm').and.returnValue(of({
formRepresentation: { formRepresentation: {
name: 'task-form', name: 'task-form',
@@ -202,38 +197,38 @@ describe('Form Cloud service', () => {
service.getTaskForm(appName, taskId).subscribe((result) => { service.getTaskForm(appName, taskId).subscribe((result) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.name).toBe('task-form'); expect(result.name).toBe('task-form');
expect(result.taskId).toBe(responseBody.entry.id); expect(result.taskId).toBe('id');
expect(result.taskName).toBe(responseBody.entry.name); expect(result.taskName).toBe('name');
done(); done();
}); });
}); });
it('should save task form', (done) => { it('should save task form', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); requestSpy.and.returnValue(Promise.resolve(mockTaskResponseBody));
const formId = 'form-id'; const formId = 'form-id';
service.saveTaskForm(appName, taskId, processInstanceId, formId, {}).subscribe((result: any) => { service.saveTaskForm(appName, taskId, processInstanceId, formId, {}).subscribe((result: any) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.id).toBe('id'); expect(result.id).toBe('id');
expect(result.name).toBe('name'); expect(result.name).toBe('name');
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/form/v1/forms/${formId}/save`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/form/v1/forms/${formId}/save`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('POST'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('POST');
done(); done();
}); });
}); });
it('should complete task form', (done) => { it('should complete task form', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); requestSpy.and.returnValue(Promise.resolve(mockTaskResponseBody));
const formId = 'form-id'; const formId = 'form-id';
service.completeTaskForm(appName, taskId, processInstanceId, formId, {}, '', 1).subscribe((result: any) => { service.completeTaskForm(appName, taskId, processInstanceId, formId, {}, '', 1).subscribe((result: any) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.id).toBe('id'); expect(result.id).toBe('id');
expect(result.name).toBe('name'); expect(result.name).toBe('name');
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/form/v1/forms/${formId}/submit/versions/1`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/form/v1/forms/${formId}/submit/versions/1`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('POST'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('POST');
done(); done();
}); });
}); });
@@ -31,6 +31,7 @@ import { TaskVariableCloud } from '../models/task-variable-cloud.model';
import { BaseCloudService } from '../../services/base-cloud.service'; import { BaseCloudService } from '../../services/base-cloud.service';
import { FormContent } from '../../services/form-fields.interfaces'; import { FormContent } from '../../services/form-fields.interfaces';
import { FormCloudServiceInterface } from './form-cloud.service.interface'; import { FormCloudServiceInterface } from './form-cloud.service.interface';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -44,10 +45,11 @@ export class FormCloudService extends BaseCloudService implements FormCloudServi
} }
constructor( constructor(
apiService: AlfrescoApiService, private apiService: AlfrescoApiService,
adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService appConfigService: AppConfigService
) { ) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -16,20 +16,17 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { FormDefinitionSelectorCloudService } from './form-definition-selector-cloud.service'; import { FormDefinitionSelectorCloudService } from './form-definition-selector-cloud.service';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { mockFormRepresentations } from '../mocks/form-representation.mock'; import { mockFormRepresentations } from '../mocks/form-representation.mock';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any;
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi', 'on']);
describe('Form Definition Selector Cloud Service', () => { describe('Form Definition Selector Cloud Service', () => {
let service: FormDefinitionSelectorCloudService; let service: FormDefinitionSelectorCloudService;
let apiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
const appName = 'app-name'; const appName = 'app-name';
setupTestBed({ setupTestBed({
@@ -41,17 +38,11 @@ describe('Form Definition Selector Cloud Service', () => {
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(FormDefinitionSelectorCloudService); service = TestBed.inject(FormDefinitionSelectorCloudService);
apiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
spyOn(apiService, 'getInstance').and.returnValue({ spyOn(adfHttpClient, 'request').and.returnValue(Promise.resolve(mockFormRepresentations));
oauth2Auth,
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
} as any);
}); });
it('should fetch all the forms when getForms is called', (done) => { it('should fetch all the forms when getForms is called', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(mockFormRepresentations));
service.getForms(appName).subscribe((result) => { service.getForms(appName).subscribe((result) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.length).toBe(3); expect(result.length).toBe(3);
@@ -60,8 +51,6 @@ describe('Form Definition Selector Cloud Service', () => {
}); });
it('should fetch only standalone enabled forms when getStandaloneTaskForms is called', (done) => { it('should fetch only standalone enabled forms when getStandaloneTaskForms is called', (done) => {
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(mockFormRepresentations));
service.getStandAloneTaskForms(appName).subscribe((result) => { service.getStandAloneTaskForms(appName).subscribe((result) => {
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.length).toBe(2); expect(result.length).toBe(2);
@@ -16,21 +16,22 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { from, Observable } from 'rxjs'; import { from, Observable } from 'rxjs';
import { BaseCloudService } from '../../services/base-cloud.service'; import { BaseCloudService } from '../../services/base-cloud.service';
import { FormRepresentation } from '../../services/form-fields.interfaces'; import { FormRepresentation } from '../../services/form-fields.interfaces';
import { FormDefinitionSelectorCloudServiceInterface } from './form-definition-selector-cloud.service.interface'; import { FormDefinitionSelectorCloudServiceInterface } from './form-definition-selector-cloud.service.interface';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class FormDefinitionSelectorCloudService extends BaseCloudService implements FormDefinitionSelectorCloudServiceInterface { export class FormDefinitionSelectorCloudService extends BaseCloudService implements FormDefinitionSelectorCloudServiceInterface {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService) { appConfigService: AppConfigService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -16,42 +16,24 @@
*/ */
import { fakeAsync, TestBed } from '@angular/core/testing'; import { fakeAsync, TestBed } from '@angular/core/testing';
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { ProcessListCloudService } from './process-list-cloud.service'; import { ProcessListCloudService } from './process-list-cloud.service';
import { ProcessQueryCloudRequestModel } from '../models/process-cloud-query-request.model'; import { ProcessQueryCloudRequestModel } from '../models/process-cloud-query-request.model';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('ProcessListCloudService', () => { describe('ProcessListCloudService', () => {
let service: ProcessListCloudService; let service: ProcessListCloudService;
let alfrescoApiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let requestSpy: jasmine.Spy;
const returnCallQueryParameters = (): any => ({ const returnCallQueryParameters = (_queryUrl, options) => Promise.resolve(options.queryParams);
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, queryParams) => Promise.resolve(queryParams)
},
isEcmLoggedIn: () => false
});
const returnCallUrl = (): any => ({ const returnCallUrl = (queryUrl) => Promise.resolve(queryUrl);
oauth2Auth: {
callCustomApi: (queryUrl) => Promise.resolve(queryUrl)
},
isEcmLoggedIn: () => false
});
const returnCallOperation = (): any => ({ const returnCallOperation = (_queryUrl, options) => Promise.resolve(options);
oauth2Auth: {
callCustomApi: (_queryUrl, operation, _context, _queryParams) => Promise.resolve(operation)
},
isEcmLoggedIn: () => false
});
const returnCallBody = (): any => ({ const returnCallBody = (_queryUrl, options) => Promise.resolve(options.bodyParam);
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, _queryParams, _headerParams, _formParams, bodyParam) => Promise.resolve(bodyParam)
},
isEcmLoggedIn: () => false
});
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -60,13 +42,14 @@ describe('ProcessListCloudService', () => {
}); });
beforeEach(fakeAsync(() => { beforeEach(fakeAsync(() => {
alfrescoApiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
service = TestBed.inject(ProcessListCloudService); service = TestBed.inject(ProcessListCloudService);
requestSpy = spyOn(adfHttpClient, 'request');
})); }));
it('should append to the call all the parameters', (done) => { it('should append to the call all the parameters', (done) => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getProcessByRequest(processRequest).subscribe((res) => { service.getProcessByRequest(processRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -79,7 +62,7 @@ describe('ProcessListCloudService', () => {
it('should concat the app name to the request url', (done) => { it('should concat the app name to the request url', (done) => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getProcessByRequest(processRequest).subscribe((requestUrl) => { service.getProcessByRequest(processRequest).subscribe((requestUrl) => {
expect(requestUrl).toBeDefined(); expect(requestUrl).toBeDefined();
expect(requestUrl).not.toBeNull(); expect(requestUrl).not.toBeNull();
@@ -93,7 +76,7 @@ describe('ProcessListCloudService', () => {
appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service',
sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }] sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }]
} as ProcessQueryCloudRequestModel; } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getProcessByRequest(processRequest).subscribe((res) => { service.getProcessByRequest(processRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -104,7 +87,7 @@ describe('ProcessListCloudService', () => {
it('should return an error when app name is not specified', (done) => { it('should return an error when app name is not specified', (done) => {
const processRequest = { appName: null } as ProcessQueryCloudRequestModel; const processRequest = { appName: null } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getProcessByRequest(processRequest).subscribe( service.getProcessByRequest(processRequest).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -118,7 +101,7 @@ describe('ProcessListCloudService', () => {
it('should append to the call all the parameters', async () => { it('should append to the call all the parameters', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const request = await service.getAdminProcessByRequest(processRequest).toPromise(); const request = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(request).toBeDefined(); expect(request).toBeDefined();
@@ -130,7 +113,7 @@ describe('ProcessListCloudService', () => {
it('should concat the app name to the request url', async () => { it('should concat the app name to the request url', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
const requestUrl = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestUrl = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(requestUrl).toBeDefined(); expect(requestUrl).toBeDefined();
@@ -143,7 +126,7 @@ describe('ProcessListCloudService', () => {
appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service',
sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }] sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }]
} as ProcessQueryCloudRequestModel; } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const request = await service.getAdminProcessByRequest(processRequest).toPromise(); const request = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(request).toBeDefined(); expect(request).toBeDefined();
@@ -153,7 +136,7 @@ describe('ProcessListCloudService', () => {
it('should return an error when app name is not specified', async () => { it('should return an error when app name is not specified', async () => {
const processRequest = { appName: null } as ProcessQueryCloudRequestModel; const processRequest = { appName: null } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
try { try {
await service.getAdminProcessByRequest(processRequest).toPromise(); await service.getAdminProcessByRequest(processRequest).toPromise();
@@ -166,16 +149,16 @@ describe('ProcessListCloudService', () => {
it('should make post request', async () => { it('should make post request', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallOperation); requestSpy.and.callFake(returnCallOperation);
const requestMethod = await service.getAdminProcessByRequest(processRequest).toPromise(); const adminProcessResponse = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(requestMethod).toBeDefined(); expect(adminProcessResponse).toBeDefined();
expect(requestMethod).not.toBeNull(); expect(adminProcessResponse).not.toBeNull();
expect(requestMethod).toBe('POST'); expect(adminProcessResponse.httpMethod).toBe('POST');
}); });
it('should not have variable keys as part of query parameters', async () => { it('should not have variable keys as part of query parameters', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const requestParams = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestParams = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(requestParams).toBeDefined(); expect(requestParams).toBeDefined();
@@ -185,7 +168,7 @@ describe('ProcessListCloudService', () => {
it('should send right variable keys as post body', async () => { it('should send right variable keys as post body', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallBody); requestSpy.and.callFake(returnCallBody);
const requestBodyParams = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestBodyParams = await service.getAdminProcessByRequest(processRequest).toPromise();
expect(requestBodyParams).toBeDefined(); expect(requestBodyParams).toBeDefined();
@@ -16,20 +16,21 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { ProcessQueryCloudRequestModel } from '../models/process-cloud-query-request.model'; import { ProcessQueryCloudRequestModel } from '../models/process-cloud-query-request.model';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { ProcessListCloudSortingModel } from '../models/process-list-sorting.model'; import { ProcessListCloudSortingModel } from '../models/process-list-sorting.model';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ProcessListCloudService extends BaseCloudService { export class ProcessListCloudService extends BaseCloudService {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private logService: LogService) { private logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
private getProcess( private getProcess(
@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@@ -24,14 +24,15 @@ import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud
import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { TaskCloudNodePaging } from '../../../models/task-cloud.model'; import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ProcessTaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface { export class ProcessTaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
protected logService: LogService) { protected logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, LogService, AppConfigService } from '@alfresco/adf-core'; import { LogService, AppConfigService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, Subject, throwError } from 'rxjs'; import { Observable, Subject, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { catchError, map } from 'rxjs/operators';
@@ -24,6 +24,7 @@ import { BaseCloudService } from '../../services/base-cloud.service';
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model'; import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
import { ApplicationVersionModel, ApplicationVersionResponseModel } from '../../models/application-version.model'; import { ApplicationVersionModel, ApplicationVersionResponseModel } from '../../models/application-version.model';
import { ProcessCloudInterface } from './process-cloud.interface'; import { ProcessCloudInterface } from './process-cloud.interface';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -32,10 +33,10 @@ export class ProcessCloudService extends BaseCloudService implements ProcessClou
dataChangesDetected = new Subject<ProcessInstanceCloud>(); dataChangesDetected = new Subject<ProcessInstanceCloud>();
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private logService: LogService) { private logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -17,16 +17,17 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs'; import { of, throwError } from 'rxjs';
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { StartProcessCloudService } from './start-process-cloud.service'; import { StartProcessCloudService } from './start-process-cloud.service';
import { fakeProcessPayload } from '../mock/start-process.component.mock'; import { fakeProcessPayload } from '../mock/start-process.component.mock';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { HttpErrorResponse, HttpClientModule } from '@angular/common/http'; import { HttpErrorResponse, HttpClientModule } from '@angular/common/http';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('StartProcessCloudService', () => { describe('StartProcessCloudService', () => {
let service: StartProcessCloudService; let service: StartProcessCloudService;
let alfrescoApiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
setupTestBed({ setupTestBed({
imports: [HttpClientModule] imports: [HttpClientModule]
@@ -34,7 +35,7 @@ describe('StartProcessCloudService', () => {
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(StartProcessCloudService); service = TestBed.inject(StartProcessCloudService);
alfrescoApiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
}); });
it('should be able to create a new process', (done) => { it('should be able to create a new process', (done) => {
@@ -105,11 +106,8 @@ describe('StartProcessCloudService', () => {
it('should transform the response into task variables', (done) => { it('should transform the response into task variables', (done) => {
const appName = 'test-app'; const appName = 'test-app';
const processDefinitionId = 'processDefinitionId'; const processDefinitionId = 'processDefinitionId';
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi']); const requestSpy = spyOn(adfHttpClient, 'request');
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true })); requestSpy.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
spyOn(alfrescoApiService, 'getInstance').and.returnValue({
oauth2Auth
} as any);
service.getStartEventFormStaticValuesMapping(appName, processDefinitionId).subscribe((result) => { service.getStartEventFormStaticValuesMapping(appName, processDefinitionId).subscribe((result) => {
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
@@ -122,8 +120,8 @@ describe('StartProcessCloudService', () => {
expect(result[2].name).toEqual('static3'); expect(result[2].name).toEqual('static3');
expect(result[2].id).toEqual('static3'); expect(result[2].id).toEqual('static3');
expect(result[2].value).toEqual(true); expect(result[2].value).toEqual(true);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`)).toBeTruthy(); expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
done(); done();
}); });
}); });
@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@@ -24,16 +24,17 @@ import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model'; import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class StartProcessCloudService extends BaseCloudService { export class StartProcessCloudService extends BaseCloudService {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
private logService: LogService, private logService: LogService,
appConfigService: AppConfigService) { appConfigService: AppConfigService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -15,27 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { AdfHttpClient } from '@alfresco/adf-core/api';
import { RequestOptions } from '@alfresco/js-api';
import { from, Observable } from 'rxjs'; import { from, Observable } from 'rxjs';
export interface CallApiParams {
path: string;
httpMethod: string;
pathParams?: any;
queryParams?: any;
headerParams?: any;
formParams?: any;
bodyParam?: any;
contentTypes?: string[];
accepts?: string[];
returnType?: any;
contextRoot?: string;
responseType?: string;
}
export class BaseCloudService { export class BaseCloudService {
protected defaultParams: CallApiParams = { protected defaultParams: RequestOptions = {
path: '', path: '',
httpMethod: '', httpMethod: '',
contentTypes: ['application/json'], contentTypes: ['application/json'],
@@ -43,7 +30,7 @@ export class BaseCloudService {
}; };
constructor( constructor(
protected apiService: AlfrescoApiService, protected adfHttpClient: AdfHttpClient,
protected appConfigService: AppConfigService) {} protected appConfigService: AppConfigService) {}
getBasePath(appName: string): string { getBasePath(appName: string): string {
@@ -54,63 +41,64 @@ export class BaseCloudService {
protected post<T, R>(url: string, data?: T, queryParams?: any): Observable<R> { protected post<T, R>(url: string, data?: T, queryParams?: any): Observable<R> {
return from( return from(
this.callApi<R>({ this.callApi<R>(
url,
{
...this.defaultParams, ...this.defaultParams,
path: url, path: url,
httpMethod: 'POST', httpMethod: 'POST',
bodyParam: data, bodyParam: data,
queryParams queryParams
}) }
)
); );
} }
protected put<T, R>(url: string, data?: T): Observable<R> { protected put<T, R>(url: string, data?: T): Observable<R> {
return from( return from(
this.callApi<R>({ this.callApi<R>(
url,
{
...this.defaultParams, ...this.defaultParams,
path: url, path: url,
httpMethod: 'PUT', httpMethod: 'PUT',
bodyParam: data bodyParam: data
}) }
)
); );
} }
protected delete(url: string): Observable<void> { protected delete(url: string): Observable<void> {
return from( return from(
this.callApi<void>({ this.callApi<void>(
url,
{
...this.defaultParams, ...this.defaultParams,
path: url, path: url,
httpMethod: 'DELETE' httpMethod: 'DELETE'
}) }
)
); );
} }
protected get<T>(url: string, queryParams?: any): Observable<T> { protected get<T>(url: string, queryParams?: any): Observable<T> {
return from( return from(
this.callApi<T>({ this.callApi<T>(
url,
{
...this.defaultParams, ...this.defaultParams,
path: url, path: url,
httpMethod: 'GET', httpMethod: 'GET',
queryParams queryParams
}) }
)
); );
} }
protected callApi<T>(params: CallApiParams): Promise<T> { protected callApi<T>(url: string, params: RequestOptions): Promise<T> {
return this.apiService.getInstance() return this.adfHttpClient.request(
.oauth2Auth.callCustomApi( url,
params.path, params
params.httpMethod,
params.pathParams,
params.queryParams,
params.headerParams,
params.formParams,
params.bodyParam,
params.contentTypes,
params.accepts,
params.returnType,
params.contextRoot,
params.responseType
); );
} }
@@ -16,7 +16,7 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { NotificationCloudService } from './notification-cloud.service'; import { NotificationCloudService } from './notification-cloud.service';
@@ -27,7 +27,7 @@ describe('NotificationCloudService', () => {
let apollo: Apollo; let apollo: Apollo;
let apolloCreateSpy: jasmine.Spy; let apolloCreateSpy: jasmine.Spy;
let apolloSubscribeSpy: jasmine.Spy; let apolloSubscribeSpy: jasmine.Spy;
let apiService: AlfrescoApiService;
const useMock: any = { const useMock: any = {
subscribe: () => {} subscribe: () => {}
}; };
@@ -43,14 +43,6 @@ describe('NotificationCloudService', () => {
} }
`; `;
const apiServiceMock: any = {
oauth2Auth: {
token: '1234567'
},
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
};
setupTestBed({ setupTestBed({
imports: [ imports: [
TranslateModule.forRoot(), TranslateModule.forRoot(),
@@ -61,9 +53,7 @@ describe('NotificationCloudService', () => {
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(NotificationCloudService); service = TestBed.inject(NotificationCloudService);
apollo = TestBed.inject(Apollo); apollo = TestBed.inject(Apollo);
apiService = TestBed.inject(AlfrescoApiService);
spyOn(apiService, 'getInstance').and.returnValue(apiServiceMock);
service.appsListening = []; service.appsListening = [];
apolloCreateSpy = spyOn(apollo, 'createNamed'); apolloCreateSpy = spyOn(apollo, 'createNamed');
apolloSubscribeSpy = spyOn(apollo, 'use').and.returnValue(useMock); apolloSubscribeSpy = spyOn(apollo, 'use').and.returnValue(useMock);
@@ -22,8 +22,9 @@ import { WebSocketLink } from '@apollo/client/link/ws';
import { onError } from '@apollo/client/link/error'; import { onError } from '@apollo/client/link/error';
import { getMainDefinition } from '@apollo/client/utilities'; import { getMainDefinition } from '@apollo/client/utilities';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AppConfigService, AlfrescoApiService, AuthenticationService } from '@alfresco/adf-core'; import { AppConfigService, AuthenticationService } from '@alfresco/adf-core';
import { BaseCloudService } from './base-cloud.service'; import { BaseCloudService } from './base-cloud.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -32,12 +33,12 @@ export class NotificationCloudService extends BaseCloudService {
appsListening = []; appsListening = [];
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
public apollo: Apollo, public apollo: Apollo,
private http: HttpLink, private http: HttpLink,
private authService: AuthenticationService) { private authService: AuthenticationService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
private get webSocketHost() { private get webSocketHost() {
@@ -17,36 +17,22 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { UserPreferenceCloudService } from './user-preference-cloud.service'; import { UserPreferenceCloudService } from './user-preference-cloud.service';
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { mockPreferences, getMockPreference, createMockPreference, updateMockPreference } from '../mock/user-preference.mock'; import { mockPreferences, getMockPreference, createMockPreference, updateMockPreference } from '../mock/user-preference.mock';
import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('PreferenceService', () => { describe('PreferenceService', () => {
let service: UserPreferenceCloudService; let service: UserPreferenceCloudService;
let alfrescoApiMock: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let getInstanceSpy: jasmine.Spy; let requestSpy: jasmine.Spy;
const errorResponse = { const errorResponse = {
error: 'Mock Error', error: 'Mock Error',
state: 404, stateText: 'Not Found' state: 404, stateText: 'Not Found'
}; };
const apiMock = (mockResponse): any => ({
oauth2Auth: {
callCustomApi: () => Promise.resolve(mockResponse)
},
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
});
const apiErrorMock: any = {
oauth2Auth: {
callCustomApi: () => Promise.reject(errorResponse)
},
isEcmLoggedIn:() => false
};
setupTestBed({ setupTestBed({
imports: [ imports: [
TranslateModule.forRoot(), TranslateModule.forRoot(),
@@ -56,8 +42,8 @@ describe('PreferenceService', () => {
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(UserPreferenceCloudService); service = TestBed.inject(UserPreferenceCloudService);
alfrescoApiMock = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
getInstanceSpy = spyOn(alfrescoApiMock, 'getInstance').and.returnValue(apiMock(mockPreferences)); requestSpy = spyOn(adfHttpClient, 'request').and.returnValue(Promise.resolve(mockPreferences));
}); });
it('should return the preferences', (done) => { it('should return the preferences', (done) => {
@@ -81,7 +67,7 @@ describe('PreferenceService', () => {
}); });
it('Should not fetch preferences if error occurred', (done) => { it('Should not fetch preferences if error occurred', (done) => {
getInstanceSpy.and.returnValue(apiErrorMock); requestSpy.and.returnValue(Promise.reject(errorResponse));
service.getPreferences('mock-app-name') service.getPreferences('mock-app-name')
.subscribe( .subscribe(
() => fail('expected an error, not preferences'), () => fail('expected an error, not preferences'),
@@ -95,7 +81,7 @@ describe('PreferenceService', () => {
}); });
it('should return the preference by key', (done) => { it('should return the preference by key', (done) => {
getInstanceSpy.and.returnValue(apiMock(getMockPreference)); requestSpy.and.returnValue(Promise.resolve(getMockPreference));
service.getPreferenceByKey('mock-app-name', 'mock-preference-key').subscribe((res: any) => { service.getPreferenceByKey('mock-app-name', 'mock-preference-key').subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -109,7 +95,7 @@ describe('PreferenceService', () => {
}); });
it('Should not fetch preference by key if error occurred', (done) => { it('Should not fetch preference by key if error occurred', (done) => {
getInstanceSpy.and.returnValue(apiErrorMock); requestSpy.and.returnValue(Promise.reject(errorResponse));
service.getPreferenceByKey('mock-app-name', 'mock-preference-key') service.getPreferenceByKey('mock-app-name', 'mock-preference-key')
.subscribe( .subscribe(
() => fail('expected an error, not preference'), () => fail('expected an error, not preference'),
@@ -123,7 +109,7 @@ describe('PreferenceService', () => {
}); });
it('should create preference', (done) => { it('should create preference', (done) => {
getInstanceSpy.and.returnValue(apiMock(createMockPreference)); requestSpy.and.returnValue(Promise.resolve(createMockPreference));
service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference).subscribe((res: any) => { service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -135,7 +121,7 @@ describe('PreferenceService', () => {
}); });
it('Should not create preference if error occurred', (done) => { it('Should not create preference if error occurred', (done) => {
getInstanceSpy.and.returnValue(apiErrorMock); requestSpy.and.returnValue(Promise.reject(errorResponse));
service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference) service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference)
.subscribe( .subscribe(
() => fail('expected an error, not to create preference'), () => fail('expected an error, not to create preference'),
@@ -149,7 +135,7 @@ describe('PreferenceService', () => {
}); });
it('should update preference', (done) => { it('should update preference', (done) => {
getInstanceSpy.and.returnValue(apiMock(updateMockPreference)); requestSpy.and.returnValue(Promise.resolve(updateMockPreference));
service.updatePreference('mock-app-name', 'mock-preference-key', updateMockPreference).subscribe((res: any) => { service.updatePreference('mock-app-name', 'mock-preference-key', updateMockPreference).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -161,7 +147,7 @@ describe('PreferenceService', () => {
}); });
it('Should not update preference if error occurred', (done) => { it('Should not update preference if error occurred', (done) => {
getInstanceSpy.and.returnValue(apiErrorMock); requestSpy.and.returnValue(Promise.reject(errorResponse));
service.createPreference('mock-app-name', 'mock-preference-key', updateMockPreference) service.createPreference('mock-app-name', 'mock-preference-key', updateMockPreference)
.subscribe( .subscribe(
() => fail('expected an error, not to update preference'), () => fail('expected an error, not to update preference'),
@@ -175,7 +161,7 @@ describe('PreferenceService', () => {
}); });
it('should delete preference', (done) => { it('should delete preference', (done) => {
getInstanceSpy.and.returnValue(apiMock('')); requestSpy.and.returnValue(Promise.resolve(''));
service.deletePreference('mock-app-name', 'mock-preference-key').subscribe((res: any) => { service.deletePreference('mock-app-name', 'mock-preference-key').subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
done(); done();
@@ -183,7 +169,7 @@ describe('PreferenceService', () => {
}); });
it('Should not delete preference if error occurred', (done) => { it('Should not delete preference if error occurred', (done) => {
getInstanceSpy.and.returnValue(apiErrorMock); requestSpy.and.returnValue(Promise.reject(errorResponse));
service.deletePreference('mock-app-name', 'mock-preference-key') service.deletePreference('mock-app-name', 'mock-preference-key')
.subscribe( .subscribe(
() => fail('expected an error, not to delete preference'), () => fail('expected an error, not to delete preference'),
@@ -17,18 +17,19 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { PreferenceCloudServiceInterface } from './preference-cloud.interface'; import { PreferenceCloudServiceInterface } from './preference-cloud.interface';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { throwError, Observable } from 'rxjs'; import { throwError, Observable } from 'rxjs';
import { BaseCloudService } from './base-cloud.service'; import { BaseCloudService } from './base-cloud.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class UserPreferenceCloudService extends BaseCloudService implements PreferenceCloudServiceInterface { export class UserPreferenceCloudService extends BaseCloudService implements PreferenceCloudServiceInterface {
constructor( constructor(
apiService: AlfrescoApiService, adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private logService: LogService) { private logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -16,20 +16,21 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model'; import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model';
import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../start-task/models/task-details-cloud.model'; import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../start-task/models/task-details-cloud.model';
import { BaseCloudService } from '../../services/base-cloud.service'; import { BaseCloudService } from '../../services/base-cloud.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class StartTaskCloudService extends BaseCloudService { export class StartTaskCloudService extends BaseCloudService {
constructor( constructor(
apiService: AlfrescoApiService, adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService) { appConfigService: AppConfigService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -16,7 +16,7 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { setupTestBed, TranslationService, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed, TranslationService } from '@alfresco/adf-core';
import { TaskCloudService } from './task-cloud.service'; import { TaskCloudService } from './task-cloud.service';
import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock'; import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock';
import { assignedTaskDetailsCloudMock, createdTaskDetailsCloudMock, emptyOwnerTaskDetailsCloudMock } from '../task-header/mocks/task-details-cloud.mock'; import { assignedTaskDetailsCloudMock, createdTaskDetailsCloudMock, emptyOwnerTaskDetailsCloudMock } from '../task-header/mocks/task-details-cloud.mock';
@@ -25,53 +25,25 @@ import { cloudMockUser } from '../start-task/mock/user-cloud.mock';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { IdentityUserService } from '../../people/services/identity-user.service'; import { IdentityUserService } from '../../people/services/identity-user.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('Task Cloud Service', () => { describe('Task Cloud Service', () => {
let service: TaskCloudService; let service: TaskCloudService;
let alfrescoApiMock: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let identityUserService: IdentityUserService; let identityUserService: IdentityUserService;
let translateService: TranslationService; let translateService: TranslationService;
let requestSpy: jasmine.Spy;
const returnFakeTaskCompleteResults = (): any => ({ const returnFakeTaskCompleteResults = () => Promise.resolve(taskCompleteCloudMock);
reply: () => {},
oauth2Auth: {
callCustomApi : () => Promise.resolve(taskCompleteCloudMock)
},
isEcmLoggedIn: () => false
});
const returnFakeTaskCompleteResultsError = (): any => ({ const returnFakeTaskCompleteResultsError = () => Promise.reject(taskCompleteCloudMock);
reply: () => {},
oauth2Auth: {
callCustomApi : () => Promise.reject(taskCompleteCloudMock)
},
isEcmLoggedIn: () => false
});
const returnFakeTaskDetailsResults = (): any => ({ const returnFakeTaskDetailsResults = () => Promise.resolve(fakeTaskDetailsCloud);
reply: () => {},
oauth2Auth: {
callCustomApi : () => Promise.resolve(fakeTaskDetailsCloud)
},
isEcmLoggedIn: () => false
});
const returnFakeCandidateUsersResults = (): any => ({ const returnFakeCandidateUsersResults = () => Promise.resolve(['mockuser1', 'mockuser2', 'mockuser3']);
reply: () => {},
oauth2Auth: {
callCustomApi : () => Promise.resolve(['mockuser1', 'mockuser2', 'mockuser3'])
},
isEcmLoggedIn: () => false
});
const returnFakeCandidateGroupResults = (): any => ({ const returnFakeCandidateGroupResults = () => Promise.resolve(['mockgroup1', 'mockgroup2', 'mockgroup3']);
reply: () => {},
oauth2Auth: {
callCustomApi : () => Promise.resolve(['mockgroup1', 'mockgroup2', 'mockgroup3'])
},
isEcmLoggedIn: () => false
});
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -81,18 +53,19 @@ describe('Task Cloud Service', () => {
}); });
beforeEach(() => { beforeEach(() => {
alfrescoApiMock = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
identityUserService = TestBed.inject(IdentityUserService); identityUserService = TestBed.inject(IdentityUserService);
translateService = TestBed.inject(TranslationService); translateService = TestBed.inject(TranslationService);
service = TestBed.inject(TaskCloudService); service = TestBed.inject(TaskCloudService);
spyOn(translateService, 'instant').and.callFake((key) => key ? `${key}_translated` : null); spyOn(translateService, 'instant').and.callFake((key) => key ? `${key}_translated` : null);
spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(cloudMockUser); spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(cloudMockUser);
requestSpy = spyOn(adfHttpClient, 'request');
}); });
it('should complete a task', (done) => { it('should complete a task', (done) => {
const appName = 'simple-app'; const appName = 'simple-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskCompleteResults); requestSpy.and.callFake(returnFakeTaskCompleteResults);
service.completeTask(appName, taskId).subscribe((res: any) => { service.completeTask(appName, taskId).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -103,7 +76,7 @@ describe('Task Cloud Service', () => {
}); });
it('should not complete a task', (done) => { it('should not complete a task', (done) => {
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskCompleteResultsError); requestSpy.and.callFake(returnFakeTaskCompleteResultsError);
const appName = 'simple-app'; const appName = 'simple-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
@@ -140,7 +113,7 @@ describe('Task Cloud Service', () => {
const appName = 'simple-app'; const appName = 'simple-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
const canCompleteTaskResult = service.canCompleteTask(emptyOwnerTaskDetailsCloudMock); const canCompleteTaskResult = service.canCompleteTask(emptyOwnerTaskDetailsCloudMock);
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskCompleteResults); requestSpy.and.callFake(returnFakeTaskCompleteResults);
service.completeTask(appName, taskId).subscribe((res: any) => { service.completeTask(appName, taskId).subscribe((res: any) => {
expect(canCompleteTaskResult).toEqual(true); expect(canCompleteTaskResult).toEqual(true);
@@ -156,7 +129,7 @@ describe('Task Cloud Service', () => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const assignee = 'user12'; const assignee = 'user12';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.claimTask(appName, taskId, assignee).subscribe((res: any) => { service.claimTask(appName, taskId, assignee).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -170,7 +143,7 @@ describe('Task Cloud Service', () => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
const assignee = 'user12'; const assignee = 'user12';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.claimTask(appName, taskId, assignee).subscribe( service.claimTask(appName, taskId, assignee).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -183,7 +156,7 @@ describe('Task Cloud Service', () => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
const assignee = 'user12'; const assignee = 'user12';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.claimTask(appName, taskId, assignee).subscribe( service.claimTask(appName, taskId, assignee).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -195,7 +168,7 @@ describe('Task Cloud Service', () => {
it('should return the task details when unclaiming a task', (done) => { it('should return the task details when unclaiming a task', (done) => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.unclaimTask(appName, taskId).subscribe((res: any) => { service.unclaimTask(appName, taskId).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -208,7 +181,7 @@ describe('Task Cloud Service', () => {
it('should throw error if appName is not defined when unclaiming a task', (done) => { it('should throw error if appName is not defined when unclaiming a task', (done) => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.unclaimTask(appName, taskId).subscribe( service.unclaimTask(appName, taskId).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -220,7 +193,7 @@ describe('Task Cloud Service', () => {
it('should throw error if taskId is not defined when unclaiming a task', (done) => { it('should throw error if taskId is not defined when unclaiming a task', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.unclaimTask(appName, taskId).subscribe( service.unclaimTask(appName, taskId).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -232,7 +205,7 @@ describe('Task Cloud Service', () => {
it('should return the task details when querying by id', (done) => { it('should return the task details when querying by id', (done) => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.getTaskById(appName, taskId).subscribe((res: any) => { service.getTaskById(appName, taskId).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -245,7 +218,7 @@ describe('Task Cloud Service', () => {
it('should throw error if appName is not defined when querying by id', (done) => { it('should throw error if appName is not defined when querying by id', (done) => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.getTaskById(appName, taskId).subscribe( service.getTaskById(appName, taskId).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -257,7 +230,7 @@ describe('Task Cloud Service', () => {
it('should throw error if taskId is not defined when querying by id', (done) => { it('should throw error if taskId is not defined when querying by id', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.getTaskById(appName, taskId).subscribe( service.getTaskById(appName, taskId).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -270,7 +243,7 @@ describe('Task Cloud Service', () => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
const updatePayload = { description: 'New description' }; const updatePayload = { description: 'New description' };
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.updateTask(appName, taskId, updatePayload).subscribe( service.updateTask(appName, taskId, updatePayload).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -283,7 +256,7 @@ describe('Task Cloud Service', () => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
const updatePayload = { description: 'New description' }; const updatePayload = { description: 'New description' };
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.updateTask(appName, taskId, updatePayload).subscribe( service.updateTask(appName, taskId, updatePayload).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -296,7 +269,7 @@ describe('Task Cloud Service', () => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
const updatePayload = { description: 'New description' }; const updatePayload = { description: 'New description' };
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.updateTask(appName, taskId, updatePayload).subscribe((res: any) => { service.updateTask(appName, taskId, updatePayload).subscribe((res: any) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -310,7 +283,7 @@ describe('Task Cloud Service', () => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
const updatePayload = { description: 'New description' }; const updatePayload = { description: 'New description' };
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.updateTask(appName, taskId, updatePayload).subscribe( service.updateTask(appName, taskId, updatePayload).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -323,7 +296,7 @@ describe('Task Cloud Service', () => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
const updatePayload = { description: 'New description' }; const updatePayload = { description: 'New description' };
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.updateTask(appName, taskId, updatePayload).subscribe( service.updateTask(appName, taskId, updatePayload).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -335,7 +308,7 @@ describe('Task Cloud Service', () => {
it('should return the candidate users by appName and taskId', (done) => { it('should return the candidate users by appName and taskId', (done) => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateUsersResults); requestSpy.and.callFake(returnFakeCandidateUsersResults);
service.getCandidateUsers(appName, taskId).subscribe((res: string[]) => { service.getCandidateUsers(appName, taskId).subscribe((res: string[]) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -349,7 +322,7 @@ describe('Task Cloud Service', () => {
it('should log message and return empty array if appName is not defined when fetching candidate users', (done) => { it('should log message and return empty array if appName is not defined when fetching candidate users', (done) => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateUsersResults); requestSpy.and.callFake(returnFakeCandidateUsersResults);
service.getCandidateUsers(appName, taskId).subscribe( service.getCandidateUsers(appName, taskId).subscribe(
(res: any[]) => { (res: any[]) => {
expect(res.length).toBe(0); expect(res.length).toBe(0);
@@ -360,7 +333,7 @@ describe('Task Cloud Service', () => {
it('should log message and return empty array if taskId is not defined when fetching candidate users', (done) => { it('should log message and return empty array if taskId is not defined when fetching candidate users', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateUsersResults); requestSpy.and.callFake(returnFakeCandidateUsersResults);
service.getCandidateUsers(appName, taskId).subscribe( service.getCandidateUsers(appName, taskId).subscribe(
(res: any[]) => { (res: any[]) => {
expect(res.length).toBe(0); expect(res.length).toBe(0);
@@ -371,7 +344,7 @@ describe('Task Cloud Service', () => {
it('should return the candidate groups by appName and taskId', (done) => { it('should return the candidate groups by appName and taskId', (done) => {
const appName = 'taskp-app'; const appName = 'taskp-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateGroupResults); requestSpy.and.callFake(returnFakeCandidateGroupResults);
service.getCandidateGroups(appName, taskId).subscribe((res: string[]) => { service.getCandidateGroups(appName, taskId).subscribe((res: string[]) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -385,7 +358,7 @@ describe('Task Cloud Service', () => {
it('should log message and return empty array if appName is not defined when fetching candidate groups', (done) => { it('should log message and return empty array if appName is not defined when fetching candidate groups', (done) => {
const appName = null; const appName = null;
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateGroupResults); requestSpy.and.callFake(returnFakeCandidateGroupResults);
service.getCandidateGroups(appName, taskId).subscribe( service.getCandidateGroups(appName, taskId).subscribe(
(res: any[]) => { (res: any[]) => {
expect(res.length).toBe(0); expect(res.length).toBe(0);
@@ -396,7 +369,7 @@ describe('Task Cloud Service', () => {
it('should log message and return empty array if taskId is not defined when fetching candidate groups', (done) => { it('should log message and return empty array if taskId is not defined when fetching candidate groups', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = null; const taskId = null;
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeCandidateGroupResults); requestSpy.and.callFake(returnFakeCandidateGroupResults);
service.getCandidateGroups(appName, taskId).subscribe( service.getCandidateGroups(appName, taskId).subscribe(
(res: any[]) => { (res: any[]) => {
expect(res.length).toBe(0); expect(res.length).toBe(0);
@@ -407,7 +380,7 @@ describe('Task Cloud Service', () => {
it('should call assign api and return updated task details', (done) => { it('should call assign api and return updated task details', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.assign(appName, taskId, 'Phil Woods').subscribe( service.assign(appName, taskId, 'Phil Woods').subscribe(
(res) => { (res) => {
expect(res.assignee).toBe('Phil Woods'); expect(res.assignee).toBe('Phil Woods');
@@ -418,7 +391,7 @@ describe('Task Cloud Service', () => {
it('should throw error if appName is not defined when changing task assignee', (done) => { it('should throw error if appName is not defined when changing task assignee', (done) => {
const appName = ''; const appName = '';
const taskId = '68d54a8f'; const taskId = '68d54a8f';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.assign(appName, taskId, 'mock-assignee').subscribe( service.assign(appName, taskId, 'mock-assignee').subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -430,7 +403,7 @@ describe('Task Cloud Service', () => {
it('should throw error if taskId is not defined when changing task assignee', (done) => { it('should throw error if taskId is not defined when changing task assignee', (done) => {
const appName = 'task-app'; const appName = 'task-app';
const taskId = ''; const taskId = '';
spyOn(alfrescoApiMock, 'getInstance').and.callFake(returnFakeTaskDetailsResults); requestSpy.and.callFake(returnFakeTaskDetailsResults);
service.assign(appName, taskId, 'mock-assignee').subscribe( service.assign(appName, taskId, 'mock-assignee').subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, LogService, AppConfigService, CardViewArrayItem, TranslationService } from '@alfresco/adf-core'; import { LogService, AppConfigService, CardViewArrayItem, TranslationService } from '@alfresco/adf-core';
import { throwError, Observable, of, Subject } from 'rxjs'; import { throwError, Observable, of, Subject } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { catchError, map } from 'rxjs/operators';
import { import {
@@ -36,6 +36,7 @@ import {
} from '../models/task.model'; } from '../models/task.model';
import { TaskCloudServiceInterface } from './task-cloud.service.interface'; import { TaskCloudServiceInterface } from './task-cloud.service.interface';
import { IdentityUserService } from '../../people/services/identity-user.service'; import { IdentityUserService } from '../../people/services/identity-user.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -45,13 +46,13 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi
dataChangesDetected$ = new Subject(); dataChangesDetected$ = new Subject();
constructor( constructor(
apiService: AlfrescoApiService, adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private logService: LogService, private logService: LogService,
private translateService: TranslationService, private translateService: TranslationService,
private identityUserService: IdentityUserService private identityUserService: IdentityUserService
) { ) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { Injectable, Inject } from '@angular/core'; import { Injectable, Inject } from '@angular/core';
import { Observable, of, BehaviorSubject, throwError } from 'rxjs'; import { Observable, of, BehaviorSubject, throwError } from 'rxjs';
import { TaskFilterCloudModel } from '../models/filter-cloud.model'; import { TaskFilterCloudModel } from '../models/filter-cloud.model';
@@ -27,6 +27,7 @@ import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { NotificationCloudService } from '../../../services/notification-cloud.service'; import { NotificationCloudService } from '../../../services/notification-cloud.service';
import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model'; import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
import { IdentityUserService } from '../../../people/services/identity-user.service'; import { IdentityUserService } from '../../../people/services/identity-user.service';
import { AdfHttpClient } from '@alfresco/adf-core/api';
const TASK_EVENT_SUBSCRIPTION_QUERY = ` const TASK_EVENT_SUBSCRIPTION_QUERY = `
subscription { subscription {
@@ -55,10 +56,10 @@ export class TaskFilterCloudService extends BaseCloudService {
private identityUserService: IdentityUserService, private identityUserService: IdentityUserService,
@Inject(TASK_FILTERS_SERVICE_TOKEN) @Inject(TASK_FILTERS_SERVICE_TOKEN)
public preferenceService: PreferenceCloudServiceInterface, public preferenceService: PreferenceCloudServiceInterface,
apiService: AlfrescoApiService, adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private notificationCloudService: NotificationCloudService) { private notificationCloudService: NotificationCloudService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
this.filtersSubject = new BehaviorSubject([]); this.filtersSubject = new BehaviorSubject([]);
this.filters$ = this.filtersSubject.asObservable(); this.filters$ = this.filtersSubject.asObservable();
} }
@@ -16,32 +16,23 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { setupTestBed, AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { setupTestBed, LogService } from '@alfresco/adf-core';
import { ServiceTaskListCloudService } from './service-task-list-cloud.service'; import { ServiceTaskListCloudService } from './service-task-list-cloud.service';
import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model'; import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('Activiti ServiceTaskList Cloud Service', () => { describe('Activiti ServiceTaskList Cloud Service', () => {
let service: ServiceTaskListCloudService; let service: ServiceTaskListCloudService;
let alfrescoApiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let logService: LogService; let logService: LogService;
let requestSpy: jasmine.Spy;
const returnCallQueryParameters = (): any => ({ const returnCallQueryParameters = (_queryUrl, options) => Promise.resolve(options.queryParams);
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, queryParams) => Promise.resolve(queryParams)
},
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
});
const returnCallUrl = (): any => ({ const returnCallUrl = (queryUrl) => Promise.resolve(queryUrl);
oauth2Auth: {
callCustomApi: (queryUrl) => Promise.resolve(queryUrl)
},
isEcmLoggedIn: () => false
});
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -50,14 +41,15 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
}); });
beforeEach(() => { beforeEach(() => {
alfrescoApiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
service = TestBed.inject(ServiceTaskListCloudService); service = TestBed.inject(ServiceTaskListCloudService);
logService = TestBed.inject(LogService); logService = TestBed.inject(LogService);
requestSpy = spyOn(adfHttpClient, 'request');
}); });
it('should append to the call all the parameters', (done) => { it('should append to the call all the parameters', (done) => {
const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ServiceTaskQueryCloudRequestModel; const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ServiceTaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getServiceTaskByRequest(taskRequest).subscribe((res) => { service.getServiceTaskByRequest(taskRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -70,7 +62,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
it('should concat the app name to the request url', (done) => { it('should concat the app name to the request url', (done) => {
const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ServiceTaskQueryCloudRequestModel; const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ServiceTaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getServiceTaskByRequest(taskRequest).subscribe((requestUrl) => { service.getServiceTaskByRequest(taskRequest).subscribe((requestUrl) => {
expect(requestUrl).toBeDefined(); expect(requestUrl).toBeDefined();
expect(requestUrl).not.toBeNull(); expect(requestUrl).not.toBeNull();
@@ -84,7 +76,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service',
sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }] sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }]
} as ServiceTaskQueryCloudRequestModel; } as ServiceTaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getServiceTaskByRequest(taskRequest).subscribe((res) => { service.getServiceTaskByRequest(taskRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -95,7 +87,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
it('should return an error when app name is not specified', (done) => { it('should return an error when app name is not specified', (done) => {
const taskRequest = { appName: null } as ServiceTaskQueryCloudRequestModel; const taskRequest = { appName: null } as ServiceTaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getServiceTaskByRequest(taskRequest).subscribe( service.getServiceTaskByRequest(taskRequest).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -111,7 +103,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getBasePath').and.returnValue('http://localhost/fakeName'); spyOn(service, 'getBasePath').and.returnValue('http://localhost/fakeName');
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
logServiceErrorSpy = spyOn(logService, 'error'); logServiceErrorSpy = spyOn(logService, 'error');
}); });
@@ -16,20 +16,21 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { ServiceTaskQueryCloudRequestModel, ServiceTaskIntegrationContextCloudModel } from '../models/service-task-cloud.model'; import { ServiceTaskQueryCloudRequestModel, ServiceTaskIntegrationContextCloudModel } from '../models/service-task-cloud.model';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ServiceTaskListCloudService extends BaseCloudService { export class ServiceTaskListCloudService extends BaseCloudService {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
private logService: LogService) { private logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**
@@ -16,31 +16,22 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed } from '@alfresco/adf-core';
import { TaskListCloudService } from './task-list-cloud.service'; import { TaskListCloudService } from './task-list-cloud.service';
import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AdfHttpClient } from '@alfresco/adf-core/api';
describe('TaskListCloudService', () => { describe('TaskListCloudService', () => {
let service: TaskListCloudService; let service: TaskListCloudService;
let alfrescoApiService: AlfrescoApiService; let adfHttpClient: AdfHttpClient;
let requestSpy: jasmine.Spy;
const returnCallQueryParameters = (): any => ({ const returnCallQueryParameters = (_queryUrl, options) => Promise.resolve(options.queryParams);
oauth2Auth: {
callCustomApi : (_queryUrl, _operation, _context, queryParams) => Promise.resolve(queryParams)
},
isEcmLoggedIn: () => false,
reply: jasmine.createSpy('reply')
});
const returnCallUrl = (): any => ({ const returnCallUrl = (queryUrl) => Promise.resolve(queryUrl);
oauth2Auth: {
callCustomApi : (queryUrl) => Promise.resolve(queryUrl)
},
isEcmLoggedIn: () => false
});
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -50,13 +41,14 @@ describe('TaskListCloudService', () => {
}); });
beforeEach(() => { beforeEach(() => {
alfrescoApiService = TestBed.inject(AlfrescoApiService); adfHttpClient = TestBed.inject(AdfHttpClient);
service = TestBed.inject(TaskListCloudService); service = TestBed.inject(TaskListCloudService);
requestSpy = spyOn(adfHttpClient, 'request');
}); });
it('should append to the call all the parameters', (done) => { it('should append to the call all the parameters', (done) => {
const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as TaskQueryCloudRequestModel; const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as TaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getTaskByRequest(taskRequest).subscribe((res) => { service.getTaskByRequest(taskRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -69,7 +61,7 @@ describe('TaskListCloudService', () => {
it('should concat the app name to the request url', (done) => { it('should concat the app name to the request url', (done) => {
const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as TaskQueryCloudRequestModel; const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as TaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getTaskByRequest(taskRequest).subscribe((requestUrl) => { service.getTaskByRequest(taskRequest).subscribe((requestUrl) => {
expect(requestUrl).toBeDefined(); expect(requestUrl).toBeDefined();
expect(requestUrl).not.toBeNull(); expect(requestUrl).not.toBeNull();
@@ -81,7 +73,7 @@ describe('TaskListCloudService', () => {
it('should concat the sorting to append as parameters', (done) => { it('should concat the sorting to append as parameters', (done) => {
const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service',
sorting: [{ orderBy: 'NAME', direction: 'DESC'}, { orderBy: 'TITLE', direction: 'ASC'}] } as TaskQueryCloudRequestModel; sorting: [{ orderBy: 'NAME', direction: 'DESC'}, { orderBy: 'TITLE', direction: 'ASC'}] } as TaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
service.getTaskByRequest(taskRequest).subscribe((res) => { service.getTaskByRequest(taskRequest).subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res).not.toBeNull(); expect(res).not.toBeNull();
@@ -92,7 +84,7 @@ describe('TaskListCloudService', () => {
it('should return an error when app name is not specified', (done) => { it('should return an error when app name is not specified', (done) => {
const taskRequest = { appName: null } as TaskQueryCloudRequestModel; const taskRequest = { appName: null } as TaskQueryCloudRequestModel;
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
service.getTaskByRequest(taskRequest).subscribe( service.getTaskByRequest(taskRequest).subscribe(
() => { }, () => { },
(error) => { (error) => {
@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService, LogService } from '@alfresco/adf-core';
import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
@@ -24,14 +24,15 @@ import { BaseCloudService } from '../../../services/base-cloud.service';
import { TaskCloudNodePaging } from '../../../models/task-cloud.model'; import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface'; import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
import { AdfHttpClient } from '@alfresco/adf-core/api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class TaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface { export class TaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface {
constructor(apiService: AlfrescoApiService, constructor(adfHttpClient: AdfHttpClient,
appConfigService: AppConfigService, appConfigService: AppConfigService,
protected logService: LogService) { protected logService: LogService) {
super(apiService, appConfigService); super(adfHttpClient, appConfigService);
} }
/** /**