@@ -36,6 +36,69 @@ describe('ResourceMapper', () => {
3636 } ,
3737 { path : `${ rootPath } space/foo.exe$.html` } )
3838
39+ // GET/HEAD/POST/DELETE/PATCH base cases
40+
41+ itMapsUrl . skip ( mapper , 'a URL of a non-existing file' ,
42+ {
43+ url : 'http://localhost/space/foo.html' ,
44+ contentTypes : [ 'text/html' ]
45+ } ,
46+ [ /* no files */ ] ,
47+ new Error ( 'Not found' ) )
48+
49+ itMapsUrl ( mapper , 'a URL of an existing file with extension' ,
50+ {
51+ url : 'http://localhost/space/foo.html' ,
52+ contentTypes : [ 'text/html' ]
53+ } ,
54+ [
55+ `${ rootPath } space/foo.html`
56+ ] ,
57+ { path : `${ rootPath } space/foo.html` } )
58+
59+ itMapsUrl . skip ( mapper , 'an extensionless URL of an existing file' ,
60+ {
61+ url : 'http://localhost/space/foo' ,
62+ contentTypes : [ 'text/html' ]
63+ } ,
64+ [
65+ `${ rootPath } space/foo.html`
66+ ] ,
67+ { path : `${ rootPath } space/foo.html` } )
68+
69+ itMapsUrl . skip ( mapper , 'an extensionless URL of an existing file, with choices' ,
70+ {
71+ url : 'http://localhost/space/foo' ,
72+ contentTypes : [ 'text/html' , 'text/turtle' , 'image/png' ]
73+ } ,
74+ [
75+ `${ rootPath } space/foo.html` ,
76+ `${ rootPath } space/foo.ttl` ,
77+ `${ rootPath } space/foo.png`
78+ ] ,
79+ { path : `${ rootPath } space/foo.html` } )
80+
81+ itMapsUrl . skip ( mapper , 'an extensionless URL of an existing file, first choice not available' ,
82+ {
83+ url : 'http://localhost/space/foo' ,
84+ contentTypes : [ 'text/html' , 'text/turtle' , 'image/png' ]
85+ } ,
86+ [
87+ `${ rootPath } space/foo.ttl` ,
88+ `${ rootPath } space/foo.png`
89+ ] ,
90+ { path : `${ rootPath } space/foo.ttl` } )
91+
92+ itMapsUrl . skip ( mapper , 'an extensionless URL of an existing file, no choice available' ,
93+ {
94+ url : 'http://localhost/space/foo' ,
95+ contentTypes : [ 'text/html' , 'text/turtle' , 'image/png' ]
96+ } ,
97+ [
98+ `${ rootPath } space/foo.txt`
99+ ] ,
100+ new Error ( 'Not acceptable' ) )
101+
39102 // Security cases
40103
41104 itMapsUrl ( mapper , 'a URL with an unknown content type' ,
@@ -61,12 +124,20 @@ function asserter (assert) {
61124 return f
62125}
63126
64- function mapsUrl ( it , mapper , label , options , expected ) {
127+ function mapsUrl ( it , mapper , label , options , files , expected ) {
128+ // Shift parameters if necessary
129+ if ( ! expected ) {
130+ expected = files
131+ files = [ ]
132+ }
133+
134+ // Set up positive test
65135 if ( ! ( expected instanceof Error ) ) {
66136 it ( `maps ${ label } ` , async ( ) => {
67137 const actual = await mapper . mapUrlToFile ( options )
68138 expect ( actual ) . to . deep . equal ( expected )
69139 } )
140+ // Set up error test
70141 } else {
71142 it ( `does not map ${ label } ` , async ( ) => {
72143 const actual = mapper . mapUrlToFile ( options )
0 commit comments