From d212aafce506e40fccf4910090a62ade6961466c Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Sun, 22 Nov 2015 18:25:58 -0800 Subject: [PATCH] Add test/http-workflows to test common patterns that involve sequential http requests --- test/http-workflows.js | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/http-workflows.js diff --git a/test/http-workflows.js b/test/http-workflows.js new file mode 100644 index 000000000..952d18f7a --- /dev/null +++ b/test/http-workflows.js @@ -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); + } + }) +});