Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Last active January 30, 2019 13:47
Show Gist options
  • Save hypeJunction/18200ce8c42b396d9c75e606166b5fd0 to your computer and use it in GitHub Desktop.
Save hypeJunction/18200ce8c42b396d9c75e606166b5fd0 to your computer and use it in GitHub Desktop.
import request from 'supertest';
// Factory allows us to produce a "clean" instance of an app
// with stubbed services for each test
import factory from '../factory';
describe('AccountController', () => {
let app;
let services;
let models;
beforeEach(async () => {
app = await factory();
services = app.get('services');
models = services.db.models;
});
afterEach(() => {
app = null;
services = null;
models = null;
});
describe('.login()', async () => {
it('should fail login with invalid credentials', async () => {
const password = 'abcdefgh123456';
const user = await services.seeder.user({
password,
});
const response = await request(app)
.post('/api/account/login')
.send({
email: user.email,
password: '1234567',
})
.set('Accept', 'application/json');
expect(response.statusCode).to.equal(403);
// We can then test expected side-effects and state changes,
// for example we could grab the logger service and
// make sure a corresponding entry was made
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment