Fix 'core' tests

This commit is contained in:
Denys Vuika
2016-06-16 14:35:13 +01:00
parent 627f49bbf0
commit cb5f0a1c27
3 changed files with 21 additions and 70 deletions

View File

@@ -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,

View File

@@ -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 {
}
}
}

View File

@@ -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();
}
);
});