From cb5f0a1c272a4d5a76f07ef64efb2612c2129586 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 16 Jun 2016 14:35:13 +0100 Subject: [PATCH] Fix 'core' tests --- .../ng2-alfresco-core/karma.conf.js | 2 +- .../src/assets/AlfrescoApi.mock.ts | 64 ------------------- ...rescoAuthenticationService.service.spec.ts | 25 ++++++-- 3 files changed, 21 insertions(+), 70 deletions(-) delete mode 100644 ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts diff --git a/ng2-components/ng2-alfresco-core/karma.conf.js b/ng2-components/ng2-alfresco-core/karma.conf.js index 719757138f..42269c9cd9 100644 --- a/ng2-components/ng2-alfresco-core/karma.conf.js +++ b/ng2-components/ng2-alfresco-core/karma.conf.js @@ -42,7 +42,7 @@ module.exports = function (config) { // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, diff --git a/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts b/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts deleted file mode 100644 index 8fbdd71af3..0000000000 --- a/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts +++ /dev/null @@ -1,64 +0,0 @@ -/*! - * @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 { - - static getClientWithTicket(basePath: string, ticket: string) { - return {}; - } - -} -export module AlfrescoApiMock { - - export module Auth { - - export class AuthenticationApi { - - constructor(alfrescoClient: any) { - } - - createTicket(loginRequest: any) { - if (loginRequest.userId === 'fake-username' && loginRequest.password === 'fake-password') { - return new Promise(function (resolve, reject) { - resolve({ - entry: { - userId: 'fake-username', - id: 'fake-post-token' - } - }); - }); - } else { - new Promise(function (resolve, reject) { - reject(); - }); - } - } - - deleteTicket(loginRequest: any) { - return new Promise(function (resolve, reject) { - resolve(); - }); - } - - } - - export class LoginRequest { - } - } -} - - diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts index 78237f0a91..154306a9ba 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts @@ -19,11 +19,9 @@ import { it, describe, beforeEach } from '@angular/core/testing'; import { ReflectiveInjector } from '@angular/core'; import { AlfrescoSettingsService } from './AlfrescoSettingsService.service'; import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service'; -import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock'; declare var AlfrescoApi: any; - describe('AlfrescoAuthentication', () => { let injector, service; @@ -53,7 +51,6 @@ describe('AlfrescoAuthentication', () => { return keys[i] || null; }); - window['AlfrescoApi'] = AlfrescoApiMock; service = injector.get(AlfrescoAuthenticationService); }); @@ -71,6 +68,17 @@ describe('AlfrescoAuthentication', () => { }); it('should return true and token on sign in', () => { + + let p = new Promise(function (resolve, reject) { + resolve({ + entry: { + userId: 'fake-username', + id: 'fake-post-token' + } + }); + }); + spyOn(service, 'getCreateTicketPromise').and.returnValue(p); + service.token = ''; service.login('fake-username', 'fake-password') .subscribe(() => { @@ -83,12 +91,19 @@ describe('AlfrescoAuthentication', () => { }); it('should return false and token undefined on log out', () => { + + let p = new Promise(function (resolve, reject) { + resolve(); + }); + + spyOn(service, 'getDeleteTicketPromise').and.returnValue(p); + localStorage.setItem('token', 'fake-token'); service.logout() .subscribe(() => { expect(service.isLoggedIn()).toBe(false); - expect(service.getToken()).toBe(null); - expect(localStorage.getItem('token')).toBe(null); + expect(service.getToken()).toBeUndefined(); + expect(localStorage.getItem('token')).toBeUndefined(); } ); });