2020-01-14 20:06:25 +00:00
|
|
|
const authSpec = (chai, knex, server) => {
|
2020-01-13 22:47:45 +00:00
|
|
|
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)
|
2020-01-14 22:22:42 +00:00
|
|
|
.post('/auth/signup')
|
|
|
|
.type('form')
|
|
|
|
.send(newUserFormData)
|
|
|
|
.end((err, res) => {
|
|
|
|
if (err) done(err);
|
|
|
|
res.should.cookie('token');
|
|
|
|
done();
|
2020-01-14 20:06:25 +00:00
|
|
|
});
|
2020-01-14 22:22:42 +00:00
|
|
|
});
|
2020-01-14 20:06:25 +00:00
|
|
|
|
2020-01-14 22:22:42 +00:00
|
|
|
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();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
it('post to sign up should add user to db with password', 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.password !== newUserFormData.password) done();
|
|
|
|
})
|
|
|
|
});
|
2020-01-14 20:06:25 +00:00
|
|
|
})
|
2020-01-14 22:22:42 +00:00
|
|
|
|
|
|
|
|
2020-01-13 22:47:45 +00:00
|
|
|
}
|
|
|
|
module.exports = authSpec;
|