-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathformats-test.js
138 lines (128 loc) · 5.54 KB
/
formats-test.js
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
const path = require('path')
const assert = require('chai').assert
const { setupSupertestServer } = require('../utils')
describe('formats', function () {
const server = setupSupertestServer({
root: path.join(__dirname, '../resources'),
webid: false
})
describe('HTML', function () {
it('should return HTML containing "Hello, World!" if Accept is set to text/html', function (done) {
server.get('/hello.html')
.set('accept', 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5')
.expect('Content-type', /text\/html/)
.expect(/Hello, world!/)
.expect(200, done)
})
describe('HTML dataIsland', function () {
it('should return 404 if Accept is set to only text/turtle and no dataIsland', function (done) {
server.get('/hello.html')
.set('accept', 'text/turtle')
.expect(404, done)
})
it('should return text/turtle if dataIsland and Accept is set to only text/turtle', function (done) {
server.get('/hello-with-data-island.html')
.set('accept', 'text/turtle')
.expect('Content-type', /text\/turtle/)
.expect(/<> a "test"./)
.expect(200, done)
})
it('should return JSON-LD if dataIsland and Accept is set to only application/ld+json', function (done) {
server.get('/hello-with-data-island.html')
.set('accept', 'application/ld+json')
.expect('Content-type', 'application/ld+json; charset=utf-8')
.expect(200, done)
})
})
})
describe('JSON-LD', function () {
function isCorrectSubject (idFragment) {
return (res) => {
const payload = JSON.parse(res.text)
const id = payload[0]['@id']
assert(id.endsWith(idFragment), 'The subject of the JSON-LD graph is correct')
}
}
function isValidJSON (res) {
// This would throw an error
JSON.parse(res.text)
}
it('should return JSON-LD document if Accept is set to only application/ld+json', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'application/ld+json')
.expect(200)
.expect('content-type', /application\/ld\+json/)
.expect(isValidJSON)
.expect(isCorrectSubject('/patch-5-initial.ttl#Iss1408851516666'))
.end(done)
})
it('should return the container listing in JSON-LD if Accept is set to only application/ld+json', function (done) {
server.get('/')
.set('accept', 'application/ld+json')
.expect(200)
.expect('content-type', /application\/ld\+json/)
.end(done)
})
it('should prefer to avoid translation even if type is listed with less priority', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'application/ld+json;q=0.9,text/turtle;q=0.8,text/plain;q=0.7,*/*;q=0.5')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
it('should return JSON-LD document if Accept is set to application/ld+json and other types', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'application/ld+json;q=0.9,application/rdf+xml;q=0.7')
.expect('content-type', /application\/ld\+json/)
.expect(200, done)
})
})
describe('N-Quads', function () {
it('should return N-Quads document is Accept is set to application/n-quads', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'application/n-quads;q=0.9,application/ld+json;q=0.8,application/rdf+xml;q=0.7')
.expect('content-type', /application\/n-quads/)
.expect(200, done)
})
})
describe('n3', function () {
it('should return turtle document if Accept is set to text/n3', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'text/n3;q=0.9,application/n-quads;q=0.7,text/plain;q=0.7')
.expect('content-type', /text\/n3/)
.expect(200, done)
})
})
describe('turtle', function () {
it('should return turtle document if Accept is set to turtle', function (done) {
server.get('/patch-5-initial.ttl')
.set('accept', 'text/turtle;q=0.9,application/rdf+xml;q=0.8,text/plain;q=0.7,*/*;q=0.5')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
it('should return turtle document if Accept is set to turtle', function (done) {
server.get('/lennon.jsonld')
.set('accept', 'text/turtle')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
it('should return turtle when listing container with an index page', function (done) {
server.get('/sampleContainer/')
.set('accept', 'application/rdf+xml;q=0.4, application/xhtml+xml;q=0.3, text/xml;q=0.2, application/xml;q=0.2, text/html;q=0.3, text/plain;q=0.1, text/turtle;q=1.0, application/n3;q=1')
.expect('content-type', /text\/html/)
.expect(200, done)
})
it('should return turtle when listing container without an index page', function (done) {
server.get('/sampleContainer2/')
.set('accept', 'application/rdf+xml;q=0.4, application/xhtml+xml;q=0.3, text/xml;q=0.2, application/xml;q=0.2, text/html;q=0.3, text/plain;q=0.1, text/turtle;q=1.0, application/n3;q=1')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
})
describe('none', function () {
it('should return turtle document if no Accept header is set', function (done) {
server.get('/patch-5-initial.ttl')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
})
})