node-go/server/test/auth.spec.js
2020-01-14 12:06:25 -08:00

47 lines
No EOL
1.2 KiB
JavaScript

const authSpec = (chai, knex, server) => {
const newUserFormData = {
'username':'newUser',
'password':'password',
'email':'user@example.com'
}
it('post to sign up should return 200 status', done => {
chai.request(server)
.post('/auth/signup')
.type('form')
.send(newUserFormData)
.end((err, res) => {
if (err) done(err);
res.should.status(200);
done();
});
});
it('post to sign up should return token', done => {
chai.request(server)
.post('/auth/signup')
.type('form')
.send(newUserFormData)
.end((err, res) => {
if (err) done(err);
res.should.cookie('token');
done();
});
});
it('post to sign up should add user to db', done => {
chai.request(server)
.post('/auth/signup')
.type('form')
.send(newUserFormData)
.end((err, res) => {
if (err) done(err);
knex('user').where({'username': newUserFormData.username}).then(results => {
const newUser = results[0];
if (newUser.username === newUserFormData.username) done();
})
});
})
}
module.exports = authSpec;