@@ -39,10 +39,13 @@ test("/health-check returns 200 with OK", async () => {
39
39
describe ( "/snapshot" , ( ) => {
40
40
const snapshotFirstPathComp = "snapshot" as const ;
41
41
for ( const [ name , path ] of [
42
- [ "valid with a one-level subdir" , "2024-01-01/a" ] ,
43
- [ "valid with a one-level subdir with a trailing slash" , "2024-01-01/a/" ] ,
44
- [ "valid with a two-level subdir" , "2024-01-01/a/b" ] ,
45
- [ "valid with a two-level subdir with a trailing slash" , "2024-01-01/a/b/" ] ,
42
+ [ "valid with a one-level subdir" , "2024-01-01/a/b" ] ,
43
+ [ "valid with a one-level subdir with a trailing slash" , "2024-02-02/a/b/" ] ,
44
+ [ "valid with a two-level subdir" , "2024-01-01/a/b/c" ] ,
45
+ [
46
+ "valid with a two-level subdir with a trailing slash" ,
47
+ "2024-03-03/a/b/c/" ,
48
+ ] ,
46
49
] as const ) {
47
50
test ( `Redirect with valid URL under /shapshot: ${ name } ` , async ( ) => {
48
51
const response = await fetch (
@@ -55,14 +58,33 @@ describe("/snapshot", () => {
55
58
expect ( response . status ) . toBe ( 301 ) ;
56
59
expect ( response . headers . get ( "location" ) ) . toBe (
57
60
delpaGitHubRawBaseUrl +
58
- " /melpa-snapshot-2024-01-01/ refs/heads/master/packages/" +
61
+ ` /melpa-snapshot-${ path . split ( "/" ) [ 0 ] } / refs/heads/master/packages/` +
59
62
path . slice (
60
63
path . indexOf ( "/" ) + 1 , // Remove the top-level folder in path
61
64
) ,
62
65
) ;
63
66
} ) ;
64
67
}
65
68
69
+ for ( const [ name , path ] of [
70
+ [ "without a trailing slash" , "2024-01-01" ] ,
71
+ [ "with a trailing slash" , "2024-02-02/" ] ,
72
+ ] as const ) {
73
+ test ( `Report OK with valid snapshot version at a root dir of /shapshot: ${ name } ` , async ( ) => {
74
+ const response = await fetch (
75
+ `${ hostAddress } /${ snapshotFirstPathComp } /${ path } ` ,
76
+ {
77
+ redirect : "manual" ,
78
+ } ,
79
+ ) ;
80
+
81
+ expect ( response . status ) . toBe ( 200 ) ;
82
+ const responseText = await response . text ( ) ;
83
+ expect ( responseText ) . toContain ( "valid snapshot version" ) ;
84
+ expect ( responseText ) . toContain ( path . split ( "/" ) [ 0 ] ) ;
85
+ } ) ;
86
+ }
87
+
66
88
for ( const [ name , path ] of [
67
89
[ "non-existing snapshot" , "2025-01-01" ] ,
68
90
[ "non-existing partially-matched snapshot" , "2024-01" ] ,
@@ -89,7 +111,11 @@ describe("/snapshot", () => {
89
111
90
112
expect ( response . status ) . toBe ( 404 ) ;
91
113
expect ( response . headers . get ( "content-type" ) ) . toContain ( "text/plain" ) ;
92
- expect ( await response . text ( ) ) . toBe ( "404 Not Found" ) ;
114
+ const responseText = await response . text ( ) ;
115
+ expect ( responseText ) . toContain ( "404 Not Found" ) ;
116
+ expect ( responseText ) . toContain (
117
+ `Invalid snapshot version: ${ path . split ( "/" ) [ 0 ] } ` ,
118
+ ) ;
93
119
} ) ;
94
120
}
95
121
} ) ;
0 commit comments