Skip to content

Commit 3a9f176

Browse files
committed
Improving test structure
1 parent 9878760 commit 3a9f176

5 files changed

Lines changed: 163 additions & 142 deletions

File tree

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ function ldnode (argv) {
5252

5353
// Adding proxy
5454
if (opts.xssProxy) {
55-
console.log(opts.proxyFilter);
5655
proxy(app, opts.proxyFilter);
5756
}
5857

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"test-debug": "DEBUG='ldnode:*' ./node_modules/mocha/bin/mocha ./test/*.js",
6161
"test-acl": "./node_modules/mocha/bin/mocha ./test/acl.js",
6262
"test-params": "./node_modules/mocha/bin/mocha ./test/params.js",
63-
"test-http": "./node_modules/mocha/bin/mocha ./test/test.js"
63+
"test-http": "./node_modules/mocha/bin/mocha ./test/http.js",
64+
"test-formats": "./node_modules/mocha/bin/mocha ./test/http.js"
6465
},
6566
"bin": {
6667
"ldnode": "./bin/ldnode.js"

test/formats.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*jslint node: true*/
2+
var supertest = require('supertest');
3+
var path = require('path');
4+
var ldnode = require('../index');
5+
var fs = require('fs');
6+
var S = require('string');
7+
8+
describe('formats', function () {
9+
var address = 'http://localhost:3457';
10+
var ldp = ldnode.createServer({
11+
root: __dirname + '/resources',
12+
});
13+
ldp.listen(3457);
14+
15+
var server = supertest(address);
16+
describe('HTML', function() {
17+
it('Should return "Hello, World!"', function(done) {
18+
server.get('/hello.html')
19+
.expect('Content-type', /text\/html/)
20+
.expect(/Hello, world!/)
21+
.expect(200, done);
22+
});
23+
});
24+
25+
describe('JSON-LD', function() {
26+
var isValidJSON = function(res) {
27+
var json = JSON.parse(res.text);
28+
};
29+
it('Should return JSON-LD document', function(done) {
30+
server.get('/patch-5-initial.ttl')
31+
.set('accept', 'application/json+ld')
32+
.expect('content-type', /application\/json\+ld/)
33+
.expect(200, done);
34+
});
35+
it('Should return valid JSON', function(done) {
36+
server.get('/patch-5-initial.ttl')
37+
.set('accept', 'application/json+ld')
38+
.expect(isValidJSON)
39+
.expect(200, done);
40+
});
41+
});
42+
43+
describe('N-Quads', function() {
44+
it('Should return N-Quads document', function(done) {
45+
server.get('/patch-5-initial.ttl')
46+
.set('accept', 'application/n-quads')
47+
.expect('content-type', /application\/n-quads/)
48+
.expect(200, done);
49+
});
50+
});
51+
52+
describe('n3', function() {
53+
it('Should return turtle document if content-type set to n3', function(done) {
54+
server.get('/patch-5-initial.ttl')
55+
.set('accept', 'text/n3')
56+
.expect('content-type', /text\/n3/)
57+
.expect(200, done);
58+
});
59+
});
60+
});

test/test.js renamed to test/http.js

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var ldnode = require('../index');
55
var fs = require('fs');
66
var S = require('string');
77

8-
describe('ldnode', function() {
8+
describe('HTTP APIs', function() {
99
var address = 'http://localhost:3457';
1010
var ldp = ldnode.createServer({
1111
root: __dirname + '/resources',
@@ -14,16 +14,7 @@ describe('ldnode', function() {
1414

1515
var server = supertest(address);
1616

17-
describe('Hello World', function() {
18-
it('Should return "Hello, World!"', function(done) {
19-
server.get('/hello.html')
20-
.expect('Content-type', /text\/html/)
21-
.expect(/Hello, world!/)
22-
.expect(200, done);
23-
});
24-
});
25-
26-
describe('Root container', function() {
17+
describe('GET Root container', function() {
2718
it('Should exists', function(done) {
2819
server.get('/')
2920
.expect(200, done);
@@ -35,42 +26,6 @@ describe('ldnode', function() {
3526
});
3627
});
3728

38-
describe('JSON-LD support', function() {
39-
var isValidJSON = function(res) {
40-
var json = JSON.parse(res.text);
41-
};
42-
it('Should return JSON-LD document', function(done) {
43-
server.get('/patch-5-initial.ttl')
44-
.set('accept', 'application/json+ld')
45-
.expect('content-type', /application\/json\+ld/)
46-
.expect(200, done);
47-
});
48-
it('Should return valid JSON', function(done) {
49-
server.get('/patch-5-initial.ttl')
50-
.set('accept', 'application/json+ld')
51-
.expect(isValidJSON)
52-
.expect(200, done);
53-
});
54-
});
55-
56-
describe('N-Quads support', function() {
57-
it('Should return N-Quads document', function(done) {
58-
server.get('/patch-5-initial.ttl')
59-
.set('accept', 'application/n-quads')
60-
.expect('content-type', /application\/n-quads/)
61-
.expect(200, done);
62-
});
63-
});
64-
65-
describe('n3 support', function() {
66-
it('Should return turtle document if content-type set to n3', function(done) {
67-
server.get('/patch-5-initial.ttl')
68-
.set('accept', 'text/n3')
69-
.expect('content-type', /text\/n3/)
70-
.expect(200, done);
71-
});
72-
});
73-
7429
describe('GET API', function() {
7530
it('Should return 404 for non-existent resource', function(done) {
7631
server.get('/invalidfile.foo')

test/patch.js

Lines changed: 99 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -36,105 +36,111 @@ describe('PATCH', function () {
3636
ldp.listen(3453);
3737
var server = supertest('http://localhost:3453/test');
3838

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

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-
'sampleContainer/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('sampleContainer/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('sampleContainer/prefixSparql.ttl');
81-
done(err);
82-
});
58+
describe('DELETE and INSERT', function () {
59+
it('should be update a resource using SPARQL-query using `prefix`', function (done) {
60+
write(
61+
'@prefix schema: <http://schema.org/> .\n' +
62+
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
63+
'# <http://example.com/timbl#> a schema:Person ;\n' +
64+
'<#> a schema:Person ;\n' +
65+
' profile:first_name "Tim" .\n',
66+
'sampleContainer/prefixSparql.ttl');
67+
server.post('/prefixSparql.ttl')
68+
.set('content-type', 'application/sparql-update')
69+
.send('@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n' +
70+
'@prefix schema: <http://schema.org/> .\n' +
71+
'@prefix profile: <http://ogp.me/ns/profile#> .\n' +
72+
'@prefix ex: <http://example.org/vocab#> .\n' +
73+
'DELETE { <#> profile:first_name "Tim" }\n' +
74+
'INSERT { <#> profile:first_name "Timothy" }')
75+
.expect(200)
76+
.end(function(err, res, body){
77+
assert.equal(
78+
read('sampleContainer/prefixSparql.ttl'),
79+
'@prefix schema: <http://schema.org/>.\n' +
80+
'@prefix profile: <http://ogp.me/ns/profile#>.\n' +
81+
'\n' +
82+
' <#> profile:first_name "Timothy"; a schema:Person .\n');
83+
rm('sampleContainer/prefixSparql.ttl');
84+
done(err);
85+
});
86+
});
8387
});
8488

85-
it('should add a new triple', function (done) {
86-
write(
87-
'<#current> <#temp> 123 .',
88-
'sampleContainer/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('sampleContainer/addingTriple.ttl'),
96-
'\n' +
97-
' <#current> <#temp> 123 .\n' +
98-
' <#test> <#hello> 456 .\n');
99-
rm('sampleContainer/addingTriple.ttl');
100-
done(err);
101-
});
102-
});
89+
describe('INSERT', function () {
90+
it('should add a new triple', function (done) {
91+
write(
92+
'<#current> <#temp> 123 .',
93+
'sampleContainer/addingTriple.ttl');
94+
server.post('/addingTriple.ttl')
95+
.set('content-type', 'application/sparql-update')
96+
.send('INSERT DATA { :test :hello 456 .}')
97+
.expect(200)
98+
.end(function(err, res, body){
99+
assert.equal(
100+
read('sampleContainer/addingTriple.ttl'),
101+
'\n' +
102+
' <#current> <#temp> 123 .\n' +
103+
' <#test> <#hello> 456 .\n');
104+
rm('sampleContainer/addingTriple.ttl');
105+
done(err);
106+
});
107+
});
103108

104-
it('should add value to existing triple', function (done) {
105-
write(
106-
'<#current> <#temp> 123 .',
107-
'sampleContainer/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('sampleContainer/addingTripleValue.ttl'),
115-
'\n' +
116-
' <#current> <#temp> 123, 456 .\n');
117-
rm('sampleContainer/addingTripleValue.ttl');
118-
done(err);
119-
});
120-
});
109+
it('should add value to existing triple', function (done) {
110+
write(
111+
'<#current> <#temp> 123 .',
112+
'sampleContainer/addingTripleValue.ttl');
113+
server.post('/addingTripleValue.ttl')
114+
.set('content-type', 'application/sparql-update')
115+
.send('INSERT DATA { :current :temp 456 .}')
116+
.expect(200)
117+
.end(function(err, res, body){
118+
assert.equal(
119+
read('sampleContainer/addingTripleValue.ttl'),
120+
'\n' +
121+
' <#current> <#temp> 123, 456 .\n');
122+
rm('sampleContainer/addingTripleValue.ttl');
123+
done(err);
124+
});
125+
});
121126

122-
it('should add value to same subject', function (done) {
123-
write(
124-
'<#current> <#temp> 123 .',
125-
'sampleContainer/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('sampleContainer/addingTripleSubj.ttl'),
133-
'\n'+
134-
' <#current> <#temp2> 456; <#temp> 123 .\n');
135-
rm('sampleContainer/addingTripleSubj.ttl');
136-
done(err);
137-
});
127+
it('should add value to same subject', function (done) {
128+
write(
129+
'<#current> <#temp> 123 .',
130+
'sampleContainer/addingTripleSubj.ttl');
131+
server.post('/addingTripleSubj.ttl')
132+
.set('content-type', 'application/sparql-update')
133+
.send('INSERT DATA { :current :temp2 456 .}')
134+
.expect(200)
135+
.end(function(err, res, body){
136+
assert.equal(
137+
read('sampleContainer/addingTripleSubj.ttl'),
138+
'\n'+
139+
' <#current> <#temp2> 456; <#temp> 123 .\n');
140+
rm('sampleContainer/addingTripleSubj.ttl');
141+
done(err);
142+
});
143+
});
138144
});
139145

140146
it('nothing should change with empty patch', function (done) {

0 commit comments

Comments
 (0)