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

View File

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

View File

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

View File

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

View File

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

View File

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