From 9c0885aa07b2743680fb3e9dbcfcafcfc954c6f7 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 3 Feb 2014 10:58:37 -0800 Subject: [PATCH] Fix remoting for container/file apis --- lib/storage-service.js | 2 +- test/upload-download.test.js | 98 ++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/lib/storage-service.js b/lib/storage-service.js index fa83d6f..aa26d91 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -148,7 +148,7 @@ StorageService.prototype.getContainer.http = StorageService.prototype.createContainer.shared = true; StorageService.prototype.createContainer.accepts = [ - {arg: 'options', type: 'object'} + {arg: 'options', type: 'object', http: {source: 'body'}} ]; StorageService.prototype.createContainer.returns = {arg: 'container', type: 'object', root: true}; StorageService.prototype.createContainer.http = diff --git a/test/upload-download.test.js b/test/upload-download.test.js index c975f15..a79aa85 100644 --- a/test/upload-download.test.js +++ b/test/upload-download.test.js @@ -29,6 +29,81 @@ describe('storage service', function () { server.close(); }); + it('should create a container', function (done) { + + request('http://localhost:3000') + .post('/containers') + .send({name: 'test-container'}) + .set('Accept', 'application/json') + .set('Content-Type', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert.equal(res.body.name, 'test-container'); + done(); + }); + }); + + it('should get a container', function (done) { + + request('http://localhost:3000') + .get('/containers/test-container') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert.equal(res.body.name, 'test-container'); + done(); + }); + }); + + it('should list containers', function (done) { + + request('http://localhost:3000') + .get('/containers') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert(Array.isArray(res.body)); + assert.equal(res.body.length, 2); + done(); + }); + }); + + it('should delete a container', function (done) { + + request('http://localhost:3000') + .del('/containers/test-container') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + done(); + }); + }); + + it('should list containers after delete', function (done) { + + request('http://localhost:3000') + .get('/containers') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert(Array.isArray(res.body)); + assert.equal(res.body.length, 1); + done(); + }); + }); + + it('should list files', function (done) { + + request('http://localhost:3000') + .get('/containers/album1/files') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert(Array.isArray(res.body)); + done(); + }); + }); + it('uploads files', function (done) { request('http://localhost:3000') @@ -44,6 +119,18 @@ describe('storage service', function () { }); }); + it('should get file by name', function (done) { + + request('http://localhost:3000') + .get('/containers/album1/files/test.jpg') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + assert.equal(res.body.name, 'test.jpg'); + done(); + }); + }); + it('downloads files', function (done) { request('http://localhost:3000') @@ -54,6 +141,17 @@ describe('storage service', function () { }); }); + it('should delete a file', function (done) { + + request('http://localhost:3000') + .del('/containers/album1/files/test.jpg') + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect(200, function (err, res) { + done(); + }); + }); + it('reports errors if it fails to find the file to download', function (done) { request('http://localhost:3000')