Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Commit

Permalink
Support patch, update and remove many (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Apr 28, 2016
1 parent 8b4dea4 commit 6d83062
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Base {
params = params || {};
let url = this.base;

if (typeof id !== 'undefined') {
if (typeof id !== 'undefined' && id !== null) {
url += `/${id}`;
}

Expand Down
12 changes: 10 additions & 2 deletions test/client/fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('fetch REST connector', function() {
done();
});
});

it('can initialize a client instance', done => {
const init = rest(url).fetch(fetch);
const todos = init.service('todos');

assert.ok(todos instanceof init.Service, 'Returned service is a client');
todos.find({}).then(todos => assert.deepEqual(todos, [
{
Expand All @@ -54,4 +54,12 @@ describe('fetch REST connector', function() {
}
])).then(() => done()).catch(done);
});

it('remove many', done => {
service.remove(null).then(todo => {
assert.equal(todo.id, null);
assert.equal(todo.text, 'deleted many');
done();
});
});
});
12 changes: 10 additions & 2 deletions test/client/jquery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('jQuery REST connector', function() {
query: {}
})).then(done).catch(done);
});

it('can initialize a client instance', done => {
const init = rest(url).jquery(service.connection);
const todos = init.service('todos');

assert.ok(todos instanceof init.Service, 'Returned service is a client');
todos.find({}).then(todos => assert.deepEqual(todos, [
{
Expand All @@ -59,4 +59,12 @@ describe('jQuery REST connector', function() {
}
])).then(() => done()).catch(done);
});

it('remove many', done => {
service.remove(null).then(todo => {
assert.equal(todo.id, null);
assert.equal(todo.text, 'deleted many');
done();
});
});
});
8 changes: 8 additions & 0 deletions test/client/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ describe('node-request REST connector', function() {
done();
}).catch(done);
});

it('remove many', done => {
service.remove(null).then(todo => {
assert.equal(todo.id, null);
assert.equal(todo.text, 'deleted many');
done();
});
});
});
12 changes: 11 additions & 1 deletion test/client/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ let errorHandler = function(error, req, res, next) {
module.exports = function(configurer) {
// Create an in-memory CRUD service for our Todos
var todoService = memory().extend({
get: function(id, params) {
get(id, params) {
if(params.query.error) {
throw new Error('Something went wrong');
}

return this._super(id, params)
.then(data => Object.assign({ query: params.query }, data));
},

remove(id) {
if(id === null) {
return Promise.resolve({
id, text: 'deleted many'
});
}

return this._super.apply(this, arguments);
}
});

Expand Down
12 changes: 10 additions & 2 deletions test/client/superagent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ describe('Superagent REST connector', function() {
query: {}
})).then(done).catch(done);
});

it('can initialize a client instance', done => {
const init = rest(url).superagent(superagent);
const todos = init.service('todos');

assert.ok(todos instanceof init.Service, 'Returned service is a client');
todos.find({}).then(todos => assert.deepEqual(todos, [
{
Expand All @@ -47,4 +47,12 @@ describe('Superagent REST connector', function() {
}
])).then(() => done()).catch(done);
});

it('remove many', done => {
service.remove(null).then(todo => {
assert.equal(todo.id, null);
assert.equal(todo.text, 'deleted many');
done();
});
});
});

0 comments on commit 6d83062

Please sign in to comment.