JSFiddle - React, Tailwind, and code Playground
by rakesh makluri
JavaScript
import { AuthenticationService } from "./authentication.service";
import { of } from "rxjs";
import { fakeAsync, tick } from "@angular/core/testing";
import { Constants } from "../mds-common/constants";
describe('Authentication Service', () => {
let authenticationService: AuthenticationService;
let httpClientSpy;
let router;
let utilsComponent;
beforeEach(() => {
httpClientSpy = jasmine.createSpyObj('UitkHttpService', ['get']);
router = jasmine.createSpyObj('Router', ['navigate']);
utilsComponent = jasmine.createSpyObj('UtilsComponent', ['getRequestedConfigInfo']);
// utilsComponent = new UtilsComponents();
authenticationService = new AuthenticationService(<any> httpClientSpy, <any> router, utilsComponent);
});
it('should do authorizationTokenExchange', fakeAsync(() => {
const jsonResponseObj: any = {
msid: '123',
firstName: 'FN',
lastName: 'LN',
expires: '20-11-2018',
idToken: 'test token',
email: '[email protected]',
mdr_access: true
};
httpClientSpy.get.and.returnValue(of(jsonResponseObj));
authenticationService.authorizationTokenExchange('test token');
tick();
const storedObj = JSON.parse(window.localStorage.get(Constants.CURRENT_USER));
expect(storedObj.msid).toEqual(jsonResponseObj.msid);
expect(storedObj.first_name).toEqual(jsonResponseObj.firstName);
expect(storedObj.last_name).toEqual(jsonResponseObj.lastName);
expect(storedObj.expiration).toEqual(jsonResponseObj.expires);
expect(storedObj.email).toEqual(jsonResponseObj.email);
expect(router.navigate).toHaveBeenCalled();
}));
it('should test isAccessMDRandRoles method', () => {
const jsonResponseObj: any = {
msid: '123',
firstName: 'FN',
lastName: 'LN',
expires: '20-11-2018',
...