1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-01 14:54:43 -05:00
shimapan/test/api.js

151 lines
4.3 KiB
JavaScript
Raw Normal View History

process.env.NODE_ENV = 'test';
var async = require('async');
var mongoose = require('mongoose');
var User = require('../app/models/User.js');
var Invite = require('../app/models/Invite.js');
2017-10-13 18:08:13 -04:00
var Upload = require('../app/models/Upload.js');
var Token = require('../app/models/Token.js');
var chai = require('chai');
var should = chai.should();
var app = require('../server');
var server = app.server;
2017-10-13 18:08:13 -04:00
var util = require('./testUtil.js');
before(function (done) {
async.series([
function (cb) {
2017-10-13 18:08:13 -04:00
util.resetDatabase(cb);
},
2017-10-13 18:08:13 -04:00
function(cb) {
util.createInvites([{
code: 'TestCode1',
scope: ['test.perm']
}, {
code: 'TestCode2'
}, {
code: 'TestCode3',
exp: new Date()
2017-10-13 18:08:13 -04:00
}
], cb);
}
], function (err) {
if (err) console.log(err);
done();
});
});
describe('Users', function () {
describe('/POST register', function () {
it('SHOULD register valid user, valid invite', function (done) {
2017-10-13 18:08:13 -04:00
util.verifySuccessfulRegister({
username: 'TestUser1',
password: 'TestPassword',
invite: 'TestCode1'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD register another valid user, valid invite', function(done) {
2017-10-13 18:08:13 -04:00
util.verifySuccessfulRegister({
username: 'TestUser2',
password: 'TestPassword',
invite: 'TestCode2'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT register invalid user, valid invite', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedUserRegister({
username: 'TestUser1',
password: 'TestPassword',
invite: 'TestCode2'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT register valid user, nonexistant invite', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedInviteRegister({
username: 'TestUser3',
password: 'TestPassword',
invite: 'bogus'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT register valid user, used invite', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedInviteRegister({
username: 'TestUser3',
password: 'TestPassword',
invite: 'TestCode1'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT register valid user, expired invite', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedInviteRegister({
username: 'TestUser3',
password: 'TestPassword',
invite: 'TestCode3'
2017-10-13 18:08:13 -04:00
}, done);
})
});
describe('/POST login', function () {
it('SHOULD accept valid user, valid password', function (done) {
2017-10-13 18:08:13 -04:00
util.verifySuccessfulLogin({
username: 'TestUser1',
password: 'TestPassword'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT accept valid user, invalid password', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedPasswordLogin({
username: 'TestUser1',
password: 'bogus'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT accept invalid user, any password', function (done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedUsernameLogin({
username: 'BogusTestUser',
password: 'bogus'
2017-10-13 18:08:13 -04:00
}, done);
});
});
});
describe('Uploads', function () {
describe('/POST upload', function () {
it('SHOULD accept logged in valid upload', function(done) {
2017-10-13 18:08:13 -04:00
util.verifySuccessfulUpload({
username: 'TestUser2',
password: 'TestPassword'
2017-10-13 18:08:13 -04:00
}, done);
});
it('SHOULD NOT accept unauthenticated valid upload', function(done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedAuthUpload(done);
});
it('SHOULD NOT accept invalid permission, valid upload', function(done) {
2017-10-13 18:08:13 -04:00
util.verifyFailedPermissionUpload({
username: 'TestUser1',
password: 'TestPassword'
2017-10-13 18:08:13 -04:00
}, done);
});
2017-10-13 18:08:13 -04:00
it('SHOULD NOT accept invalid size upload', function(done) {
util.verifyFailedSizeUpload({
username: 'TestUser2',
password: 'TestPassword'
}, done);
})
});
});
after(function () {
server.close(function () {
process.exit();
});
});