1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-14 00:46:38 -05:00

Fix db execution order and add expired invite test

This commit is contained in:
Jack 2017-10-12 20:57:22 -04:00
parent 3191aad0c1
commit 95b0526858
Signed by: foltik
GPG Key ID: 303F88F996E95541

View File

@ -15,10 +15,19 @@ var db = app.db;
chai.use(http);
function register(user, cb) {
chai.request(server)
.post('/api/auth/register')
.send(user)
.end(cb);
}
before(function (done) {
async.parallel([
async.series([
function (cb) {
db.once('open', cb);
db.once('open', function() {
cb();
});
},
function (cb) {
User.remove({}, function (err) {
@ -45,6 +54,19 @@ before(function (done) {
inv.save(function (err) {
cb(err);
});
},
function (cb) {
var inv = new Invite();
inv.code = 'TestCode3';
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
inv.exp = yesterday;
inv.scope = ['test.perm', 'file.upload'];
inv.save(function (err) {
cb(err);
});
}
], function (err) {
if (err) console.log(err);
@ -61,10 +83,7 @@ describe('Users', function () {
invite: 'TestCode1'
};
chai.request(server)
.post('/api/auth/register')
.send(user)
.end(function (err, res) {
register(user, function(err, res) {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('token');
@ -79,10 +98,7 @@ describe('Users', function () {
invite: 'TestCode2'
};
chai.request(server)
.post('/api/auth/register')
.send(user)
.end(function (err, res) {
register(user, function(err, res) {
res.should.have.status(401);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Username in use.');
@ -97,10 +113,7 @@ describe('Users', function () {
invite: 'bogus'
};
chai.request(server)
.post('/api/auth/register')
.send(user)
.end(function(err, res) {
register(user, function(err, res) {
res.should.have.a.status(401);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Invalid invite code.');
@ -115,10 +128,7 @@ describe('Users', function () {
invite: 'TestCode1'
};
chai.request(server)
.post('/api/auth/register')
.send(user)
.end(function(err, res) {
register(user, function(err, res) {
res.should.have.a.status(401);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Invalid invite code.');
@ -126,7 +136,20 @@ describe('Users', function () {
});
});
//TODO: Make sure expired invites don't work
it('SHOULD NOT register valid user, expired invite', function(done) {
var user = {
username: 'TestUser3',
password: 'TestPassword',
invite: 'TestCode3'
};
register(user, function(err, res) {
res.should.have.a.status(401);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Invalid invite code.');
done();
})
})
});
});