Skip to content

Commit d9953c5

Browse files
author
deiu
committed
Fixed conflict
2 parents 46041fc + 4b83a31 commit d9953c5

1 file changed

Lines changed: 117 additions & 16 deletions

File tree

test/patch.js

Lines changed: 117 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var expect = require('chai').expect;
66
var assert = require('chai').assert;
77
var path = require('path');
88

9+
// Helper functions for the FS
910
function cp (src, dest) {
1011
return fsExtra.copySync(
1112
__dirname + '/' + src,
@@ -26,31 +27,131 @@ function write (text, file) {
2627
return fs.writeFileSync(__dirname + '/' + file, text);
2728
}
2829

29-
3030
describe('PATCH', function () {
31+
// Starting LDP
3132
var ldp = ldnode.createServer({
3233
root: __dirname + '/testfiles',
3334
mount: '/test'
3435
});
3536
ldp.listen(3453);
3637
var server = supertest('http://localhost:3453/test');
3738

38-
describe('POST', function() {
39+
it('should be an empty resource if last triple is deleted', function (done) {
3940
write(
4041
'<#current> <#temp> 123 .',
41-
'testfiles/emptyExample.ttl');
42+
'testfiles/existingTriple.ttl');
43+
server.post('/existingTriple.ttl')
44+
.set('content-type', 'application/sparql-update')
45+
.send('DELETE { :current :temp 123 .}')
46+
.expect(200)
47+
.end(function(err, res, body){
48+
assert.equal(
49+
read('testfiles/existingTriple.ttl'),
50+
'\n');
51+
rm('testfiles/existingTriple.ttl');
52+
done(err);
53+
});
54+
});
4255

43-
it('nothing should change with an empty file', function (done) {
44-
server.post('/emptyExample.ttl')
45-
.set('content-type', 'application/sparql-update')
46-
.send('')
47-
.end(function(err, res, body){
48-
assert.equal(
49-
read('testfiles/emptyExample.ttl'),
50-
'\n <#current> <#temp> 123 .\n');
51-
rm('testfiles/emptyExample.ttl');
52-
done(err);
53-
});
54-
});
56+
it('should be update a resource using SPARQL-query using `prefix`', function (done) {
57+
write(
58+
'@prefix schema: <http://schema.org/> .\n' +
59+
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
60+
'# <http://example.com/timbl#> a schema:Person ;\n' +
61+
'<#> a schema:Person ;\n' +
62+
' profile:first_name "Tim" .\n',
63+
'testfiles/prefixSparql.ttl');
64+
server.post('/prefixSparql.ttl')
65+
.set('content-type', 'application/sparql-update')
66+
.send('@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n' +
67+
'@prefix schema: <http://schema.org/> .\n' +
68+
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
69+
'@prefix ex: <http://example.org/vocab#> .\n' +
70+
'DELETE { <#> profile:first_name "Tim" }\n' +
71+
'INSERT { <#> profile:first_name "Timothy" }')
72+
.expect(200)
73+
.end(function(err, res, body){
74+
assert.equal(
75+
read('testfiles/prefixSparql.ttl'),
76+
'@prefix schema: <http://schema.org/>.\n' +
77+
'@prefix profile: <http://ogp.me/ns/profile#>.\n' +
78+
'\n' +
79+
' <#> profile:first_name "Timothy"; a schema:Person .\n');
80+
rm('testfiles/prefixSparql.ttl');
81+
done(err);
82+
});
83+
});
84+
85+
it('should add a new triple', function (done) {
86+
write(
87+
'<#current> <#temp> 123 .',
88+
'testfiles/addingTriple.ttl');
89+
server.post('/addingTriple.ttl')
90+
.set('content-type', 'application/sparql-update')
91+
.send('INSERT DATA { :test :hello 456 .}')
92+
.expect(200)
93+
.end(function(err, res, body){
94+
assert.equal(
95+
read('testfiles/addingTriple.ttl'),
96+
'\n' +
97+
' <#current> <#temp> 123 .\n' +
98+
' <#test> <#hello> 456 .\n');
99+
rm('testfiles/addingTriple.ttl');
100+
done(err);
101+
});
102+
});
103+
104+
it('should add value to existing triple', function (done) {
105+
write(
106+
'<#current> <#temp> 123 .',
107+
'testfiles/addingTripleValue.ttl');
108+
server.post('/addingTripleValue.ttl')
109+
.set('content-type', 'application/sparql-update')
110+
.send('INSERT DATA { :current :temp 456 .}')
111+
.expect(200)
112+
.end(function(err, res, body){
113+
assert.equal(
114+
read('testfiles/addingTripleValue.ttl'),
115+
'\n' +
116+
' <#current> <#temp> 123, 456 .\n');
117+
rm('testfiles/addingTripleValue.ttl');
118+
done(err);
119+
});
120+
});
121+
122+
it('should add value to same subject', function (done) {
123+
write(
124+
'<#current> <#temp> 123 .',
125+
'testfiles/addingTripleSubj.ttl');
126+
server.post('/addingTripleSubj.ttl')
127+
.set('content-type', 'application/sparql-update')
128+
.send('INSERT DATA { :current :temp2 456 .}')
129+
.expect(200)
130+
.end(function(err, res, body){
131+
assert.equal(
132+
read('testfiles/addingTripleSubj.ttl'),
133+
'\n'+
134+
' <#current> <#temp2> 456; <#temp> 123 .\n');
135+
rm('testfiles/addingTripleSubj.ttl');
136+
done(err);
137+
});
138+
});
139+
140+
it('nothing should change with empty patch', function (done) {
141+
write(
142+
'<#current> <#temp> 123 .',
143+
'testfiles/emptyExample.ttl');
144+
server.post('/emptyExample.ttl')
145+
.set('content-type', 'application/sparql-update')
146+
.send('')
147+
.expect(200)
148+
.end(function(err, res, body){
149+
assert.equal(
150+
read('testfiles/emptyExample.ttl'),
151+
'\n' +
152+
' <#current> <#temp> 123 .\n');
153+
rm('testfiles/emptyExample.ttl');
154+
done(err);
155+
});
55156
});
56-
});
157+
});

0 commit comments

Comments
 (0)