Skip to content

Instantly share code, notes, and snippets.

@ebramanti
Last active February 18, 2016 21:50
Show Gist options
  • Save ebramanti/b7a31f9aaa5bf7cfb133 to your computer and use it in GitHub Desktop.
Save ebramanti/b7a31f9aaa5bf7cfb133 to your computer and use it in GitHub Desktop.
describe('GET potatoes', function() {
it('returns JSON with only authenticated robot\'s potatoes', function(done) {
const objs = {};
const createGlados = function() {
return factory.create('robot').then(function(robot) {
objs.glados = robot;
return robot;
});
};
const createWheatley = function() {
return factory.create('robot').then(function(robot) {
objs.wheatley = robot;
return robot;
});
};
const createGladosPotatoes = function() {
return Promise.all([
factory.create('potato', { ownerId: objs.glados.id }),
factory.create('potato', { ownerId: objs.glados.id }),
]).then(function(potatoes) {
objs.gladosPotatoes = potatoes;
return potatoes;
});
};
const createWheatleyPotato = function() {
return factory.create('potato', { ownerId: objs.wheatley.id })
.then(function(potato) {
objs.wheatleyPotato = potato;
return potato;
});
};
createGlados
.then(createGladosPotatoes)
.then(createWheatley)
.then(createWheatleyPotato)
.then(function() {
request
.auth(objs.glados)
.get('/potatoes')
.then(function(response) {
const potatoesResponse = response.body.potatoes;
const returnedIds = _.pluck(potatoesResponse, 'id');
expect(returnedIds).to.include(_.pluck(objs.gladosPotatoes, 'id'));
expect(returnedIds).not.to.include(objs.wheatleyPotato.id);
done();
});
}).catch(done);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment