1+ // Integration tests for PATCH with application/sparql-update
2+
13var ldnode = require ( '../../index' )
24var supertest = require ( 'supertest' )
35var assert = require ( 'chai' ) . assert
@@ -6,10 +8,9 @@ var path = require('path')
68// Helper functions for the FS
79var rm = require ( '../test-utils' ) . rm
810var write = require ( '../test-utils' ) . write
9- // var cp = require('./test-utils').cp
1011var read = require ( '../test-utils' ) . read
1112
12- describe ( 'PATCH' , function ( ) {
13+ describe ( 'PATCH through application/sparql-update ' , function ( ) {
1314 // Starting LDP
1415 var ldp = ldnode ( {
1516 root : path . join ( __dirname , '../resources/sampleContainer' ) ,
@@ -18,52 +19,41 @@ describe('PATCH', function () {
1819 } )
1920 var server = supertest ( ldp )
2021
21- it . skip ( '.................. ', function ( done ) {
22+ it ( 'should create a new file if file does not exist ', function ( done ) {
2223 rm ( 'sampleContainer/notExisting.ttl' )
2324 server . patch ( '/notExisting.ttl' )
2425 . set ( 'content-type' , 'application/sparql-update' )
2526 . send ( 'INSERT DATA { :test :hello 456 .}' )
2627 . expect ( 200 )
2728 . end ( function ( err , res , body ) {
28- if ( err ) {
29- done ( err )
30- }
31- console . log ( '@@@@ ' + read ( 'sampleContainer/notExisting.ttl' ) )
3229 assert . equal (
33- read ( 'sampleContainer/notExisting.ttl' ) , ''
34- )
30+ read ( 'sampleContainer/notExisting.ttl' ) ,
31+ '@prefix : </notExisting.ttl#>.\n\n:test :hello 456 .\n\n' )
3532 rm ( 'sampleContainer/notExisting.ttl' )
3633 done ( err )
3734 } )
3835 } )
3936
4037 describe ( 'DELETE' , function ( ) {
41- it ( 'reproduce index 1 bug from pad' , function ( done ) {
42- var expected = `@prefix : </existingTriple.ttl#>.
43- @prefix dc: <http://purl.org/dc/elements/1.1/>.
44- @prefix c: <https://www.w3.org/People/Berners-Lee/card#>.
45- @prefix n: <http://rdfs.org/sioc/ns#>.
46- @prefix p: <http://www.w3.org/ns/pim/pad#>.
47- @prefix ic: <http://www.w3.org/2002/12/cal/ical#>.
48- @prefix XML: <http://www.w3.org/2001/XMLSchema#>.
49- @prefix flow: <http://www.w3.org/2005/01/wf/flow#>.
50- @prefix ui: <http://www.w3.org/ns/ui#>.
51- @prefix ind: </parent/index.ttl#>.
52- @prefix mee: <http://www.w3.org/ns/pim/meeting#>.
53-
54- :id1477502276660 dc:author c:i; n:content ""; p:next :this.
55-
56- :id1477522707481
57- ic:dtstart "2016-10-26T22:58:27Z"^^XML:dateTime;
58- flow:participant c:i;
59- ui:backgroundColor "#c1d0c8".
60- :this
61- a p:Notepad;
62- dc:author c:i;
63- dc:created "2016-10-25T15:44:42Z"^^XML:dateTime;
64- dc:title "Shared Notes";
65- p:next :id1477502276660.
66- ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
38+ it ( 'should be an empty resource if last triple is deleted' , function ( done ) {
39+ write (
40+ '<#current> <#temp> 123 .' ,
41+ 'sampleContainer/existingTriple.ttl' )
42+ server . post ( '/existingTriple.ttl' )
43+ . set ( 'content-type' , 'application/sparql-update' )
44+ . send ( 'DELETE { :current :temp 123 .}' )
45+ . expect ( 200 )
46+ . end ( function ( err , res , body ) {
47+ assert . equal (
48+ read ( 'sampleContainer/existingTriple.ttl' ) ,
49+ '@prefix : </existingTriple.ttl#>.\n\n' )
50+ rm ( 'sampleContainer/existingTriple.ttl' )
51+ done ( err )
52+ } )
53+ } )
54+
55+ it ( 'should delete a single triple from a pad document' , function ( done ) {
56+ var expected = '@prefix : </existingTriple.ttl#>.\n@prefix dc: <http://purl.org/dc/elements/1.1/>.\n@prefix c: <https://www.w3.org/People/Berners-Lee/card#>.\n@prefix n: <http://rdfs.org/sioc/ns#>.\n@prefix p: <http://www.w3.org/ns/pim/pad#>.\n@prefix ic: <http://www.w3.org/2002/12/cal/ical#>.\n@prefix XML: <http://www.w3.org/2001/XMLSchema#>.\n@prefix flow: <http://www.w3.org/2005/01/wf/flow#>.\n@prefix ui: <http://www.w3.org/ns/ui#>.\n@prefix ind: </parent/index.ttl#>.\n@prefix mee: <http://www.w3.org/ns/pim/meeting#>.\n\n:id1477502276660 dc:author c:i; n:content ""; p:next :this.\n\n:id1477522707481\n ic:dtstart "2016-10-26T22:58:27Z"^^XML:dateTime;\n flow:participant c:i;\n ui:backgroundColor "#c1d0c8".\n:this\n a p:Notepad;\n dc:author c:i;\n dc:created "2016-10-25T15:44:42Z"^^XML:dateTime;\n dc:title "Shared Notes";\n p:next :id1477502276660.\nind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n'
6757
6858 write ( `\n\
6959
@@ -114,7 +104,9 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
114104 } )
115105
116106 describe ( 'DELETE and INSERT' , function ( ) {
117- it ( 'should be update a resource using SPARQL-query using `prefix`' , function ( done ) {
107+ after ( ( ) => rm ( 'sampleContainer/prefixSparql.ttl' ) )
108+
109+ it ( 'should update a resource using SPARQL-query using `prefix`' , function ( done ) {
118110 write (
119111 '@prefix schema: <http://schema.org/> .\n' +
120112 '@prefix profile: <http://ogp.me/ns/profile#> .\n' +
@@ -134,11 +126,7 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
134126 . end ( function ( err , res , body ) {
135127 assert . equal (
136128 read ( 'sampleContainer/prefixSparql.ttl' ) ,
137- '@prefix : </prefixSparql.ttl#>.\n' +
138- '@prefix schema: <http://schema.org/>.\n' +
139- '@prefix pro: <http://ogp.me/ns/profile#>.\n\n' +
140- ': a schema:Person; pro:first_name "Timothy".\n\n' )
141- rm ( 'sampleContainer/prefixSparql.ttl' )
129+ '@prefix : </prefixSparql.ttl#>.\n@prefix schema: <http://schema.org/>.\n@prefix pro: <http://ogp.me/ns/profile#>.\n\n: a schema:Person; pro:first_name "Timothy".\n\n' )
142130 done ( err )
143131 } )
144132 } )
@@ -156,9 +144,7 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
156144 . end ( function ( err , res , body ) {
157145 assert . equal (
158146 read ( 'sampleContainer/addingTriple.ttl' ) ,
159- '@prefix : </addingTriple.ttl#>.\n\n' +
160- ':current :temp 123 .\n\n' +
161- ':test :hello 456 .\n\n' )
147+ '@prefix : </addingTriple.ttl#>.\n\n:current :temp 123 .\n\n:test :hello 456 .\n\n' )
162148 rm ( 'sampleContainer/addingTriple.ttl' )
163149 done ( err )
164150 } )
@@ -175,8 +161,7 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
175161 . end ( function ( err , res , body ) {
176162 assert . equal (
177163 read ( 'sampleContainer/addingTripleValue.ttl' ) ,
178- '@prefix : </addingTripleValue.ttl#>.\n\n' +
179- ':current :temp 123, 456 .\n\n' )
164+ '@prefix : </addingTripleValue.ttl#>.\n\n:current :temp 123, 456 .\n\n' )
180165 rm ( 'sampleContainer/addingTripleValue.ttl' )
181166 done ( err )
182167 } )
@@ -193,8 +178,7 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
193178 . end ( function ( err , res , body ) {
194179 assert . equal (
195180 read ( 'sampleContainer/addingTripleSubj.ttl' ) ,
196- '@prefix : </addingTripleSubj.ttl#>.\n\n' +
197- ':current :temp 123; :temp2 456 .\n\n' )
181+ '@prefix : </addingTripleSubj.ttl#>.\n\n:current :temp 123; :temp2 456 .\n\n' )
198182 rm ( 'sampleContainer/addingTripleSubj.ttl' )
199183 done ( err )
200184 } )
@@ -212,8 +196,7 @@ ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
212196 . end ( function ( err , res , body ) {
213197 assert . equal (
214198 read ( 'sampleContainer/emptyExample.ttl' ) ,
215- '@prefix : </emptyExample.ttl#>.\n\n' +
216- ':current :temp 123 .\n\n' )
199+ '@prefix : </emptyExample.ttl#>.\n\n:current :temp 123 .\n\n' )
217200 rm ( 'sampleContainer/emptyExample.ttl' )
218201 done ( err )
219202 } )
0 commit comments