-
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.
Escaping names passed to Overpass (#2074)
* Escaping names passed to Overpass Resolves #2073 * Add tests for relevant scenario * Fix lint, improve coverage --------- Co-authored-by: HarelM <[email protected]>
- Loading branch information
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
import { inject, TestBed } from "@angular/core/testing"; | ||
import { provideHttpClient, withInterceptorsFromDi } from "@angular/common/http"; | ||
import { HttpTestingController, provideHttpClientTesting } from "@angular/common/http/testing"; | ||
import { OverpassTurboService } from "./overpass-turbo.service"; | ||
|
||
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 mtb way by name", inject([OverpassTurboService, HttpTestingController], async (service: OverpassTurboService, mockBackend: HttpTestingController) => { | ||
// Arrange | ||
const response = "<osm></osm>"; | ||
// Act | ||
const promise = service.getLongWay("id", "aaa", false, true); | ||
|
||
mockBackend.expectOne(u => u.body.includes("mtb:name")).flush(response); | ||
// Assert | ||
const results = await promise; | ||
expect(results.features.length).toBe(0); | ||
})); | ||
|
||
it("Should get a long waterway way by name", inject([OverpassTurboService, HttpTestingController], async (service: OverpassTurboService, mockBackend: HttpTestingController) => { | ||
// Arrange | ||
const response = "<osm></osm>"; | ||
// Act | ||
const promise = service.getLongWay("id", "aaa", true, false); | ||
|
||
mockBackend.expectOne(u => u.body.includes("waterway")).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); | ||
})); | ||
}); |
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