@@ -720,6 +720,7 @@ describe('HTTP APIs', function () {
720720 } )
721721
722722 describe ( 'POST API' , function ( ) {
723+ let postLocation
723724 before ( function ( ) {
724725 // Ensure all these are finished before running tests
725726 return Promise . all ( [
@@ -738,6 +739,12 @@ describe('HTTP APIs', function () {
738739 '../resources/sampleContainer/post2.ttl' ) , {
739740 encoding : 'utf8'
740741 } )
742+ // Capture the resource name generated by server by parsing Location: header
743+ let postedResourceName
744+ const getResourceName = function ( res ) {
745+ postedResourceName = res . header . location
746+ }
747+
741748 it ( 'should create new document resource' , function ( done ) {
742749 server . post ( '/post-tests/' )
743750 . send ( postRequest1Body )
@@ -763,7 +770,24 @@ describe('HTTP APIs', function () {
763770 . set ( 'slug' , 'put-resource' )
764771 . set ( 'link' , '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' )
765772 . send ( postRequest2Body )
766- . expect ( 201 , done )
773+ . expect ( 201 )
774+ . end ( ( err , res ) => {
775+ if ( err ) return done ( err )
776+ try {
777+ postLocation = res . headers . location
778+ console . log ( 'location ' + postLocation )
779+ const createdDir = fs . statSync ( path . join ( __dirname , '../resources' , postLocation . slice ( 0 , - 1 ) ) )
780+ assert ( createdDir . isDirectory ( ) , 'Container should have been created' )
781+ } catch ( err ) {
782+ return done ( err )
783+ }
784+ done ( )
785+ } )
786+ } )
787+ it ( 'should get newly created container with new slug' , function ( done ) {
788+ console . log ( 'location' + postLocation )
789+ server . get ( postLocation )
790+ . expect ( 200 , done )
767791 } )
768792 it ( 'should error with 403 if auxiliary resource file.acl' , function ( done ) {
769793 server . post ( '/post-tests/' )
@@ -821,11 +845,6 @@ describe('HTTP APIs', function () {
821845 server . delete ( '/post-tests/post-resource-1.ttl' )
822846 . expect ( 200 , done )
823847 } )
824- // Capture the resource name generated by server by parsing Location: header
825- let postedResourceName
826- const getResourceName = function ( res ) {
827- postedResourceName = res . header . location
828- }
829848 it ( 'should create new resource without slug header' , function ( done ) {
830849 server . post ( '/post-tests/' )
831850 . send ( postRequest1Body )
@@ -864,9 +883,15 @@ describe('HTTP APIs', function () {
864883 server . post ( '/post-tests/' )
865884 . send ( postRequest1Body )
866885 . set ( 'content-type' , 'text/turtle' )
867- . set ( 'slug' , 'loans' )
868- . set ( 'link' , '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' )
869- . expect ( 201 , done )
886+ . set ( 'slug' , 'loans.ttl' )
887+ . expect ( 201 )
888+ . expect ( getResourceName )
889+ . end ( done )
890+ } )
891+ it ( 'should get newly created document resource with new slug' , function ( done ) {
892+ console . log ( postedResourceName )
893+ server . get ( postedResourceName )
894+ . expect ( 200 , done )
870895 } )
871896 it ( 'should create a container with a name hex decoded from the slug' , ( done ) => {
872897 const containerName = 'Film%4011'
0 commit comments