blob: cd2f08923d0ee0f61894f80d5990bfb407c7b6a5 [file] [log] [blame]
/*
******************************************************************************
* Copyright © 2019 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { User } from '@shared/models/user';
import { ActivatedRoute } from '@angular/router';
import { Subject, Observable } from 'rxjs';
class FakeRouter {
public events = new Observable();
navigate(commands: any[]) {
return commands[0];
}
}
class FakeSandbox {
public user: User;
public setUser( user: User ) {
this.user = user;
}
public setupLanguage() {
}
}
describe('AppComponent', () => {
let component: AppComponent;
const fakeRouter: any = new FakeRouter();
const sandbox = new FakeSandbox();
const fakeRoute = new ActivatedRoute;
beforeEach(() => {
component = new AppComponent( fakeRouter, sandbox as any, fakeRoute );
});
it('should create the app', async(() => {
expect(component).toBeTruthy();
}));
it('ngOnInit works', () => {
fakeRoute.params = new Observable();
component.ngOnInit();
});
it('should extract the user data from the JWT-AccessToken', async(() => {
const accessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJodVl0e' +
'VByUEVLQ1phY3FfMW5sOGZscENETnFHdmZEZHctYUxGQXNoWHZVIn0.eyJqdGkiOiI4ZmY5NTlhZC' +
'02ODQ1LTRlOGEtYjRiYi02ODQ0YjAwMjU0ZjgiLCJleHAiOjE1MDY2MDA0NTAsIm5iZiI6MCwiaWF' +
'0IjoxNTA2NjAwMTUwLCJpc3MiOiJodHRwOi8vZW50amF2YTAwMjo4MDgwL2F1dGgvcmVhbG1zL2Vs' +
'b2dib29rIiwiYXVkIjoiZWxvZ2Jvb2stYmFja2VuZCIsInN1YiI6IjM1OWVmOWM5LTc3ZGYtNGEzZ' +
'C1hOWM5LWY5NmQ4MzdkMmQ1NyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImVsb2dib29rLWJhY2tlbm' +
'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Rbequnh8Z6wLXjcmQNLgrgknXB_gogWAqH29dqKexwceMNIbq-kjaeLsmHSXM9TE9' +
'q7_Ln9el04OlkpOVspVguedfINcNFg0DmYLJWyD2ORkOHLmYigN6YnyB9P2NFOnKGlLuQ87GjosI0' +
'0zBniRGi3PhE9NGd51Qggdbcsm0aM8GiMaZ7SO5i8iQWL10TRFRFyTEfy6hSO8g';
const incognito: any = component;
incognito._processAccessToken(accessToken);
expect(sandbox.user.name).toBe('Administrator Administratowich');
}));
it('read the param access token', () => {
const token = 'AJDHDND';
const uri = 'a=X&b=y&accessToken=' + token;
const inkognito: any = component;
const token2 = inkognito._readParamAccessToken(uri, 'accessToken');
expect(token2).toBe(token);
});
it('getParametersFromURL is entered', () => {
const inkognito: any = component;
const param1 = inkognito._getParametersFromUrl();
expect(param1).toBe(null);
});
});