Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {TestBed, inject, getTestBed} from '@angular/core/testing'; |
| 2 | |
| 3 | import { HealthStatusService } from './health-status.service'; |
| 4 | import {Constants} from "../../utils/constants"; |
| 5 | import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; |
| 6 | import {ExternalComponentStatus} from "../../models/externalComponentStatus"; |
| 7 | |
| 8 | describe('HealthStatusService', () => { |
| 9 | |
| 10 | let injector; |
| 11 | let service: HealthStatusService; |
| 12 | let httpMock: HttpTestingController; |
| 13 | |
| 14 | beforeEach(() => { |
| 15 | TestBed.configureTestingModule({ |
| 16 | imports: [HttpClientTestingModule], |
| 17 | providers: [HealthStatusService] |
| 18 | }); |
| 19 | |
| 20 | injector = getTestBed(); |
| 21 | service = injector.get(HealthStatusService); |
| 22 | httpMock = injector.get(HttpTestingController); |
| 23 | }); |
| 24 | |
| 25 | describe('#getProbe', () =>{ |
| 26 | it('when call probe, there is http GET with right url', () => { |
| 27 | |
| 28 | service.getProbe().subscribe((result: Array<ExternalComponentStatus>)=>{ |
| 29 | expect(result[0].component).toEqual("AAI"); |
| 30 | expect(result[0].available).toBeTruthy(); |
| 31 | expect(result[0].metadata).toEqual({ myKey: 'myValue' }); |
| 32 | |
| 33 | expect(result[1].component).toEqual("MSO"); |
| 34 | expect(result[1].available).toBeFalsy(); |
| 35 | expect(result[1].metadata).toEqual({otherKey: 123}); |
| 36 | }); |
| 37 | |
| 38 | const req = httpMock.expectOne(Constants.Path.SERVICES_PROBE_PATH); |
| 39 | expect(req.request.method).toEqual('GET'); |
| 40 | req.flush([ |
| 41 | { |
| 42 | "component": "AAI", |
| 43 | "available": true, |
| 44 | "metadata": { |
| 45 | "myKey": "myValue" |
| 46 | } |
| 47 | }, |
| 48 | { |
| 49 | "component": "MSO", |
| 50 | "available": false, |
| 51 | "metadata": { |
| 52 | "otherKey": 123 |
| 53 | } |
| 54 | }, |
| 55 | ]); |
| 56 | }); |
| 57 | |
| 58 | }); |
| 59 | |
| 60 | }); |