-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
IsraelHiking.Web/src/application/services/overpass-turbo.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
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); | ||
})); | ||
}); |