@@ -15,13 +15,11 @@ describe('HTTP APIs', function() {
1515 } ;
1616 var getLink = function ( res , rel ) {
1717 var links = res . headers . link . split ( ',' ) ;
18- for ( var linkIndex in links ) {
19- var link = links [ linkIndex ] ;
18+ for ( var i in links ) {
19+ var link = links [ i ] ;
2020 var parsedLink = li . parse ( link ) ;
21- for ( var linkRel in parsedLink ) {
22- if ( linkRel == rel ) {
23- return parsedLink [ rel ] ;
24- }
21+ if ( parsedLink [ rel ] ) {
22+ return parsedLink [ rel ] ;
2523 }
2624 }
2725 return undefined ;
@@ -31,23 +29,25 @@ describe('HTTP APIs', function() {
3129 var link = getLink ( res , rel ) ;
3230 if ( link ) {
3331 if ( link !== value ) {
34- console . log ( "Not same value" ) ;
32+ console . log ( "Not same value:" , value , '!=' , link ) ;
3533 }
3634 } else {
37- console . log ( "Header does not exist" ) ;
35+ console . log ( rel , "header does not exist:" , link ) ;
3836 }
3937 } ;
4038 return handler ;
4139 } ;
4240
4341 var address = 'http://localhost:3457' ;
44- var ldp = ldnode . createServer ( {
42+ var ldpServer = ldnode . createServer ( {
4543 root : __dirname + '/resources' ,
4644 } ) ;
47- ldp . listen ( 3457 ) ;
45+ ldpServer . listen ( 3457 ) ;
4846
49- var server = supertest ( address ) ;
47+ var suffixAcl = ".acl" ;
48+ var suffixMeta = ".meta" ;
5049
50+ var server = supertest ( address ) ;
5151
5252 describe ( 'GET Root container' , function ( ) {
5353 it ( 'should have Access-Control-Allow-Origin as the req.Origin' , function ( done ) {
@@ -89,6 +89,13 @@ describe('HTTP APIs', function() {
8989 . end ( done ) ;
9090 } ) ;
9191
92+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
93+ server . options ( '/sampleContainer/example1.ttl' )
94+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
95+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
96+ . end ( done ) ;
97+ } ) ;
98+
9299 it ( 'should have set Link as resource' , function ( done ) {
93100 server . options ( '/sampleContainer/example1.ttl' )
94101 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
@@ -103,15 +110,10 @@ describe('HTTP APIs', function() {
103110 . end ( done ) ;
104111 } ) ;
105112
106- it ( 'should have set meta Link in ' , function ( done ) {
113+ it ( 'should have set acl and describedBy Links for container ' , function ( done ) {
107114 server . options ( '/sampleContainer/' )
108- . expect ( hasHeader ( '\'describedBy\'' , address + '/sampleContainer/' + '.meta' ) )
109- . end ( done ) ;
110- } ) ;
111-
112- it ( 'should have set acl Link in' , function ( done ) {
113- server . options ( '/sampleContainer/' )
114- . expect ( hasHeader ( '\'acl\'' , address + '/sampleContainer/' + '.acl' ) )
115+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
116+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
115117 . end ( done ) ;
116118 } ) ;
117119 } ) ;
@@ -136,6 +138,12 @@ describe('HTTP APIs', function() {
136138 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
137139 . expect ( 200 , done ) ;
138140 } ) ;
141+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
142+ server . get ( '/sampleContainer/example1.ttl' )
143+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
144+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
145+ . end ( done ) ;
146+ } ) ;
139147
140148 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
141149 server . head ( '/sampleContainer/' )
@@ -162,15 +170,11 @@ describe('HTTP APIs', function() {
162170 . expect ( 'content-type' , / t e x t \/ t u r t l e / )
163171 . expect ( 200 , done ) ;
164172 } ) ;
165- it ( 'should have set meta Link' , function ( done ) {
166- server . get ( '/sampleContainer/' )
167- . expect ( hasHeader ( '\'describedBy\'' , address + '/sampleContainer/' + '.meta' ) )
168- . end ( done ) ;
169- } ) ;
170173
171- it ( 'should have set acl Link ' , function ( done ) {
174+ it ( 'should have set acl and describedBy Links for container ' , function ( done ) {
172175 server . get ( '/sampleContainer/' )
173- . expect ( hasHeader ( '\'acl\'' , address + '/sampleContainer/' + '.acl' ) )
176+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
177+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
174178 . end ( done ) ;
175179 } ) ;
176180 } ) ;
@@ -194,26 +198,26 @@ describe('HTTP APIs', function() {
194198 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
195199 . expect ( 200 , done ) ;
196200 } ) ;
201+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
202+ server . get ( '/sampleContainer/example1.ttl' )
203+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
204+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
205+ . end ( done ) ;
206+ } ) ;
197207
198208 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
199209 server . get ( '/sampleContainer/' )
200210 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # B a s i c C o n t a i n e r > ; r e l = " t y p e " / )
201- . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
211+ . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
202212 . expect ( 200 , done ) ;
203213 } ) ;
204214
205- it ( 'Should return meta header' , function ( done ) {
206- server . head ( '/' )
207- . expect ( hasHeader ( '\'describedBy\'' , address + '/' + '.meta' ) )
208- . expect ( 200 , done ) ;
209- } ) ;
210-
211- it ( 'Should return acl header' , function ( done ) {
212- server . head ( '/' )
213- . expect ( hasHeader ( '\'acl\'' , address + '/' + '.acl' ) )
214- . expect ( 200 , done ) ;
215+ it ( 'should have set acl and describedBy Links for container' , function ( done ) {
216+ server . get ( '/sampleContainer/' )
217+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
218+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
219+ . end ( done ) ;
215220 } ) ;
216-
217221 } ) ;
218222
219223 describe ( 'PUT API' , function ( ) {
@@ -230,8 +234,8 @@ describe('HTTP APIs', function() {
230234 server . put ( '/foo/bar/baz.ttl' )
231235 . send ( putRequestBody )
232236 . set ( 'content-type' , 'text/turtle' )
233- . expect ( hasHeader ( '\' describedBy\'' , address + '/sampleContainer/ ' + '.meta' ) )
234- . expect ( hasHeader ( '\' acl\'' , address + '/sampleContainer/ ' + '.acl' ) )
237+ . expect ( hasHeader ( 'describedBy' , 'baz.ttl ' + suffixMeta ) )
238+ . expect ( hasHeader ( 'acl' , 'baz.ttl ' + suffixAcl ) )
235239 . expect ( function ( ) {
236240 fs . unlinkSync ( __dirname + '/resources/foo/bar/baz.ttl' ) ;
237241 fs . rmdirSync ( __dirname + '/resources/foo/bar/' ) ;
@@ -270,8 +274,8 @@ describe('HTTP APIs', function() {
270274 . set ( 'content-type' , 'text/turtle' )
271275 . set ( 'slug' , 'post-resource-1' )
272276 . expect ( 'location' , address + '/post-resource-1.ttl' )
273- . expect ( hasHeader ( '\' describedBy\'' , address + '/post-resource-1.ttl' + '.meta' ) )
274- . expect ( hasHeader ( '\' acl\'' , address + '/post-resource-1.ttl' + '.acl' ) )
277+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
278+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
275279 . expect ( 201 , done ) ;
276280 } ) ;
277281 it ( 'Should reject requests to existing resources' , function ( done ) {
0 commit comments