@@ -8,13 +8,17 @@ import { describe, expect, test } from "@jest/globals";
8
8
import { CongestionSvc } from "./congestion" ;
9
9
import { initDB } from "../clients/db" ;
10
10
import { RoutingSvcFactory } from "../factories/routing" ;
11
+ import { NotFoundError , ValidationError } from "../error" ;
11
12
12
13
describe ( "RoutingSvc" , ( ) => {
13
14
const congestionSvc = new CongestionSvc ( initDB ( ) ) ;
14
15
// test routing with and without congestion routing
15
- const routingSvc = RoutingSvcFactory . create ( congestionSvc ) ;
16
+ const routingSvcs = [
17
+ RoutingSvcFactory . create ( congestionSvc ) ,
18
+ // RoutingSvcFactory.create(),
19
+ ] ;
16
20
17
- test ( "route() returns routes" , async ( ) => {
21
+ test . each ( routingSvcs ) ( "route() returns routes" , async ( routingSvc ) => {
18
22
const routes = await routingSvc . route (
19
23
// NTU nanyang circle
20
24
{
@@ -30,9 +34,48 @@ describe("RoutingSvc", () => {
30
34
expect ( routes . length ) . toBeGreaterThan ( 0 ) ;
31
35
} ) ;
32
36
37
+ test . each ( routingSvcs ) (
38
+ "route() throws NotFoundError on no route" ,
39
+ async ( routingSvc ) => {
40
+ expect (
41
+ routingSvc . route (
42
+ // NTU nanyang circle
43
+ {
44
+ longitude : 103.6849923 ,
45
+ latitude : 1.3437504 ,
46
+ } ,
47
+ {
48
+ longitude : 0 ,
49
+ latitude : 0 ,
50
+ } ,
51
+ ) ,
52
+ ) . rejects . toThrowError ( NotFoundError ) ;
53
+ } ,
54
+ ) ;
55
+
56
+ test . each ( routingSvcs ) (
57
+ "route() throws ValidationError on bad coordinate" ,
58
+ async ( routingSvc ) => {
59
+ expect (
60
+ routingSvc . route (
61
+ // NTU nanyang circle
62
+ {
63
+ longitude : 103.6849923 ,
64
+ latitude : 1.3437504 ,
65
+ } ,
66
+ // changi airport (invalid latitude)
67
+ {
68
+ longitude : 103.98847034565972 ,
69
+ latitude : - 91.0 ,
70
+ } ,
71
+ ) ,
72
+ ) . rejects . toThrowError ( ValidationError ) ;
73
+ } ,
74
+ ) ;
75
+
33
76
test ( "geolookup() returns correct GeoLocation for a given postcode" , async ( ) => {
34
77
const postcode = "639798" ; // Example postcode for NTU area
35
- const location = await routingSvc . geolookup ( postcode ) ;
78
+ const location = await routingSvcs [ 0 ] . geolookup ( postcode ) ;
36
79
37
80
expect ( location ) . toBeDefined ( ) ;
38
81
expect ( location . latitude ) . toBeCloseTo ( 1.3437504 , 2 ) ;
@@ -42,7 +85,7 @@ describe("RoutingSvc", () => {
42
85
test ( "geolookup() throws an error for invalid postcode" , async ( ) => {
43
86
const invalidPostcode = "000000" ; // Example of an invalid postcode
44
87
45
- await expect ( routingSvc . geolookup ( invalidPostcode ) ) . rejects . toThrow (
88
+ await expect ( routingSvcs [ 0 ] . geolookup ( invalidPostcode ) ) . rejects . toThrow (
46
89
`No location found for postcode: ${ invalidPostcode } ` ,
47
90
) ;
48
91
} ) ;
0 commit comments