mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
* #1712 - changed workflow api call from private to enterprise * #1712 - removed Testbed added injector
This commit is contained in:
@@ -15,23 +15,46 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
|
import {
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoApiService,
|
||||||
|
StorageService,
|
||||||
|
LogService
|
||||||
|
} from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { CoreModule, AlfrescoApiService, LogService, LogServiceMock } from 'ng2-alfresco-core';
|
|
||||||
import { FormService } from './form.service';
|
import { FormService } from './form.service';
|
||||||
|
import { Response, ResponseOptions } from '@angular/http';
|
||||||
import { EcmModelService } from './ecm-model.service';
|
import { EcmModelService } from './ecm-model.service';
|
||||||
import { FormDefinitionModel } from '../models/form-definition.model';
|
import { FormDefinitionModel } from '../models/form-definition.model';
|
||||||
import { Response, ResponseOptions } from '@angular/http';
|
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('FormService', () => {
|
let fakeGroupResponse = {
|
||||||
|
'size': 2,
|
||||||
|
'total': 2,
|
||||||
|
'start': 0,
|
||||||
|
'data': [{
|
||||||
|
'id': 2004,
|
||||||
|
'name': 'PEOPLE_GROUP',
|
||||||
|
'externalId': null,
|
||||||
|
'status': 'active',
|
||||||
|
'groups': null
|
||||||
|
}, { 'id': 2005, 'name': 'PEOPLE_GROUP_2', 'externalId': null, 'status': 'active', 'groups': null }]
|
||||||
|
};
|
||||||
|
|
||||||
let responseBody: any;
|
let fakePeopleResponse = {
|
||||||
let service: FormService;
|
'size': 3,
|
||||||
let apiService: AlfrescoApiService;
|
'total': 3,
|
||||||
let logService: LogService;
|
'start': 0,
|
||||||
let bpmCli: any;
|
'data': [{ 'id': 2002, 'firstName': 'Peo', 'lastName': 'Ple', 'email': 'people' }, {
|
||||||
|
'id': 2003,
|
||||||
|
'firstName': 'Peo02',
|
||||||
|
'lastName': 'Ple02',
|
||||||
|
'email': 'people02'
|
||||||
|
}, { 'id': 2004, 'firstName': 'Peo03', 'lastName': 'Ple03', 'email': 'people03' }]
|
||||||
|
};
|
||||||
|
|
||||||
function createFakeBlob() {
|
function createFakeBlob() {
|
||||||
let data = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
let data = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
||||||
@@ -44,21 +67,26 @@ describe('FormService', () => {
|
|||||||
return new Blob([bytes], { type: 'image/png' });
|
return new Blob([bytes], { type: 'image/png' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
describe('Form service', () => {
|
||||||
|
|
||||||
|
let service, injector, apiService, logService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
imports: [
|
AlfrescoSettingsService,
|
||||||
CoreModule.forRoot()
|
AlfrescoApiService,
|
||||||
],
|
AlfrescoAuthenticationService,
|
||||||
providers: [
|
|
||||||
EcmModelService,
|
EcmModelService,
|
||||||
|
StorageService,
|
||||||
FormService,
|
FormService,
|
||||||
{ provide: LogService, useClass: LogServiceMock }
|
LogService
|
||||||
]
|
]);
|
||||||
});
|
});
|
||||||
service = TestBed.get(FormService);
|
|
||||||
apiService = TestBed.get(AlfrescoApiService);
|
beforeEach(() => {
|
||||||
bpmCli = apiService.getInstance().bpmAuth;
|
service = injector.get(FormService);
|
||||||
logService = TestBed.get(LogService);
|
apiService = injector.get(AlfrescoApiService);
|
||||||
|
logService = injector.get(LogService);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -69,14 +97,51 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse process definitions', (done) => {
|
describe('Content tests', () => {
|
||||||
responseBody = {
|
|
||||||
|
let responseBody = {
|
||||||
data: [
|
data: [
|
||||||
{ id: '1' },
|
{ id: '1' },
|
||||||
{ id: '2' }
|
{ id: '2' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let values = {
|
||||||
|
field1: 'one',
|
||||||
|
field2: 'two'
|
||||||
|
};
|
||||||
|
|
||||||
|
let simpleResponseBody = { id: 1, modelType: 'test' };
|
||||||
|
|
||||||
|
let fileContentPdfResponseBody = {
|
||||||
|
id: 999,
|
||||||
|
name: 'fake-name.pdf',
|
||||||
|
created: '2017-01-23T12:12:53.219+0000',
|
||||||
|
createdBy: { id: 2, firstName: 'fake-admin', lastName: 'fake-last', 'email': 'fake-admin' },
|
||||||
|
relatedContent: false,
|
||||||
|
contentAvailable: true,
|
||||||
|
link: false,
|
||||||
|
mimeType: 'application/pdf',
|
||||||
|
simpleType: 'pdf',
|
||||||
|
previewStatus: 'created',
|
||||||
|
thumbnailStatus: 'created'
|
||||||
|
};
|
||||||
|
|
||||||
|
let fileContentJpgResponseBody = {
|
||||||
|
id: 888,
|
||||||
|
name: 'fake-name.jpg',
|
||||||
|
created: '2017-01-23T12:12:53.219+0000',
|
||||||
|
createdBy: { id: 2, firstName: 'fake-admin', lastName: 'fake-last', 'email': 'fake-admin' },
|
||||||
|
relatedContent: false,
|
||||||
|
contentAvailable: true,
|
||||||
|
link: false,
|
||||||
|
mimeType: 'image/jpeg',
|
||||||
|
simpleType: 'image',
|
||||||
|
previewStatus: 'unsupported',
|
||||||
|
thumbnailStatus: 'unsupported'
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should fetch and parse process definitions', (done) => {
|
||||||
service.getProcessDefinitions().subscribe(result => {
|
service.getProcessDefinitions().subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/process-definitions')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/process-definitions')).toBeTruthy();
|
||||||
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||||
@@ -91,13 +156,6 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse tasks', (done) => {
|
it('should fetch and parse tasks', (done) => {
|
||||||
responseBody = {
|
|
||||||
data: [
|
|
||||||
{id: '1'},
|
|
||||||
{id: '2'}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
service.getTasks().subscribe(result => {
|
service.getTasks().subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/query')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/query')).toBeTruthy();
|
||||||
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||||
@@ -112,29 +170,20 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse the task by id', (done) => {
|
it('should fetch and parse the task by id', (done) => {
|
||||||
responseBody = {
|
|
||||||
id: '1'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.getTask('1').subscribe(result => {
|
service.getTask('1').subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/1')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/1')).toBeTruthy();
|
||||||
expect(result.id).toEqual(responseBody.id);
|
expect(result.id).toEqual('1');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify({ id: '1' })
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should save task form', (done) => {
|
it('should save task form', (done) => {
|
||||||
let values = {
|
|
||||||
field1: 'one',
|
|
||||||
field2: 'two'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.saveTaskForm('1', values).subscribe(() => {
|
service.saveTaskForm('1', values).subscribe(() => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1/save-form')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1/save-form')).toBeTruthy();
|
||||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
||||||
@@ -150,11 +199,6 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should complete task form', (done) => {
|
it('should complete task form', (done) => {
|
||||||
let values = {
|
|
||||||
field1: 'one',
|
|
||||||
field2: 'two'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.completeTaskForm('1', values).subscribe(() => {
|
service.completeTaskForm('1', values).subscribe(() => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
||||||
@@ -170,11 +214,6 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should complete task form with a specific outcome', (done) => {
|
it('should complete task form with a specific outcome', (done) => {
|
||||||
let values = {
|
|
||||||
field1: 'one',
|
|
||||||
field2: 'two'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.completeTaskForm('1', values, 'custom').subscribe(() => {
|
service.completeTaskForm('1', values, 'custom').subscribe(() => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field2).toEqual(values.field2);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field2).toEqual(values.field2);
|
||||||
@@ -191,41 +230,37 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should get task form by id', (done) => {
|
it('should get task form by id', (done) => {
|
||||||
responseBody = {id: 1};
|
|
||||||
|
|
||||||
service.getTaskForm('1').subscribe(result => {
|
service.getTaskForm('1').subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
expect(result.id).toEqual(responseBody.id);
|
expect(result.id).toEqual(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify({ id: 1 })
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition by id', (done) => {
|
it('should get form definition by id', (done) => {
|
||||||
responseBody = {id: 1};
|
|
||||||
|
|
||||||
service.getFormDefinitionById('1').subscribe(result => {
|
service.getFormDefinitionById('1').subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/form-models/1')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/form-models/1')).toBeTruthy();
|
||||||
expect(result.id).toEqual(responseBody.id);
|
expect(result.id).toEqual(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify({ id: 1 })
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition id by name', (done) => {
|
it('should get form definition id by name', (done) => {
|
||||||
const formName = 'form1';
|
const formName = 'form1';
|
||||||
const formId = 1;
|
const formId = 1;
|
||||||
responseBody = {
|
let response = {
|
||||||
data: [
|
data: [
|
||||||
{ id: formId }
|
{ id: formId }
|
||||||
]
|
]
|
||||||
@@ -240,7 +275,7 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(response)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -287,54 +322,56 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle error with generic message', () => {
|
it('should handle error with generic message', () => {
|
||||||
spyOn(logService, 'error').and.stub();
|
service.handleError(null).subscribe(() => {
|
||||||
|
}, (error) => {
|
||||||
service.handleError(null);
|
expect(error).toBe(FormService.UNKNOWN_ERROR_MESSAGE);
|
||||||
expect(logService.error).toHaveBeenCalledWith(FormService.UNKNOWN_ERROR_MESSAGE);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle error with error message', () => {
|
it('should handle error with error message', () => {
|
||||||
spyOn(logService, 'error').and.stub();
|
|
||||||
|
|
||||||
const message = '<error>';
|
const message = '<error>';
|
||||||
service.handleError({message: message});
|
|
||||||
|
|
||||||
expect(logService.error).toHaveBeenCalledWith(message);
|
service.handleError({ message: message }).subscribe(() => {
|
||||||
|
}, (error) => {
|
||||||
|
expect(error).toBe(message);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle error with detailed message', () => {
|
it('should handle error with detailed message', () => {
|
||||||
spyOn(logService, 'error').and.stub();
|
|
||||||
service.handleError({
|
service.handleError({
|
||||||
status: '400',
|
status: '400',
|
||||||
statusText: 'Bad request'
|
statusText: 'Bad request'
|
||||||
|
}).subscribe(
|
||||||
|
() => {
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
expect(error).toBe('400 - Bad request');
|
||||||
});
|
});
|
||||||
expect(logService.error).toHaveBeenCalledWith('400 - Bad request');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle error with generic message', () => {
|
it('should handle error with generic message', () => {
|
||||||
spyOn(logService, 'error').and.stub();
|
service.handleError({}).subscribe(() => {
|
||||||
service.handleError({});
|
}, (error) => {
|
||||||
expect(logService.error).toHaveBeenCalledWith(FormService.GENERIC_ERROR_MESSAGE);
|
expect(error).toBe(FormService.GENERIC_ERROR_MESSAGE);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get all the forms with modelType=2', (done) => {
|
it('should get all the forms with modelType=2', (done) => {
|
||||||
responseBody = {};
|
|
||||||
|
|
||||||
service.getForms().subscribe(result => {
|
service.getForms().subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('models?modelType=2')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('models?modelType=2')).toBeTruthy();
|
||||||
expect(result).toEqual(responseBody);
|
expect(result).toEqual({});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify({})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should search for Form with modelType=2', (done) => {
|
it('should search for Form with modelType=2', (done) => {
|
||||||
responseBody = {data: [{id: 1, name: 'findme'}, {id: 2, name: 'testform'}]};
|
let response = { data: [{ id: 1, name: 'findme' }, { id: 2, name: 'testform' }] };
|
||||||
|
|
||||||
service.searchFrom('findme').subscribe(result => {
|
service.searchFrom('findme').subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('models?modelType=2')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('models?modelType=2')).toBeTruthy();
|
||||||
@@ -346,13 +383,11 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(response)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a Form with modelType=2', (done) => {
|
it('should create a Form with modelType=2', (done) => {
|
||||||
responseBody = {id: 1, modelType: 'test'};
|
|
||||||
|
|
||||||
service.createForm('testName').subscribe(result => {
|
service.createForm('testName').subscribe(result => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/models')).toBeTruthy();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/models')).toBeTruthy();
|
||||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).modelType).toEqual(2);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).modelType).toEqual(2);
|
||||||
@@ -363,13 +398,11 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(simpleResponseBody)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add form fields to a form', (done) => {
|
it('should add form fields to a form', (done) => {
|
||||||
responseBody = {id: 1, modelType: 'test'};
|
|
||||||
|
|
||||||
let formId = '100';
|
let formId = '100';
|
||||||
let name = 'testName';
|
let name = 'testName';
|
||||||
let data = [{ name: 'name' }, { name: 'email' }];
|
let data = [{ name: 'name' }, { name: 'email' }];
|
||||||
@@ -384,25 +417,12 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(simpleResponseBody)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the unsupported content when the file is an image', (done) => {
|
it('should return the unsupported content when the file is an image', (done) => {
|
||||||
let contentId: number = 999;
|
let contentId: number = 888;
|
||||||
responseBody = {
|
|
||||||
id: contentId,
|
|
||||||
name: 'fake-name.jpg',
|
|
||||||
created: '2017-01-23T12:12:53.219+0000',
|
|
||||||
createdBy: {id: 2, firstName: 'fake-admin', lastName: 'fake-last', 'email': 'fake-admin'},
|
|
||||||
relatedContent: false,
|
|
||||||
contentAvailable: true,
|
|
||||||
link: false,
|
|
||||||
mimeType: 'image/jpeg',
|
|
||||||
simpleType: 'image',
|
|
||||||
previewStatus: 'unsupported',
|
|
||||||
thumbnailStatus: 'unsupported'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.getFileContent(contentId).subscribe(result => {
|
service.getFileContent(contentId).subscribe(result => {
|
||||||
expect(result.id).toEqual(contentId);
|
expect(result.id).toEqual(contentId);
|
||||||
@@ -415,25 +435,12 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(fileContentJpgResponseBody)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the supported content when the file is a pdf', (done) => {
|
it('should return the supported content when the file is a pdf', (done) => {
|
||||||
let contentId: number = 888;
|
let contentId: number = 999;
|
||||||
responseBody = {
|
|
||||||
id: contentId,
|
|
||||||
name: 'fake-name.pdf',
|
|
||||||
created: '2017-01-23T12:12:53.219+0000',
|
|
||||||
createdBy: {id: 2, firstName: 'fake-admin', lastName: 'fake-last', 'email': 'fake-admin'},
|
|
||||||
relatedContent: false,
|
|
||||||
contentAvailable: true,
|
|
||||||
link: false,
|
|
||||||
mimeType: 'application/pdf',
|
|
||||||
simpleType: 'pdf',
|
|
||||||
previewStatus: 'created',
|
|
||||||
thumbnailStatus: 'created'
|
|
||||||
};
|
|
||||||
|
|
||||||
service.getFileContent(contentId).subscribe(result => {
|
service.getFileContent(contentId).subscribe(result => {
|
||||||
expect(result.id).toEqual(contentId);
|
expect(result.id).toEqual(contentId);
|
||||||
@@ -446,22 +453,20 @@ describe('FormService', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
'status': 200,
|
'status': 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(responseBody)
|
responseText: JSON.stringify(fileContentPdfResponseBody)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the raw content URL', () => {
|
it('should return the raw content URL', () => {
|
||||||
let contentId: number = 999;
|
let contentId: number = 999;
|
||||||
let contentRawUrl = service.getFileRawContentUrl(contentId);
|
let contentUrl = service.getFileRawContentUrl(contentId);
|
||||||
expect(contentRawUrl).toEqual(`${bpmCli.basePath}/api/enterprise/content/${contentId}/raw`);
|
expect(contentUrl).toContain(`/api/enterprise/content/${contentId}/raw`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a Blob as thumbnail', (done) => {
|
it('should return a Blob as thumbnail', (done) => {
|
||||||
let contentId: number = 999;
|
let contentId: number = 999;
|
||||||
|
|
||||||
let blob = createFakeBlob();
|
let blob = createFakeBlob();
|
||||||
spyOn(service, 'getContentThumbnailUrl').and.returnValue(Observable.of(blob));
|
spyOn(service, 'getContentThumbnailUrl').and.returnValue(Observable.of(blob));
|
||||||
|
|
||||||
service.getContentThumbnailUrl(contentId).subscribe(result => {
|
service.getContentThumbnailUrl(contentId).subscribe(result => {
|
||||||
expect(result).toEqual(jasmine.any(Blob));
|
expect(result).toEqual(jasmine.any(Blob));
|
||||||
expect(result.size).toEqual(48);
|
expect(result.size).toEqual(48);
|
||||||
@@ -470,12 +475,46 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return list of people', (done) => {
|
||||||
|
let fakeFilter: string = 'whatever';
|
||||||
|
|
||||||
|
service.getWorkflowUsers(fakeFilter).subscribe(result => {
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result.length).toBe(3);
|
||||||
|
expect(result[0].id).toBe(2002);
|
||||||
|
expect(result[0].firstName).toBe('Peo');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(fakePeopleResponse)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return list of groups', (done) => {
|
||||||
|
let fakeFilter: string = 'whatever';
|
||||||
|
|
||||||
|
service.getWorkflowGroups(fakeFilter).subscribe(result => {
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result.length).toBe(2);
|
||||||
|
expect(result[0].id).toBe(2004);
|
||||||
|
expect(result[0].name).toBe('PEOPLE_GROUP');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(fakeGroupResponse)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should create a Form form a Node', (done) => {
|
it('should create a Form form a Node', (done) => {
|
||||||
|
|
||||||
let nameForm = 'testNode';
|
let nameForm = 'testNode';
|
||||||
|
|
||||||
responseBody = {id: 1, modelType: 'test'};
|
|
||||||
|
|
||||||
let formId = 100;
|
let formId = 100;
|
||||||
|
|
||||||
stubCreateForm();
|
stubCreateForm();
|
||||||
@@ -532,4 +571,6 @@ describe('FormService', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -294,67 +294,34 @@ export class FormService {
|
|||||||
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValuesColumn(taskId, field, column));
|
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValuesColumn(taskId, field, column));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: uses private webApp api
|
|
||||||
getWorkflowGroups(filter: string, groupId?: string): Observable<GroupModel[]> {
|
|
||||||
return Observable.create(observer => {
|
|
||||||
|
|
||||||
let xhr: XMLHttpRequest = new XMLHttpRequest();
|
|
||||||
xhr.withCredentials = true;
|
|
||||||
|
|
||||||
xhr.onreadystatechange = () => {
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
let json = JSON.parse(xhr.response);
|
|
||||||
let data: GroupModel[] = (json.data || []).map(item => <GroupModel> item);
|
|
||||||
observer.next(data);
|
|
||||||
observer.complete();
|
|
||||||
} else {
|
|
||||||
this.logService.error(xhr.response);
|
|
||||||
Observable.throw(new Error(xhr.response));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let host = this.apiService.getInstance().config.hostBpm;
|
|
||||||
let url = `${host}/activiti-app/app/rest/workflow-groups?filter=${filter}`;
|
|
||||||
if (groupId) {
|
|
||||||
url += `&groupId=${groupId}`;
|
|
||||||
}
|
|
||||||
xhr.open('GET', url, true);
|
|
||||||
xhr.setRequestHeader('Authorization', this.apiService.getInstance().getTicketBpm());
|
|
||||||
xhr.send();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getWorkflowUsers(filter: string, groupId?: string): Observable<GroupUserModel[]> {
|
getWorkflowUsers(filter: string, groupId?: string): Observable<GroupUserModel[]> {
|
||||||
return Observable.create(observer => {
|
let option: any = { filter: filter };
|
||||||
|
|
||||||
let xhr: XMLHttpRequest = new XMLHttpRequest();
|
|
||||||
xhr.withCredentials = true;
|
|
||||||
|
|
||||||
xhr.onreadystatechange = () => {
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
let json = JSON.parse(xhr.response);
|
|
||||||
let data: GroupUserModel[] = (json.data || []).map(item => <GroupUserModel> item);
|
|
||||||
observer.next(data);
|
|
||||||
observer.complete();
|
|
||||||
} else {
|
|
||||||
this.logService.error(xhr.response);
|
|
||||||
Observable.throw(new Error(xhr.response));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let host = this.apiService.getInstance().config.hostBpm;
|
|
||||||
let url = `${host}/activiti-app/app/rest/workflow-users?filter=${filter}`;
|
|
||||||
if (groupId) {
|
if (groupId) {
|
||||||
url += `&groupId=${groupId}`;
|
option.groupId = groupId;
|
||||||
}
|
}
|
||||||
xhr.open('GET', url, true);
|
return Observable.fromPromise(this.getWorkflowUserApi(option))
|
||||||
xhr.setRequestHeader('Authorization', this.apiService.getInstance().getTicketBpm());
|
.map((response: any) => <GroupUserModel[]> response.data || [])
|
||||||
xhr.send();
|
.catch(err => this.handleError(err));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
private getWorkflowUserApi(options: any) {
|
||||||
|
let alfrescoApi = this.apiService.getInstance();
|
||||||
|
return alfrescoApi.activiti.usersWorkflowApi.getUsers(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
getWorkflowGroups(filter: string, groupId?: string): Observable<GroupModel[]> {
|
||||||
|
let option: any = { filter: filter };
|
||||||
|
if (groupId) {
|
||||||
|
option.groupId = groupId;
|
||||||
|
}
|
||||||
|
return Observable.fromPromise(this.getWorkflowGroupsApi(option))
|
||||||
|
.map((response: any) => <GroupModel[]> response.data || [])
|
||||||
|
.catch(err => this.handleError(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
private getWorkflowGroupsApi(options: any) {
|
||||||
|
let alfrescoApi = this.apiService.getInstance();
|
||||||
|
return alfrescoApi.activiti.groupsApi.getGroups(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormId(res: any): string {
|
getFormId(res: any): string {
|
||||||
|
Reference in New Issue
Block a user