@@ -4,11 +4,13 @@ const { expect } = chai
44chai . use ( require ( 'chai-as-promised' ) )
55
66const itMapsUrl = asserter ( mapsUrl )
7+ const itMapsFile = asserter ( mapsFile )
78
89describe ( 'ResourceMapper' , ( ) => {
910 describe ( 'A ResourceMapper instance for a single-user setup' , ( ) => {
11+ const rootUrl = 'http://localhost/'
1012 const rootPath = '/var/www/folder/'
11- const mapper = new ResourceMapper ( { rootPath } )
13+ const mapper = new ResourceMapper ( { rootUrl , rootPath } )
1214
1315 // PUT base cases from https://www.w3.org/DesignIssues/HTTPFilenameMapping.html
1416
@@ -123,6 +125,50 @@ describe('ResourceMapper', () => {
123125 url : 'http://localhost/space/../bar'
124126 } ,
125127 new Error ( 'Disallowed /.. segment in URL' ) )
128+
129+ // File to URL mapping
130+
131+ itMapsFile ( mapper , 'an HTML file' ,
132+ { path : `${ rootPath } space/foo.html` } ,
133+ {
134+ url : 'http://localhost/space/foo.html' ,
135+ contentType : 'text/html'
136+ } )
137+
138+ itMapsFile ( mapper , 'a Turtle file' ,
139+ { path : `${ rootPath } space/foo.ttl` } ,
140+ {
141+ url : 'http://localhost/space/foo.ttl' ,
142+ contentType : 'text/turtle'
143+ } )
144+
145+ itMapsFile ( mapper , 'an unknown file type' ,
146+ { path : `${ rootPath } space/foo.bar` } ,
147+ {
148+ url : 'http://localhost/space/foo.bar' ,
149+ contentType : 'application/octet-stream'
150+ } )
151+
152+ itMapsFile ( mapper , 'an extensionless HTML file' ,
153+ { path : `${ rootPath } space/foo$.html` } ,
154+ {
155+ url : 'http://localhost/space/foo' ,
156+ contentType : 'text/html'
157+ } )
158+
159+ itMapsFile ( mapper , 'an extensionless Turtle file' ,
160+ { path : `${ rootPath } space/foo$.ttl` } ,
161+ {
162+ url : 'http://localhost/space/foo' ,
163+ contentType : 'text/turtle'
164+ } )
165+
166+ itMapsFile ( mapper , 'an extensionless unknown file type' ,
167+ { path : `${ rootPath } space/foo$.bar` } ,
168+ {
169+ url : 'http://localhost/space/foo' ,
170+ contentType : 'application/octet-stream'
171+ } )
126172 } )
127173} )
128174
@@ -154,3 +200,10 @@ function mapsUrl (it, mapper, label, options, files, expected) {
154200 } )
155201 }
156202}
203+
204+ function mapsFile ( it , mapper , label , options , expected ) {
205+ it ( `maps ${ label } ` , async ( ) => {
206+ const actual = await mapper . mapFileToUrl ( options )
207+ expect ( actual ) . to . deep . equal ( expected )
208+ } )
209+ }
0 commit comments