Improved type safety

This commit is contained in:
Denys Vuika 2016-08-24 17:46:55 +01:00
parent 5773b88ab4
commit f08796a3d2
6 changed files with 30 additions and 25 deletions

View File

@ -19,19 +19,26 @@ import {it, describe, beforeEach, afterEach} from '@angular/core/testing';
import {ReflectiveInjector, provide} from '@angular/core';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
declare var AlfrescoApi: any;
declare let jasmine: any;
describe('AlfrescoAuthentication', () => {
let injector, authService;
let injector;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsService}),
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
]);
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
let store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
@ -61,8 +68,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is ECM', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ECM');
settingsService.setProviders('ECM');
});
it('should return an ECM ticket after the login done', (done) => {
@ -144,8 +150,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is BPM', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('BPM');
settingsService.setProviders('BPM');
});
it('should return an BPM ticket after the login done', (done) => {
@ -212,24 +217,23 @@ describe('AlfrescoAuthentication', () => {
describe('Setting service change should reflect in the api', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ALL');
settingsService.setProviders('ALL');
});
it('should host ecm url change be reflected in the api configuration', () => {
authService.alfrescoSetting.ecmHost = '127.99.99.99';
settingsService.ecmHost = '127.99.99.99';
expect(authService.getAlfrescoApi().config.hostEcm).toBe('127.99.99.99');
});
it('should host bpm url change be reflected in the api configuration', () => {
authService.alfrescoSetting.bpmHost = '127.99.99.99';
settingsService.bpmHost = '127.99.99.99';
expect(authService.getAlfrescoApi().config.hostBpm).toBe('127.99.99.99');
});
it('should host bpm provider change be reflected in the api configuration', () => {
authService.alfrescoSetting.setProviders('ECM');
settingsService.setProviders('ECM');
expect(authService.getAlfrescoApi().config.provider).toBe('ECM');
});
@ -239,8 +243,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is both ECM and BPM ', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.providers = 'ALL';
settingsService.setProviders('ALL');
});
it('should return both ECM and BPM tickets after the login done', (done) => {

View File

@ -76,7 +76,7 @@ export class AlfrescoAuthenticationService {
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string) {
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => {
this.saveTickets();
@ -196,7 +196,7 @@ export class AlfrescoAuthenticationService {
return Observable.throw(error || 'Server error');
}
getAlfrescoApi(): any {
getAlfrescoApi(): AlfrescoJsApi {
return this.alfrescoApi;
}
}

View File

@ -20,6 +20,7 @@ import {ReflectiveInjector} from '@angular/core';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
import {AlfrescoContentService} from './AlfrescoContent.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
describe('AlfrescoContentService', () => {
@ -29,6 +30,7 @@ describe('AlfrescoContentService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
AlfrescoContentService,
AlfrescoAuthenticationService,
AlfrescoSettingsService

View File

@ -30,6 +30,7 @@ import {
HostListener
} from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { MinimalNodeEntity } from 'alfresco-js-api';
import {
CONTEXT_MENU_DIRECTIVES,
AlfrescoTranslationService
@ -43,7 +44,6 @@ import {
} from 'ng2-alfresco-datatable';
import { DocumentListService } from './../services/document-list.service';
import { MinimalNodeEntity } from './../models/document-library.model';
import { ContentActionModel } from './../models/content-action.model';
import {
ShareDataTableAdapter,

View File

@ -24,7 +24,8 @@ import {
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
AlfrescoContentService,
AlfrescoApiService
} from 'ng2-alfresco-core';
import { FileNode } from '../assets/document-library.model.mock';
import { ReflectiveInjector } from '@angular/core';
@ -42,6 +43,7 @@ describe('DocumentListService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoSettingsService
]);

View File

@ -18,14 +18,12 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoJsApi, NodePaging, MinimalNodeEntity } from 'alfresco-js-api';
import {
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core';
declare let AlfrescoApi: any;
@Injectable()
export class DocumentListService {
@ -66,11 +64,11 @@ export class DocumentListService {
) {
}
private getAlfrescoApi() {
private getAlfrescoApi(): AlfrescoJsApi {
return this.authService.getAlfrescoApi();
}
private getNodesPromise(folder: string, opts?: any) {
private getNodesPromise(folder: string, opts?: any): Promise<NodePaging> {
let nodeId = '-root-';
let params: any = {
relativePath: folder,
@ -86,11 +84,11 @@ export class DocumentListService {
}
}
return this.getAlfrescoApi().node.getNodeChildren(nodeId, params);
return this.getAlfrescoApi().nodes.getNodeChildren(nodeId, params);
}
deleteNode(nodeId: string) {
return Observable.fromPromise(this.getAlfrescoApi().node.deleteNode(nodeId));
deleteNode(nodeId: string): Observable<any> {
return Observable.fromPromise(this.getAlfrescoApi().nodes.deleteNode(nodeId));
}
/**