From c2ce25b1cb408ea5aa2e7bd69a5d1d17fc1e62cf Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 16 Jun 2016 15:20:19 +0100 Subject: [PATCH] Unit tests for 'AlfrescoSettingsService' --- .../AlfrescoSettingsService.service.ts | 15 +++--- .../services/AlfrescoSettingsService.spec.ts | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts index 35a0e0a44d..563ecaaf68 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts @@ -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'); - } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts new file mode 100644 index 0000000000..bcc8dd5f0c --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts @@ -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); + }); +});