From b53a3e428b29147f597bfe0465a0d0d101a95323 Mon Sep 17 00:00:00 2001 From: HarelM Date: Thu, 14 Nov 2024 00:00:01 +0200 Subject: [PATCH] Add tests for relevant scenario --- .../services/overpass-turbo.service.spec.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts diff --git a/IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts b/IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts new file mode 100644 index 00000000..dda584ce --- /dev/null +++ b/IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts @@ -0,0 +1,53 @@ +import { inject, TestBed } from "@angular/core/testing"; +import { HttpClient, provideHttpClient, withInterceptorsFromDi } from "@angular/common/http"; +import { OverpassTurboService } from "./overpass-turbo.service"; +import { HttpTestingController, provideHttpClientTesting } from "@angular/common/http/testing"; + +describe("OverpassTurboService", () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [], + providers: [ + OverpassTurboService, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] + }); + }); + + it("Should get a long way by name", inject([OverpassTurboService, HttpTestingController], async (service: OverpassTurboService, mockBackend: HttpTestingController) => { + // Arrange + const response = ""; + // Act + const promise = service.getLongWay("id", "name", false, false); + + mockBackend.expectOne("https://overpass-api.de/api/interpreter").flush(response); + // Assert + const results = await promise; + expect(results.features.length).toBe(0); + })); + + it("Should get a long way by name with '\"'", inject([OverpassTurboService, HttpTestingController], async (service: OverpassTurboService, mockBackend: HttpTestingController) => { + // Arrange + const response = ""; + // Act + const promise = service.getLongWay("id", "lalala\"", false, false); + + mockBackend.expectOne(u => u.body.includes("lalala\\\"")).flush(response); + // Assert + const results = await promise; + expect(results.features.length).toBe(0); + })); + + it("Should get a place by id", inject([OverpassTurboService, HttpTestingController], async (service: OverpassTurboService, mockBackend: HttpTestingController) => { + // Arrange + const response = ""; + // Act + const promise = service.getPlaceGeometry("42"); + + mockBackend.expectOne("https://overpass-api.de/api/interpreter").flush(response); + // Assert + const results = await promise; + expect(results.features.length).toBe(0); + })); +}); \ No newline at end of file