forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-negotiation.test.js
More file actions
56 lines (47 loc) · 1.99 KB
/
content-negotiation.test.js
File metadata and controls
56 lines (47 loc) · 1.99 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
import { expect } from 'chai'
import { createTestApp, cleanTestDir, createFile } from './helpers.js'
describe('Content Negotiation', () => {
let request, testDir
beforeEach(() => {
({ request, testDir } = createTestApp())
})
afterEach(() => cleanTestDir(testDir))
it('returns Turtle by default for .ttl', async () => {
createFile(testDir, 'data.ttl', '<http://example.org/s> <http://example.org/p> "o".')
const res = await request.get('/data.ttl').expect(200)
expect(res.headers['content-type']).to.match(/text\/turtle/)
})
it('converts Turtle to JSON-LD when requested', async () => {
createFile(testDir, 'data.ttl', '<http://example.org/s> <http://example.org/p> "o".')
const res = await request.get('/data.ttl')
.set('Accept', 'application/ld+json')
.expect(200)
expect(res.headers['content-type']).to.match(/application\/ld\+json/)
const json = JSON.parse(res.text)
expect(json).to.be.an('object')
})
it('converts Turtle to N-Triples', async () => {
createFile(testDir, 'data.ttl', '<http://example.org/s> <http://example.org/p> "o".')
const res = await request.get('/data.ttl')
.set('Accept', 'application/n-triples')
.expect(200)
expect(res.headers['content-type']).to.match(/application\/n-triples/)
})
it('returns 406 for incompatible Accept on non-RDF', async () => {
createFile(testDir, 'image.png', 'fake png data')
await request.get('/image.png')
.set('Accept', 'text/turtle')
.expect(406)
})
it('serves non-RDF files with their native type', async () => {
createFile(testDir, 'style.css', 'body { color: red }')
const res = await request.get('/style.css').expect(200)
expect(res.headers['content-type']).to.match(/text\/css/)
})
it('serves container as Turtle', async () => {
const fs = await import('fs-extra')
fs.mkdirpSync(testDir + '/box')
const res = await request.get('/box/').expect(200)
expect(res.headers['content-type']).to.match(/text\/turtle/)
})
})