mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Improved type safety
This commit is contained in:
@@ -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) => {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user