@@ -55,75 +55,81 @@ async function getConfig(scheme){
5555
5656async function run ( scheme ) {
5757
58+
5859 [ tests , fails , passes ] = [ 0 , 0 , 0 ]
5960 let cfg = await getConfig ( scheme )
61+ let res
6062
61- if ( scheme === "app:" ) await postFolder ( "app://ls/" , "test-folder" )
63+ /* CREATE TEST FOLDER ON APP */
64+ if ( scheme === "app:" ) {
65+ res = await postFolder ( "app://ls/" , "test-folder" )
66+ cfg . base += "/" ;
67+ }
6268
6369 console . log ( `\nTesting ${ cfg . base } ...` )
6470
6571 res = await postFolder ( cfg . base , cfg . c1name )
66- ok ( "400 post container with trailing slash on slug" , res . status == 400 )
72+ ok ( "400 post container with trailing slash on slug" , res . status == 400 , res )
6773
6874 cfg . c1name = cfg . c1name . replace ( / \/ $ / , '' )
6975
7076 res = await postFolder ( cfg . base , cfg . c1name )
71- ok ( "201 post container" , res . status == 201 )
77+ ok ( "201 post container" , res . status == 201 , res )
7278
7379 res = await postFolder ( cfg . base , cfg . c1name )
74- ok ( "201 post container, container found" , res . status == 201 )
80+ ok ( "201 post container, container found" , res . status == 201 , res )
7581
7682 res = await postFolder ( cfg . missingFolder , cfg . c2name )
77- ok ( "404 post container, parent not found" , res . status == 404 )
83+ ok ( "404 post container, parent not found" , res . status == 404 , res )
7884
7985 res = await postFile ( cfg . folder1 , cfg . r1name , cfg . text )
80- ok ( "201 post resource" , res . status == 201 )
86+ ok ( "201 post resource" , res . status == 201 , res )
8187
8288 res = await postFile ( cfg . folder1 , cfg . r1name , cfg . txt )
83- ok ( "201 post resource, resource found" , res . status == 201 )
89+ ok ( "201 post resource, resource found" , res . status == 201 , res )
8490
8591 res = await postFile ( cfg . missingFolder , cfg . file2 )
86- ok ( "404 post resource, parent not found" , res . status == 404 )
92+ ok ( "404 post resource, parent not found" , res . status == 404 , res )
8793
8894 res = await PUT ( cfg . folder1 )
89- ok ( "409 put container (method not allowed)" , res . status == 409 )
95+ ok ( "409 put container (method not allowed)" , res . status == 409 , res )
9096
9197 res = await PUT ( cfg . file1 , cfg . text )
92- ok ( "201 put resource" , res . status == 201 )
98+ ok ( "201 put resource" , res . status == 201 , res )
9399
94100 res = await PUT ( cfg . file1 , cfg . text )
95- ok ( "201 put resource, resource found" , res . status == 201 )
101+ ok ( "201 put resource, resource found" , res . status == 201 , res )
96102
97103 res = await PUT ( cfg . deepR , cfg . text )
98104 ok ( "201 put resource, parent not found (recursive creation)" , res . status == 201 )
99105
100106 res = await HEAD ( cfg . deepR )
101- ok ( "200 head" , res . status == 200 && res . headers . get ( "allow" ) )
107+ ok ( "200 head" , res . status == 200 && res . headers . get ( "allow" ) , res )
102108
103109 res = await HEAD ( cfg . missingFolder )
104- ok ( "404 head resource, not found" , res . status == 404 )
110+ ok ( "404 head resource, not found" , res . status == 404 , res )
105111
106112 res = await GET ( cfg . missingFolder )
107- ok ( "404 get container, not found" , res . status == 404 )
113+ ok ( "404 get container, not found" , res . status == 404 , res )
108114
109115 res = await GET ( cfg . file1 )
110116 ok ( "200 get resource" , res . status == 200 && await res . text ( ) === cfg . text )
111117
112118 res = await GET ( cfg . folder1 )
113119 let type = res . headers . get ( "content-type" )
114- ok ( "200 get container" , res . status == 200 && type === "text/turtle" )
120+ ok ( "200 get container" , res . status == 200 && type === "text/turtle" , res )
115121
116122 res = await DELETE ( cfg . folder1 )
117- ok ( "409 delete container, not empty" , res . status == 409 )
123+ ok ( "409 delete container, not empty" , res . status == 409 , res )
118124
119125 res = await DELETE ( cfg . file1 )
120126 res = await DELETE ( cfg . deepR )
121- ok ( "200 delete resource" , res . status == 200 )
127+ ok ( "200 delete resource" , res . status == 200 , res )
122128
123129 if ( scheme != "https:" ) {
124130 res = await DELETE ( cfg . folder2 )
125131 res = await DELETE ( cfg . folder1 )
126- ok ( "200 delete container" , res . status == 200 )
132+ ok ( "200 delete container" , res . status == 200 , res )
127133 }
128134
129135 console . log ( `${ passes } /${ tests } tests passed, ${ fails } failed\n` )
@@ -139,15 +145,15 @@ async function HEAD(url){
139145 return await fetch ( url , { method :"HEAD" } )
140146}
141147async function PUT ( url , text ) {
142- return await fetch ( url , { method :"PUT" , body :text } )
148+ return await fetch ( url , { method :"PUT" , body :text , headers : { "content-type" : "text/turtle" } } )
143149}
144150async function DELETE ( url ) {
145151 return await fetch ( url , { method :"DELETE" } )
146152}
147153async function POST ( parent , item , content , link ) {
148154 return await fetch ( parent , {
149155 method :"POST" ,
150- headers :{ slug :item , link :link } ,
156+ headers :{ slug :item , link :link , "content-type" : "text/turtle" } ,
151157 body :content
152158 } )
153159}
@@ -162,12 +168,13 @@ async function postFolder(parent,folder){
162168
163169/* ============================================== */
164170
165- function ok ( label , success ) {
171+ function ok ( label , success , res ) {
166172 tests = tests + 1 ;
167173 if ( success ) passes = passes + 1
168174 else fails = fails + 1
169175 let msg = success ? "ok " : "FAIL "
170176 console . log ( " " + msg + label )
177+ if ( ! success && res ) console . log ( res . status , res . statusText )
171178 return success
172179}
173180
0 commit comments