Update from development branch

This commit is contained in:
Denys Vuika
2016-07-13 12:58:02 +01:00
60 changed files with 429 additions and 484 deletions

View File

@@ -14,7 +14,8 @@ var map = {
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'alfresco-js-api' : { main: 'alfresco-js-api.js', defaultExtension: 'js' },
'ng2-translate': { defaultExtension: 'js' }
};

View File

@@ -11,10 +11,13 @@ module.exports = function (config) {
{pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true},
{pattern: 'node_modules/zone.js/dist/async-test.js', included: true, watched: true},
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.map', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.map', included: false, watched: false},
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@@ -6,19 +6,15 @@
"scripts": {
"clean": "rimraf dist node_modules typings",
"typings": "typings install",
"build": "npm run tslint && typings install && rimraf dist && tsc && npm run copytemplates && license-check",
"build": "npm run tslint && typings install && rimraf dist && tsc && license-check",
"build:w": "npm run tslint && typings install && rimraf dist && npm run watch-task",
"watch-task": "concurrently \"npm run tsc:w\" \"license-check\"",
"tslint": "npm run tslint-src && npm run tslint-root",
"tslint-src": "tslint -c tslint.json src/{,**/}**.ts",
"tslint-root": "tslint -c tslint.json *.ts",
"copytemplates": "npm run copy-html-css && npm run copy-i18n",
"copy-html-css": "cpx \"./src/**/*.{html,css}\" ./dist/src",
"copy-html-css:w": "cpx \"./src/**/*.{html,css}\" ./dist/src -w",
"copy-i18n": "cpx \"./i18n/**/*.json\" ./dist/i18n",
"copy-i18n:w": "cpx \"./i18n/**/*.json\" ./dist/i18n -w",
"copy-images": "cpx \"./src/**/*.{png,jpg,gif,svg}\" ./dist/src",
"copy-images:w": "cpx \"./src/**/*.{png,jpg,gif,svg}\" ./dist/src -w",
"licensecheck": "license-check",
"tsc": "tsc",
"tsc:w": "tsc -w",
"pretest": "npm run build",
"test": "karma start karma.conf.js --reporters mocha,coverage --single-run",
"test-browser": "karma start karma.conf.js --reporters kjhtml ",
@@ -45,6 +41,10 @@
{
"name": "Mario Romano",
"email": "mario.romano83@gmail.com"
},
{
"name": "Eugenio Romano",
"email": "eugenio.romano@alfresco.com"
}
],
"keywords": [
@@ -54,6 +54,7 @@
"alfresco"
],
"dependencies": {
"alfresco-js-api": "^0.2.0",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
@@ -69,8 +70,7 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"ng2-translate": "2.2.2",
"rimraf": "2.5.2"
"ng2-translate": "2.2.2"
},
"peerDependencies": {
"material-design-icons": "^2.2.3",
@@ -90,6 +90,7 @@
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -0,0 +1,35 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class AlfrescoApiMock {
login(username: string, password: string) {
return new Promise((resolve) => {
resolve('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
});
}
logout() {
return new Promise((resolve) => {
resolve('logout');
});
}
changeConfig() {
}
}

View File

@@ -19,6 +19,7 @@ import { Observable } from 'rxjs/Rx';
export interface AbstractAuthentication {
TYPE: string;
alfrescoApi: any;
login(username: string, password: string): Observable<any>;
@@ -26,8 +27,7 @@ export interface AbstractAuthentication {
isLoggedIn(): boolean ;
getToken(): string;
saveToken(): void;
getTicket(): string;
saveTicket(ticket: any): void;
}

View File

@@ -24,7 +24,6 @@ import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
TYPE: string = 'BPM';
private token: string;
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
private http: Http) {
@@ -41,9 +40,8 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
login(username: string, password: string): Observable<any> {
return Observable.fromPromise(this.apiActivitiLogin(username, password))
.map((response: any) => {
this.token = response.status;
return this.token;
// return {name: this.TYPE, token: response.status};
this.saveTicket(response.status);
return response.status;
})
.catch(this.handleError);
}
@@ -57,7 +55,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
return Observable.fromPromise(this.apiActivitiLogout())
.map(res => <any> res)
.do(response => {
this.removeToken(this.TYPE);
this.removeTicket(this.TYPE);
})
.catch(this.handleError);
}
@@ -67,7 +65,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.getToken();
return !!this.getTicket();
}
private apiActivitiLogin(username: string, password: string) {
@@ -91,17 +89,17 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
return this.http.get(url).toPromise();
}
public getToken (): string {
return localStorage.getItem(`token-${this.TYPE}`);
public getTicket(): string {
return localStorage.getItem(`ticket-${this.TYPE}`);
}
/**
* The method save the toke in the localStorage
* @param token
* The method save the ticket in the localStorage
* @param ticket
*/
public saveToken(): void {
if (this.token) {
super.saveToken(this.TYPE, this.token);
public saveTicket(ticket): void {
if (ticket) {
super.saveTicket(this.TYPE, ticket);
}
}

View File

@@ -23,6 +23,8 @@ declare let AlfrescoApi: any;
export class AlfrescoAuthenticationBase {
alfrescoApi: any;
private _authUrl: string = '/alfresco/api/-default-/public/authentication/versions/1';
private alfrescoSetting: AlfrescoSettingsService;
/**
@@ -40,19 +42,19 @@ export class AlfrescoAuthenticationBase {
/**
* The method save the toke in the localStorage
* @param token
* @param ticket
*/
public saveToken(provider:string, token: string): void {
if (token) {
localStorage.setItem(`token-${provider}`, token);
public saveTicket(provider:string, ticket: string): void {
if (ticket) {
localStorage.setItem(`ticket-${provider}`, ticket);
}
}
/**
* Remove the login token from localStorage
* Remove the login ticket from localStorage
*/
public removeToken(provider:string): void {
localStorage.removeItem(`token-${provider}`);
public removeTicket(provider:string): void {
localStorage.removeItem(`ticket-${provider}`);
}
/**

View File

@@ -26,84 +26,97 @@ declare let AlfrescoApi: any;
export class AlfrescoAuthenticationECM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
TYPE: string = 'ECM';
private token: string;
alfrescoApi: any;
/**
* Constructor
* @param alfrescoSettingsService
*/
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
private http: Http) {
super(alfrescoSettingsService, http);
if (!this.isLoggedIn) {
this.alfrescoApi = new AlfrescoApi({
host: this.getBaseUrl()
});
} else {
this.alfrescoApi = new AlfrescoApi({
ticket: this.getTicket(),
host: this.getBaseUrl()
});
}
}
getBaseUrl(): string {
return this.alfrescoSettingsService.host;
}
getAlfrescoApi(): any {
return this.alfrescoApi;
}
/**
* Perform a login on behalf of the user and store the ticket returned
*
* The method return tru if the user is logged in
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.getTicket();
}
/**
* Method to delegate to POST login
* @param username
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string): Observable<any> {
return Observable.fromPromise(this.getCreateTicketPromise(username, password))
.map((response: any) => {
this.token = response.entry.id;
return this.token;
// return {name: this.TYPE, token: response.entry.id};
login(username: string, password: string) {
this.alfrescoApi = new AlfrescoApi({
username: username,
password: password,
host: this.getBaseUrl()
});
return Observable.fromPromise(this.alfrescoApi.login())
.map(res => <any> res)
.do(response => {
this.saveTicket(response);
return response;
})
.catch(this.handleError);
}
/**
* Delete the current login ticket from the server
* The method remove the ticket from the local storage
*
* @returns {Observable<R>|Observable<T>}
*/
logout() {
return Observable.fromPromise(this.getDeleteTicketPromise())
public logout() {
return Observable.fromPromise(this.alfrescoApi.logout())
.map(res => <any> res)
.do(response => {
this.removeToken(this.TYPE);
this.removeTicket(this.TYPE);
return response;
})
.catch(this.handleError);
}
/**
* The method return true if the user is logged in
* @returns {boolean}
* The method return the ticket stored in the localStorage
* @returns ticket
*/
isLoggedIn(): boolean {
return !!this.getToken();
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getToken());
}
private getCreateTicketPromise(username: string, password: string) {
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
let loginRequest = new AlfrescoApi.Auth.LoginRequest();
loginRequest.userId = username;
loginRequest.password = password;
return apiInstance.createTicket(loginRequest);
}
private getDeleteTicketPromise() {
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
return apiInstance.deleteTicket();
public getTicket(): string {
return localStorage.getItem(`ticket-${this.TYPE}`);
}
/**
* The method return the token stored in the localStorage
* @param token
* The method save the ticket in the localStorage
* @param ticket
*/
public getToken (): string {
return localStorage.getItem(`token-${this.TYPE}`);
}
/**
* The method save the toke in the localStorage
* @param token
*/
public saveToken(): void {
if (this.token) {
super.saveToken(this.TYPE, this.token);
public saveTicket(ticket): void {
if (ticket) {
super.saveTicket(this.TYPE, ticket);
}
}

View File

@@ -36,7 +36,7 @@ describe('AlfrescoAuthentication', () => {
resolve({
entry: {
userId: 'fake-username',
id: 'fake-post-token-ECM'
id: 'fake-post-ticket-ECM'
}
});
reject({
@@ -48,7 +48,7 @@ describe('AlfrescoAuthentication', () => {
fakePromiseBPM = new Promise(function (resolve, reject) {
resolve({
status: 'fake-post-token-BPM'
status: 'fake-post-ticket-BPM'
});
reject({
response: {
@@ -109,7 +109,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return an ECM token after the login done', (done) => {
it('should return an ECM ticket after the login done', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -120,13 +120,13 @@ describe('AlfrescoAuthentication', () => {
service.login('fake-username', 'fake-password', providers)
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-ECM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-ECM');
done();
}
);
});
it('should return token undefined when the credentials are wrong', (done) => {
it('should return ticket undefined when the credentials are wrong', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -142,7 +142,7 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
done();
}
);
@@ -186,21 +186,21 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return a token undefined after logout', (done) => {
it('should return a ticket undefined after logout', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-ECM', 'fake-post-token-ECM');
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationECM.prototype, 'getDeleteTicketPromise').and.returnValue(fakePromiseECM);
service.logout()
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(localStorage.getItem('token-ECM')).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
done();
}
);
@@ -252,7 +252,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return an BPM token after the login done', (done) => {
it('should return an BPM ticket after the login done', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -263,13 +263,13 @@ describe('AlfrescoAuthentication', () => {
service.login('fake-username', 'fake-password', providers)
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-BPM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-BPM');
done();
}
);
});
it('should return token undefined when the credentials are wrong', (done) => {
it('should return ticket undefined when the credentials are wrong', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -284,27 +284,27 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
done();
}
);
});
it('should return a token undefined after logout', (done) => {
it('should return a ticket undefined after logout', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-BPM', 'fake-post-token-BPM');
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationBPM.prototype, 'apiActivitiLogout').and.returnValue(fakePromiseBPM);
service.logout()
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(localStorage.getItem('token-BPM')).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(localStorage.getItem('ticket-BPM')).toBeUndefined();
done();
}
);
@@ -316,7 +316,7 @@ describe('AlfrescoAuthentication', () => {
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-BPM', 'fake-post-token-BPM');
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationBPM.prototype, 'apiActivitiLogout').and.returnValue(Promise.reject('fake logout error'));
@@ -328,7 +328,7 @@ describe('AlfrescoAuthentication', () => {
(err: any) => {
expect(err).toBeDefined();
expect(err.message).toEqual('fake logout error');
expect(localStorage.getItem('token-BPM')).toEqual('fake-post-token-BPM');
expect(localStorage.getItem('ticket-BPM')).toEqual('fake-post-ticket-BPM');
done();
}
);
@@ -361,7 +361,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return both ECM and BPM tokens after the login done', (done) => {
it('should return both ECM and BPM tickets after the login done', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -374,14 +374,14 @@ describe('AlfrescoAuthentication', () => {
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.isLoggedIn(providers[1])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-ECM');
expect(service.getToken(providers[1])).toEqual('fake-post-token-BPM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-ECM');
expect(service.getTicket(providers[1])).toEqual('fake-post-ticket-BPM');
done();
}
);
});
it('should return token undefined when the credentials are correct for the ECM login but wrong for the BPM login', (done) => {
it('should return ticket undefined when the credentials are correct for the ECM login but wrong for the BPM login', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -397,15 +397,15 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(service.isLoggedIn(providers[1])).toBe(false);
expect(service.getToken(providers[1])).toBeUndefined();
expect(service.getTicket(providers[1])).toBeUndefined();
done();
}
);
});
it('should return token undefined when the credentials are correct for the BPM login but wrong for the ECM login', (done) => {
it('should return ticket undefined when the credentials are correct for the BPM login but wrong for the ECM login', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -422,9 +422,9 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(service.isLoggedIn(providers[1])).toBe(false);
expect(service.getToken(providers[1])).toBeUndefined();
expect(service.getTicket(providers[1])).toBeUndefined();
done();
}
);

View File

@@ -26,7 +26,7 @@ import { AlfrescoAuthenticationBase } from './AlfrescoAuthenticationBase.service
declare let AlfrescoApi: any;
/**
* The AlfrescoAuthenticationService provide the login service and store the token in the localStorage
* The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage
*/
@Injectable()
export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
@@ -78,10 +78,6 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
return Observable.create(observer => {
Observable.forkJoin(observableBatch).subscribe(
(response: any[]) => {
this.performeSaveToken();
/*response.forEach((res) => {
this.performeSaveToken(res.name, res.token);
});*/
observer.next(response);
},
(err: any) => {
@@ -91,7 +87,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
}
/**
* The method return tru if the user is logged in
* The method return true if the user is logged in
* @returns {boolean}
*/
isLoggedIn(type: string = 'ECM'): boolean {
@@ -102,36 +98,24 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
return false;
}
getAlfrescoApi(): any {
return this.findProviderInstance('ECM').alfrescoApi;
}
/**
* Return the token stored in the localStorage of the specific provider type
* @param token
* Return the ticket stored in the localStorage of the specific provider type
* @param ticket
*/
public getToken(type: string = 'ECM'): string {
public getTicket(type: string = 'ECM'): string {
let auth: AbstractAuthentication = this.findProviderInstance(type);
if (auth) {
return auth.getToken();
return auth.getTicket();
}
return '';
}
/**
* Save the token calling the method of the specific provider type
* @param providerName
* @param token
*/
private performeSaveToken() {
/* let auth: AbstractAuthentication = this.findProviderInstance(type);
if (auth) {
auth.saveToken();
}
*/
this.providersInstance.forEach((authInstance) => {
authInstance.saveToken();
});
}
/**
* The method remove the token from the local storage
* The method remove the ticket from the local storage
* @returns {Observable<T>}
*/
public logout(): Observable<string> {
@@ -190,7 +174,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
let auth: AbstractAuthentication = null;
if (this.providersInstance && this.providersInstance.length !== 0) {
this.providersInstance.forEach((provider) => {
if (provider.TYPE === type) {
if (provider.TYPE === type.toUpperCase()) {
auth = provider;
}
});

View File

@@ -18,15 +18,11 @@
import { Injectable } from '@angular/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
@Injectable()
export class AlfrescoContentService {
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService
) {
constructor(private authService: AlfrescoAuthenticationService) {
}
/**
@@ -34,9 +30,8 @@ export class AlfrescoContentService {
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/renditions/doclib/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
getDocumentThumbnailUrl(document: any): string {
return this.authService.alfrescoApi.content.getDocumentThumbnailUrl(document.entry.id);
}
/**
@@ -44,8 +39,7 @@ export class AlfrescoContentService {
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
getContentUrl(document: any): string {
return this.authService.alfrescoApi.content.getContentUrl(document.entry.id);
}
}

View File

@@ -26,6 +26,8 @@ describe('AlfrescoContentService', () => {
let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService;
const nodeId = 'blah';
let DEFAULT_CONTEXT_PATH: string = '/alfresco';
let DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1';
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
@@ -35,7 +37,7 @@ describe('AlfrescoContentService', () => {
AlfrescoSettingsService
]);
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return 'myToken';
return 'myTicket';
});
service = injector.get(AlfrescoContentService);
authService = injector.get(AlfrescoAuthenticationService);
@@ -47,9 +49,9 @@ describe('AlfrescoContentService', () => {
id: nodeId
}
})).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
'?attachment=false&alf_ticket=' + authService.getToken()
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
'?attachment=false&alf_ticket=' + authService.getTicket()
);
});
@@ -59,9 +61,9 @@ describe('AlfrescoContentService', () => {
id: nodeId
}
})).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
'?attachment=false&alf_ticket=' + authService.getToken()
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
'?attachment=false&alf_ticket=' + authService.getTicket()
);
});
});

View File

@@ -37,11 +37,4 @@ describe('AlfrescoSettingsService', () => {
expect(service.host).toBe(address);
});
it('should format api url', () => {
let address = 'http://192.168.0.1';
let expectedUrl =
`${address}${AlfrescoSettingsService.DEFAULT_CONTEXT_PATH}${AlfrescoSettingsService.DEFAULT_BASE_API_PATH}`;
service.host = address;
expect(service.getApiBaseUrl()).toBe(expectedUrl);
});
});