| /* |
| ****************************************************************************** |
| * Copyright © 2018 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 { HttpClientModule, HttpXhrBackend } from '@angular/common/http'; |
| import { TestBed, async, inject } from '@angular/core/testing'; |
| import { MockBackend } from '@angular/http/testing'; |
| import 'rxjs/add/observable/of'; |
| import 'rxjs/add/operator/catch'; |
| import 'rxjs/add/operator/do'; |
| import 'rxjs/add/operator/toPromise'; |
| import { SessionContext } from '../common/session-context'; |
| import { BaseHttpService, HttpMethodEn } from '../services/base-http.service'; |
| import { AuthenticationService } from './authentication.service'; |
| import { MockBaseHttpService } from '../testing/mock-base-http.service'; |
| |
| describe('Http-AuthenticationService (mockBackend)', () => { |
| let sessionContext: SessionContext; |
| let mockedBaseHttpService: MockBaseHttpService; |
| |
| beforeEach(() => { |
| sessionContext = new SessionContext(); |
| mockedBaseHttpService = new MockBaseHttpService(); |
| |
| TestBed.configureTestingModule({ |
| imports: [HttpClientModule], |
| providers: [ |
| AuthenticationService, |
| { provide: SessionContext, useValue: sessionContext }, |
| { provide: BaseHttpService, useValue: mockedBaseHttpService } |
| ] |
| }) |
| .compileComponents(); |
| }); |
| |
| it('can instantiate service when inject service', |
| inject([AuthenticationService], (service: AuthenticationService) => { |
| expect(service instanceof AuthenticationService).toBe(true); |
| })); |
| |
| |
| it('should call logout', inject([AuthenticationService], (service: AuthenticationService) => { |
| expect(service).toBeTruthy(); |
| |
| service.logout(); |
| expect(mockedBaseHttpService.lastHttpCallInfo.method).toBe(HttpMethodEn.get); |
| expect(mockedBaseHttpService.lastHttpCallInfo.uriFragment).toContain('logout'); |
| })); |
| }); |