Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Last active December 7, 2015 11:52
Show Gist options
  • Save thebergamo/e93748884b06de49b45a to your computer and use it in GitHub Desktop.
Save thebergamo/e93748884b06de49b45a to your computer and use it in GitHub Desktop.
Todo tests in Lab
/* global describe, beforeEach, before, it, expect, db, server */
'use strict';
describe('Routes /todo', () => {
let token;
before((done) => {
let options = {
method: 'POST',
url: '/user',
payload: {
name: 'Jack Bauer',
username: 'jack_b',
email: 'jbauer@24hours.com',
password: '#24hoursRescuePresident'
}
};
server.inject(options, (response) => {
token = response.result.token;
done();
});
});
describe('GET /todo', () => {
it('return 200 HTTP status code', (done) => {
db.Todo.remove(() => {
let options = {
method: 'GET',
url: '/todo',
headers: {'Authorization': 'Bearer ' + token}
};
server.inject(options, (response) => {
expect(response).to.have.property('statusCode', 200);
done();
});
});
});
it('returns an empty array when todo is empty', (done) => {
db.Todo.remove(() => {
let options = {
method: 'GET',
url: '/todo',
headers: {'Authorization': 'Bearer ' + token}
};
server.inject(options, (response) => {
expect(response).to.have.property('result');
expect(response.result).to.have.length.least(0);
done();
});
});
});
it('return 1 todo at a time', (done) => {
let options = {
method: 'GET',
url: '/todo',
headers: {'Authorization': 'Bearer ' + token}
};
server.inject(options, (response) => {
expect(response).to.have.property('result');
expect(response.result).to.have.length.least(1);
let todo = response.result;
expect(todo).to.have.property('name');
expect(todo.name).to.contain('TODO Task');
expect(todo).to.have.property('checked', false);
done();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment