forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.test.js
More file actions
108 lines (97 loc) · 3.41 KB
/
patch.test.js
File metadata and controls
108 lines (97 loc) · 3.41 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
import { expect } from 'chai'
import { createTestApp, cleanTestDir, createFile } from './helpers.js'
describe('PATCH', () => {
let request, testDir
beforeEach(() => {
({ request, testDir } = createTestApp())
})
afterEach(() => cleanTestDir(testDir))
describe('SPARQL UPDATE', () => {
it('inserts data into a new resource (201)', async () => {
const patch = `
PREFIX dc: <http://purl.org/dc/terms/>
INSERT DATA { <> dc:title "Test" . }
`
await request.patch('/new.ttl')
.set('Content-Type', 'application/sparql-update')
.send(patch)
.expect(201)
})
it('inserts data into an existing resource (200)', async () => {
createFile(testDir, 'existing.ttl', '<http://example.org/s> <http://example.org/p> "old".')
const patch = `
PREFIX ex: <http://example.org/>
INSERT DATA { ex:s ex:q "new" . }
`
await request.patch('/existing.ttl')
.set('Content-Type', 'application/sparql-update')
.send(patch)
.expect(200)
})
it('deletes and inserts (atomic replace)', async () => {
createFile(testDir, 'replace.ttl', '<http://example.org/s> <http://example.org/p> "old".')
const patch = `
PREFIX ex: <http://example.org/>
DELETE { ex:s ex:p "old" . }
INSERT { ex:s ex:p "new" . }
`
await request.patch('/replace.ttl')
.set('Content-Type', 'application/sparql-update')
.send(patch)
.expect(200)
})
})
describe('N3 Patch', () => {
it('inserts triples into a new resource (201)', async () => {
const patch = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
<> a solid:InsertDeletePatch;
solid:inserts { <http://example.org/s> <http://example.org/p> "value". }.
`
await request.patch('/n3new.ttl')
.set('Content-Type', 'text/n3')
.send(patch)
.expect(201)
})
it('inserts triples into existing resource (200)', async () => {
createFile(testDir, 'n3exist.ttl', '<http://example.org/s> <http://example.org/p> "old".')
const patch = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
<> a solid:InsertDeletePatch;
solid:inserts { <http://example.org/s> <http://example.org/q> "new". }.
`
await request.patch('/n3exist.ttl')
.set('Content-Type', 'text/n3')
.send(patch)
.expect(200)
})
it('returns 409 when deleting non-existent triple', async () => {
createFile(testDir, 'n3del.ttl', '<http://example.org/s> <http://example.org/p> "exists".')
const patch = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
<> a solid:InsertDeletePatch;
solid:deletes { <http://example.org/s> <http://example.org/p> "nope". }.
`
await request.patch('/n3del.ttl')
.set('Content-Type', 'text/n3')
.send(patch)
.expect(409)
})
it('returns 400 for missing insert/delete', async () => {
const patch = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
<> a solid:InsertDeletePatch.
`
await request.patch('/bad.ttl')
.set('Content-Type', 'text/n3')
.send(patch)
.expect(400)
})
})
it('returns 415 for unsupported patch type', async () => {
await request.patch('/file.ttl')
.set('Content-Type', 'text/plain')
.send('something')
.expect(415)
})
})