1
- import { relativeRoot } from "../../../src/node/http"
1
+ import { getMockReq } from "@jest-mock/express"
2
+ import { constructRedirectPath , relativeRoot } from "../../../src/node/http"
2
3
3
4
describe ( "http" , ( ) => {
4
5
it ( "should construct a relative path to the root" , ( ) => {
@@ -9,3 +10,46 @@ describe("http", () => {
9
10
expect ( relativeRoot ( "/foo/bar/" ) ) . toStrictEqual ( "./../.." )
10
11
} )
11
12
} )
13
+
14
+ describe ( "constructRedirectPath" , ( ) => {
15
+ it ( "should preserve slashes in queryString so they are human-readable" , ( ) => {
16
+ const mockReq = getMockReq ( {
17
+ originalUrl : "localhost:8080" ,
18
+ } )
19
+ const mockQueryParams = { folder : "/Users/jp/dev/coder" }
20
+ const mockTo = ""
21
+ const actual = constructRedirectPath ( mockReq , mockQueryParams , mockTo )
22
+ const expected = "./?folder=/Users/jp/dev/coder"
23
+ expect ( actual ) . toBe ( expected )
24
+ } )
25
+ it ( "should use an empty string if no query params" , ( ) => {
26
+ const mockReq = getMockReq ( {
27
+ originalUrl : "localhost:8080" ,
28
+ } )
29
+ const mockQueryParams = { }
30
+ const mockTo = ""
31
+ const actual = constructRedirectPath ( mockReq , mockQueryParams , mockTo )
32
+ const expected = "./"
33
+ expect ( actual ) . toBe ( expected )
34
+ } )
35
+ it ( "should append the 'to' path relative to the originalUrl" , ( ) => {
36
+ const mockReq = getMockReq ( {
37
+ originalUrl : "localhost:8080" ,
38
+ } )
39
+ const mockQueryParams = { }
40
+ const mockTo = "vscode"
41
+ const actual = constructRedirectPath ( mockReq , mockQueryParams , mockTo )
42
+ const expected = "./vscode"
43
+ expect ( actual ) . toBe ( expected )
44
+ } )
45
+ it ( "should append append queryParams after 'to' path" , ( ) => {
46
+ const mockReq = getMockReq ( {
47
+ originalUrl : "localhost:8080" ,
48
+ } )
49
+ const mockQueryParams = { folder : "/Users/jp/dev/coder" }
50
+ const mockTo = "vscode"
51
+ const actual = constructRedirectPath ( mockReq , mockQueryParams , mockTo )
52
+ const expected = "./vscode?folder=/Users/jp/dev/coder"
53
+ expect ( actual ) . toBe ( expected )
54
+ } )
55
+ } )
0 commit comments