Skip to content

Commit 999bc76

Browse files
committed
modified route.test.ts
1 parent 6b11f1a commit 999bc76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

backend/services/routing.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { initDB } from "../clients/db";
1111

1212
describe("RoutingSvc", () => {
1313
const osrm = new RoutingSvc(ROUTING_API, fetch, new CongestionSvc(initDB()));
14+
1415
test("route() returns routes", async () => {
1516
const routes = await osrm.route(
1617
// NTU nanyang circle
@@ -26,4 +27,21 @@ describe("RoutingSvc", () => {
2627
);
2728
expect(routes.length).toBeGreaterThan(0);
2829
});
30+
31+
test("geolookup() returns correct GeoLocation for a given postcode", async () => {
32+
const postcode = "639798"; // Example postcode for NTU area
33+
const location = await osrm.geolookup(postcode);
34+
35+
expect(location).toBeDefined();
36+
expect(location.latitude).toBeCloseTo(1.3437504, 4);
37+
expect(location.longitude).toBeCloseTo(103.6849923, 4);
38+
});
39+
40+
test("geolookup() throws an error for invalid postcode", async () => {
41+
const invalidPostcode = "000000"; // Example of an invalid postcode
42+
43+
await expect(osrm.geolookup(invalidPostcode)).rejects.toThrow(
44+
`No location found for postcode: ${invalidPostcode}`
45+
);
46+
});
2947
});

0 commit comments

Comments
 (0)