Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions test/http-workflows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*jslint node: true*/
var supertest = require('supertest');
var ldnode = require('../index');

var ldpServer = ldnode({
root: __dirname + '/resources'
});

var server = supertest(ldpServer);

describe('HTTP Workflows', function () {
it('can PUT JSON, then GET it back', function (done) {
// Notably, if this path ends with .json, then the test will pass
var path = '/can-put-json-then-get-test-artifact';
var blob = JSON.stringify({ content: "Hello, world "});
var contentType = 'application/json; charset=utf-8';
server.put(path)
.send(blob)
.set('content-type', contentType)
.expect(201)
.end(function (err, res) {
if (err) return done(err);
get()
});
function get() {
// now try to get the thing
server.get(path)
.set('Accept', contentType)
.expect(200)
// This fails because it will be application/octet-stream; charset=utf-8
.expect('content-type', contentType)
.end(done);
}
})
it('can PUT text/plain, then GET it back', function (done) {
var path = '/can-put-text-then-get-test-arfifact';
var blob = 'Hello, world (as text/plain)!'
var contentType = 'text/plain';
server.put(path)
.send(blob)
.set('content-type', contentType)
.expect(201)
.end(function (err, res) {
if (err) return done(err);
get()
});
function get() {
// now try to get the thing
server.get(path)
.set('Accept', contentType)
.expect(200)
// This fails because it will be application/octet-stream; charset=utf-8
.expect('content-type', contentType)
.end(done);
}
})
});