forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-2.js
More file actions
220 lines (205 loc) · 7.51 KB
/
Copy pathpatch-2.js
File metadata and controls
220 lines (205 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
var ldnode = require('../')
var supertest = require('supertest')
var assert = require('chai').assert
var path = require('path')
// Helper functions for the FS
var rm = require('./test-utils').rm
var write = require('./test-utils').write
// var cp = require('./test-utils').cp
var read = require('./test-utils').read
describe('PATCH', function () {
// Starting LDP
var ldp = ldnode({
root: path.join(__dirname, '/resources/sampleContainer'),
mount: '/test'
})
var server = supertest(ldp)
it.skip('..................', function (done) {
rm('sampleContainer/notExisting.ttl')
server.patch('/notExisting.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :test :hello 456 .}')
.expect(200)
.end(function (err, res, body) {
if (err) {
done(err)
}
console.log('@@@@ ' + read('sampleContainer/notExisting.ttl'))
assert.equal(
read('sampleContainer/notExisting.ttl'), ''
)
rm('sampleContainer/notExisting.ttl')
done(err)
})
})
describe('DELETE', function () {
it('reproduce index 1 bug from pad', function (done) {
var expected = `@prefix : </existingTriple.ttl#>.
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix c: <https://www.w3.org/People/Berners-Lee/card#>.
@prefix n: <http://rdfs.org/sioc/ns#>.
@prefix p: <http://www.w3.org/ns/pim/pad#>.
@prefix ic: <http://www.w3.org/2002/12/cal/ical#>.
@prefix XML: <http://www.w3.org/2001/XMLSchema#>.
@prefix flow: <http://www.w3.org/2005/01/wf/flow#>.
@prefix ui: <http://www.w3.org/ns/ui#>.
@prefix ind: </parent/index.ttl#>.
@prefix mee: <http://www.w3.org/ns/pim/meeting#>.
:id1477502276660 dc:author c:i; n:content ""; p:next :this.
:id1477522707481
ic:dtstart "2016-10-26T22:58:27Z"^^XML:dateTime;
flow:participant c:i;
ui:backgroundColor "#c1d0c8".
:this
a p:Notepad;
dc:author c:i;
dc:created "2016-10-25T15:44:42Z"^^XML:dateTime;
dc:title "Shared Notes";
p:next :id1477502276660.
ind:this flow:participation :id1477522707481; mee:sharedNotes :this.\n\n`
write(`\n\
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix meeting: <http://www.w3.org/ns/pim/meeting#>.
@prefix card: <https://www.w3.org/People/Berners-Lee/card#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix p: <http://www.w3.org/ns/pim/pad#>.
@prefix in: </parent/index.ttl#>.
@prefix n: <http://rdfs.org/sioc/ns#>.
@prefix flow: <http://www.w3.org/2005/01/wf/flow#>.
@prefix ic: <http://www.w3.org/2002/12/cal/ical#>.
@prefix ui: <http://www.w3.org/ns/ui#>.
<#this>
dc:author
card:i;
dc:created
"2016-10-25T15:44:42Z"^^xsd:dateTime;
dc:title
"Shared Notes";
a p:Notepad;
p:next
<#id1477502276660>.
in:this flow:participation <#id1477522707481>; meeting:sharedNotes <#this> .
<#id1477502276660> dc:author card:i; n:content ""; p:indent 1; p:next <#this> .
<#id1477522707481>
ic:dtstart
"2016-10-26T22:58:27Z"^^xsd:dateTime;
flow:participant
card:i;
ui:backgroundColor
"#c1d0c8".\n`,
'sampleContainer/existingTriple.ttl')
server.post('/existingTriple.ttl')
.set('content-type', 'application/sparql-update')
.send('DELETE { <#id1477502276660> <http://www.w3.org/ns/pim/pad#indent> 1 .}')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/existingTriple.ttl'),
expected)
rm('sampleContainer/existingTriple.ttl')
done(err)
})
})
})
describe('DELETE and INSERT', function () {
it('should be update a resource using SPARQL-query using `prefix`', function (done) {
write(
'@prefix schema: <http://schema.org/> .\n' +
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
'# <http://example.com/timbl#> a schema:Person ;\n' +
'<#> a schema:Person ;\n' +
' profile:first_name "Tim" .\n',
'sampleContainer/prefixSparql.ttl')
server.post('/prefixSparql.ttl')
.set('content-type', 'application/sparql-update')
.send('@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n' +
'@prefix schema: <http://schema.org/> .\n' +
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
'@prefix ex: <http://example.org/vocab#> .\n' +
'DELETE { <#> profile:first_name "Tim" }\n' +
'INSERT { <#> profile:first_name "Timothy" }')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/prefixSparql.ttl'),
'@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')
rm('sampleContainer/prefixSparql.ttl')
done(err)
})
})
})
describe('INSERT', function () {
it('should add a new triple', function (done) {
write(
'<#current> <#temp> 123 .',
'sampleContainer/addingTriple.ttl')
server.post('/addingTriple.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :test :hello 456 .}')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTriple.ttl'),
'@prefix : </addingTriple.ttl#>.\n\n' +
':current :temp 123 .\n\n' +
':test :hello 456 .\n\n')
rm('sampleContainer/addingTriple.ttl')
done(err)
})
})
it('should add value to existing triple', function (done) {
write(
'<#current> <#temp> 123 .',
'sampleContainer/addingTripleValue.ttl')
server.post('/addingTripleValue.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :current :temp 456 .}')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleValue.ttl'),
'@prefix : </addingTripleValue.ttl#>.\n\n' +
':current :temp 123, 456 .\n\n')
rm('sampleContainer/addingTripleValue.ttl')
done(err)
})
})
it('should add value to same subject', function (done) {
write(
'<#current> <#temp> 123 .',
'sampleContainer/addingTripleSubj.ttl')
server.post('/addingTripleSubj.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :current :temp2 456 .}')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/addingTripleSubj.ttl'),
'@prefix : </addingTripleSubj.ttl#>.\n\n' +
':current :temp 123; :temp2 456 .\n\n')
rm('sampleContainer/addingTripleSubj.ttl')
done(err)
})
})
})
it('nothing should change with empty patch', function (done) {
write(
'<#current> <#temp> 123 .',
'sampleContainer/emptyExample.ttl')
server.post('/emptyExample.ttl')
.set('content-type', 'application/sparql-update')
.send('')
.expect(200)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/emptyExample.ttl'),
'@prefix : </emptyExample.ttl#>.\n\n' +
':current :temp 123 .\n\n')
rm('sampleContainer/emptyExample.ttl')
done(err)
})
})
})