Skip to content

Commit

Permalink
Add tests for relevant scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Nov 13, 2024
1 parent 3c94252 commit b53a3e4
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { inject, TestBed } from "@angular/core/testing";
import { HttpClient, provideHttpClient, withInterceptorsFromDi } from "@angular/common/http";

Check failure on line 2 in IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts

View workflow job for this annotation

GitHub Actions / backend-and-frontend-tests

'HttpClient' is defined but never used
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 = "<osm></osm>";
// 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 = "<osm></osm>";
// 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 = "<osm></osm>";
// 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);
}));
});

0 comments on commit b53a3e4

Please sign in to comment.