Unit tests for 'AlfrescoSettingsService'

This commit is contained in:
Denys Vuika 2016-06-16 15:20:19 +01:00
parent cb5f0a1c27
commit c2ce25b1cb
2 changed files with 54 additions and 8 deletions

View File

@ -20,9 +20,13 @@ import { Injectable } from '@angular/core';
@Injectable()
export class AlfrescoSettingsService {
private _host: string = 'http://127.0.0.1:8080';
private _contextPath = '/alfresco';
private _apiBasePath: string = '/api/-default-/public/alfresco/versions/1';
static DEFAULT_HOST_ADDRESS: string = 'http://127.0.0.1:8080';
static DEFAULT_CONTEXT_PATH: string = '/alfresco';
static DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1';
private _host: string = AlfrescoSettingsService.DEFAULT_HOST_ADDRESS;
private _contextPath = AlfrescoSettingsService.DEFAULT_CONTEXT_PATH;
private _apiBasePath: string = AlfrescoSettingsService.DEFAULT_BASE_API_PATH;
public get host(): string {
return this._host;
@ -35,9 +39,4 @@ export class AlfrescoSettingsService {
getApiBaseUrl(): string {
return this._host + this._contextPath + this._apiBasePath;
}
getAuthToken(): string {
// todo: get proper token value
return 'Basic ' + btoa('admin:admin');
}
}

View File

@ -0,0 +1,47 @@
/*!
* @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.
*/
import { describe, it, beforeEach } from '@angular/core/testing';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
describe('AlfrescoSettingsService', () => {
let service: AlfrescoSettingsService;
beforeEach(() => {
service = new AlfrescoSettingsService();
});
it('should have default host', () => {
expect(service.host).toBe(AlfrescoSettingsService.DEFAULT_HOST_ADDRESS);
});
it('should change host', () => {
// this test ensures 'host' getter/setter working properly
let address = 'http://192.168.0.1';
service.host = address;
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);
});
});