mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Fix 'core' tests
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user