@@ -17,12 +17,21 @@ vi.mock("./store-helpers/persist-options", async () => {
1717const host = "test.com" ;
1818const base = `https://${ host } ` ;
1919const POST = "POST" ;
20+ const testKey = "test" ;
21+ const testStrObj = { [ testKey ] : "string" } ;
22+ const contentStrTest = JSON . stringify ( testStrObj ) ;
23+ const testIntObj = { [ testKey ] : 1 } ;
24+ const contentIntTest = JSON . stringify ( testIntObj ) ;
25+ const testNullObj = { [ testKey ] : null } ;
26+ const contentNullTest = JSON . stringify ( testNullObj ) ;
27+ const testBoolObj = { [ testKey ] : true } ;
28+ const contentBoolTest = JSON . stringify ( testBoolObj ) ;
2029
2130const getResBodyJSONTypes = (
2231 store : RequestStore ,
2332 host : string ,
2433 path : string ,
25- propName = "foo" ,
34+ propName = testKey
2635) => {
2736 const match = store . get ( ) [ host ] ?. lookup ( path ) ;
2837 if ( ! match ) throw new Error ( "Could not match path" ) ;
@@ -37,10 +46,10 @@ it("parameterises and merges paths", () => {
3746 const req1 = createSimpleRequest ( `${ base } /1/2/a` ) ;
3847 const req2 = createSimpleRequest ( `${ base } /1/2/b` ) ;
3948 const req3 = createSimpleRequest ( `${ base } /1/2/c` ) ;
40- store . insert ( req1 , { foo : "bar" } ) ;
41- store . insert ( req2 , { foo : 1 } ) ;
49+ store . insert ( req1 , contentStrTest ) ;
50+ store . insert ( req2 , contentIntTest ) ;
4251 store . parameterise ( 2 , "/1/2/a" , host ) ;
43- store . insert ( req3 , { foo : null } ) ;
52+ store . insert ( req3 , contentNullTest ) ;
4453 store . parameterise ( 1 , "/1/2/:param2" , host ) ;
4554 const properties = getResBodyJSONTypes ( store , host , "/1/zzz/asbds" ) ;
4655 expect ( properties ) . toContain ( "string" ) ;
@@ -52,7 +61,7 @@ it("parameterises and merges paths", () => {
5261it ( "inserts data and can retrieve it" , ( ) => {
5362 const store = new RequestStore ( ) ;
5463 const req = createSimpleRequest ( `${ base } /1/2/a` ) ;
55- store . insert ( req , { foo : 1 } ) ;
64+ store . insert ( req , contentIntTest ) ;
5665 const properties = getResBodyJSONTypes ( store , host , "/1/2/a" ) ;
5766 expect ( properties ) . toBe ( "integer" ) ;
5867} ) ;
@@ -65,14 +74,14 @@ it("sets leafMap correctly after multiple add and parameterise operations", () =
6574 const req4 = createSimpleRequest ( `${ base } /1/2/c` ) ;
6675 const req5 = createSimpleRequest ( `${ base } /dynamicPath/2/a` ) ;
6776 const req6 = createSimpleRequest ( `${ base } /dynamicPath/2/b` ) ;
68- store . insert ( req1 , { foo : "bar" } ) ;
69- store . insert ( req2 , { foo : "bar" } ) ;
70- store . insert ( req3 , { foo : 1 } ) ;
77+ store . insert ( req1 , contentStrTest ) ;
78+ store . insert ( req2 , contentStrTest ) ;
79+ store . insert ( req3 , contentIntTest ) ;
7180 store . parameterise ( 2 , "/1/2/a" , host ) ;
72- store . insert ( req4 , { foo : null } ) ;
81+ store . insert ( req4 , contentNullTest ) ;
7382 store . parameterise ( 1 , "/1/2/:param2" , host ) ;
74- store . insert ( req5 , { foo : "bar" } ) ;
75- store . insert ( req6 , { foo : 1 } ) ;
83+ store . insert ( req5 , contentStrTest ) ;
84+ store . insert ( req6 , contentIntTest ) ;
7685 store . parameterise ( 2 , "/dynamicPath/2/b" , host ) ;
7786 store . parameterise ( 1 , "/dynamicPath/2/:param2" , host ) ;
7887 const expected = {
@@ -94,7 +103,7 @@ it("sets leafMap correctly after multiple add and parameterise operations", () =
94103 "string" ,
95104 ] ) ;
96105 expect ( getResBodyJSONTypes ( store , host , "/staticPath/2/3/4/5" ) ) . toBe (
97- "string" ,
106+ "string"
98107 ) ;
99108} ) ;
100109
@@ -104,10 +113,10 @@ it("sets leafMap correctly after many parameterise operations", () => {
104113 const req2 = createSimpleRequest ( `${ base } /1/2/3/z/b` ) ;
105114 const req3 = createSimpleRequest ( `${ base } /1/x/y/z/b` ) ;
106115 const req4 = createSimpleRequest ( `${ base } /1/2/b` ) ;
107- store . insert ( req1 , { foo : "bar" } ) ;
108- store . insert ( req2 , { foo : null } ) ;
109- store . insert ( req3 , { foo : 1 } ) ;
110- store . insert ( req4 , { foo : true } ) ;
116+ store . insert ( req1 , contentStrTest ) ;
117+ store . insert ( req2 , contentNullTest ) ;
118+ store . insert ( req3 , contentIntTest ) ;
119+ store . insert ( req4 , contentBoolTest ) ;
111120 store . parameterise ( 4 , "/1/2/3/4/a" , host ) ;
112121 store . parameterise ( 3 , "/1/x/y/z/b" , host ) ;
113122 store . parameterise ( 3 , "/1/2/3/4/:param4" , host ) ;
@@ -133,9 +142,9 @@ it("collapses into a single route when paramaterised", () => {
133142 const req1 = createSimpleRequest ( `${ base } /1/2/3/4/a` ) ;
134143 const req2 = createSimpleRequest ( `${ base } /1/2/3/4/b` ) ;
135144 const req3 = createSimpleRequest ( `${ base } /1/2/3/4/c` ) ;
136- store . insert ( req1 , { foo : "bar" } ) ;
137- store . insert ( req2 , { foo : null } ) ;
138- store . insert ( req3 , { foo : 1 } ) ;
145+ store . insert ( req1 , contentStrTest ) ;
146+ store . insert ( req2 , contentNullTest ) ;
147+ store . insert ( req3 , contentIntTest ) ;
139148 store . parameterise ( 3 , "/1/2/3/4/a" , host ) ;
140149 store . parameterise ( 4 , "/1/2/3/:param3/a" , host ) ;
141150 const expected = {
@@ -156,8 +165,8 @@ it("can parameterise paths that are subsets of another path", () => {
156165 const store = new RequestStore ( ) ;
157166 const req1 = createSimpleRequest ( `${ base } /1/2/a` ) ;
158167 const req2 = createSimpleRequest ( `${ base } /1/2` ) ;
159- store . insert ( req1 , { foo : "bar" } ) ;
160- store . insert ( req2 , { foo : 1 } ) ;
168+ store . insert ( req1 , contentStrTest ) ;
169+ store . insert ( req2 , contentIntTest ) ;
161170 store . parameterise ( 1 , "/1/2" , host ) ;
162171 const expected = {
163172 [ host ] : {
@@ -177,10 +186,10 @@ it("can parameterise paths that exist along the same segment", () => {
177186 const req2 = createSimpleRequest ( `${ base } /1/2` ) ;
178187 const req3 = createSimpleRequest ( `${ base } /1` ) ;
179188 const req4 = createSimpleRequest ( `${ base } /1/2/3/4` ) ;
180- store . insert ( req1 , { foo : "bar" } ) ;
181- store . insert ( req2 , { foo : 1 } ) ;
182- store . insert ( req3 , { foo : null } ) ;
183- store . insert ( req4 , { foo : null } ) ;
189+ store . insert ( req1 , contentStrTest ) ;
190+ store . insert ( req2 , contentIntTest ) ;
191+ store . insert ( req3 , contentNullTest ) ;
192+ store . insert ( req4 , contentNullTest ) ;
184193 store . parameterise ( 1 , "/1/2/a" , host ) ;
185194 // Bug happens below. When /1/2 is parameterised, router.remove removes /1/2/3/4
186195 store . parameterise ( 1 , "/1/2" , host ) ;
@@ -202,11 +211,11 @@ it("parameterising a path catches future requests to the same path", () => {
202211 const store = new RequestStore ( ) ;
203212 const req1 = createSimpleRequest ( `${ base } /1/2/a` ) ;
204213 const req2 = createSimpleRequest ( `${ base } /1/2/b` ) ;
205- store . insert ( req1 , { foo : "bar" } ) ;
206- store . insert ( req2 , { foo : "bar" } ) ;
214+ store . insert ( req1 , contentStrTest ) ;
215+ store . insert ( req2 , contentStrTest ) ;
207216 store . parameterise ( 1 , "/1/2/a" , host ) ;
208- store . insert ( req1 , { foo : 1 } ) ;
209- store . insert ( req2 , { foo : 1 } ) ;
217+ store . insert ( req1 , contentIntTest ) ;
218+ store . insert ( req2 , contentIntTest ) ;
210219 const expected = {
211220 [ host ] : {
212221 "/1/:param1/a" : expect . any ( Object ) ,
@@ -222,12 +231,12 @@ it("parameterisation works after export and import", () => {
222231 const req = createSimpleRequest ( `${ base } /1/2/a` ) ;
223232 const options = { enableMoreInfo : true } ;
224233 store . options ( options ) ;
225- store . insert ( req , { foo : 1 } ) ;
234+ store . insert ( req , contentIntTest ) ;
226235 store . parameterise ( 2 , "/1/2/a" , host ) ;
227236 const exported = store . export ( ) ;
228237 store . clear ( ) ;
229238 store . import ( exported ) ;
230- store . insert ( req , { foo : 1 } ) ;
239+ store . insert ( req , contentIntTest ) ;
231240 const expectedLeafMap = {
232241 [ host ] : {
233242 "/1/2/:param2" : expect . any ( Object ) ,
0 commit comments