Skip to content

Commit ea9b40c

Browse files
committed
Adding test for Patch
But no actual implementation in patch handler yet
1 parent c541613 commit ea9b40c

File tree

4 files changed

+34
-78
lines changed

4 files changed

+34
-78
lines changed

test/integration/validate-tts.js

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,35 @@ const server = setupSuperServer({
1010
webid: false
1111
})
1212

13-
describe('Validate HTTP requests with Turtle syntax', function () {
14-
describe('PUT API', function () {
15-
const putRequestBody = fs.readFileSync(path.join(__dirname, '../resources/sampleContainer/invalid.ttl'), {
16-
'encoding': 'utf8'
13+
const invalidTurtleBody = fs.readFileSync(path.join(__dirname, '../resources/invalid1.ttl'), {
14+
'encoding': 'utf8'
15+
})
16+
17+
describe('HTTP requests with invalid Turtle syntax', () => {
18+
describe('PUT API', () => {
19+
it('should return 400', (done) => {
20+
server.put('/should-not-be-created.ttl')
21+
.send(invalidTurtleBody)
22+
.set('content-type', 'text/turtle')
23+
.expect(400, done)
1724
})
18-
it('should return 400', function (done) {
19-
server.put('/put-resource-1.ttl')
20-
.send(putRequestBody)
25+
})
26+
27+
describe.skip('PATCH API', () => {
28+
it('should return 400', (done) => { // TODO: This returns 415 right now
29+
server.patch('/patch-1-initial.ttl')
30+
.send(invalidTurtleBody)
2131
.set('content-type', 'text/turtle')
2232
.expect(400, done)
2333
})
2434
})
2535

26-
// describe('POST (multipart)', function () {
27-
// it('should create as many files as the ones passed in multipart',
28-
// function (done) {
29-
// server.post('/sampleContainer/')
30-
// .attach('timbl', path.join(__dirname, '../resources/timbl.jpg'))
31-
// .attach('nicola', path.join(__dirname, '../resources/nicola.jpg'))
32-
// .expect(200)
33-
// .end(function (err) {
34-
// if (err) return done(err)
35-
//
36-
// var sizeNicola = fs.statSync(path.join(__dirname,
37-
// '../resources/nicola.jpg')).size
38-
// var sizeTim = fs.statSync(path.join(__dirname, '../resources/timbl.jpg')).size
39-
// var sizeNicolaLocal = fs.statSync(path.join(__dirname,
40-
// '../resources/sampleContainer/nicola.jpg')).size
41-
// var sizeTimLocal = fs.statSync(path.join(__dirname,
42-
// '../resources/sampleContainer/timbl.jpg')).size
43-
//
44-
// if (sizeNicola === sizeNicolaLocal && sizeTim === sizeTimLocal) {
45-
// return done()
46-
// } else {
47-
// return done(new Error('Either the size (remote/local) don\'t match or files are not stored'))
48-
// }
49-
// })
50-
// })
51-
// after(function () {
52-
// // Clean up after POST (multipart) API tests
53-
// return Promise.all([
54-
// rm('/sampleContainer/nicola.jpg'),
55-
// rm('/sampleContainer/timbl.jpg')
56-
// ])
57-
// })
58-
// })
36+
describe.skip('POST API (multipart)', () => { // TODO: Is this something we should validate?
37+
it('should create as many files as the ones passed in multipart', (done) => {
38+
server.post('/')
39+
.attach('timbl', path.join(__dirname, '../resources/invalid1.ttl'))
40+
.attach('nicola', path.join(__dirname, '../resources/invalid2.ttl'))
41+
.expect(400, done)
42+
})
43+
})
5944
})
File renamed without changes.

test/resources/invalid2.ttl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@prefix txn: <http://example.org/data/transaction/> .
2+
@prefix srv: <http://example.org/data/server/> .
3+
@prefix log: <http://example.org/ont/transaction-log/> .
4+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
5+
6+
txn:123 invalid log:Transaction ;
7+
log:processedBy srv:A ;
8+
log:processedAt "2015-10-16T10:22:23"^^xsd:dateTime ;
9+
log:statusCode 200 .

test/utils.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,3 @@ function setupSuperServer (options) {
9393
const ldpServer = createServer(options)
9494
return supertest(ldpServer)
9595
}
96-
97-
/**
98-
* Creates a new test basic container via an LDP POST
99-
* (located in `test/resources/{containerName}`)
100-
* @method createTestContainer
101-
* @param server {supertest} An instance of a supertest server
102-
* @param containerName {String} Container name used as slug, no leading `/`
103-
* @return {Promise} Promise obj, for use with Mocha's `before()` etc
104-
*/
105-
exports.createTestContainer = function createTestContainer (server, containerName) {
106-
return new Promise(function (resolve, reject) {
107-
server.post('/')
108-
.set('content-type', 'text/turtle')
109-
.set('slug', containerName)
110-
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
111-
.set('content-type', 'text/turtle')
112-
.end(function (error, res) {
113-
error ? reject(error) : resolve(res)
114-
})
115-
})
116-
}
117-
118-
/**
119-
* Creates a new turtle test resource via an LDP PUT
120-
* (located in `test/resources/{resourceName}`)
121-
* @method createTestResource
122-
* @param resourceName {String} Resource name (should have a leading `/`)
123-
* @return {Promise} Promise obj, for use with Mocha's `before()` etc
124-
*/
125-
exports.createTestResource = function createTestResource (server, resourceName) {
126-
return new Promise(function (resolve, reject) {
127-
server.put(resourceName)
128-
.set('content-type', 'text/turtle')
129-
.end(function (error, res) {
130-
error ? reject(error) : resolve(res)
131-
})
132-
})
133-
}

0 commit comments

Comments
 (0)