mirror of https://gitee.com/bigwinds/arangodb
Added tests for users app setup and error types.
This commit is contained in:
parent
c42628f0c5
commit
c8d1f5f93b
|
@ -0,0 +1 @@
|
|||
node_modules
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"joi": "^4.6.2",
|
||||
"mocha": "^1.21.4",
|
||||
"mockuire": "^0.1.0",
|
||||
"sinon": "^1.10.3",
|
||||
"underscore": "^1.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --growl"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 120, es5: true */
|
||||
/*global require, describe, it */
|
||||
(function () {
|
||||
'use strict';
|
||||
var expect = require('expect.js'),
|
||||
errors = require('../errors');
|
||||
|
||||
describe('errors', function () {
|
||||
['UserNotFound', 'UsernameNotAvailable'].forEach(function (name) {
|
||||
describe(name, function () {
|
||||
var UserError = errors[name];
|
||||
it('is a constructor', function () {
|
||||
expect(new UserError()).to.be.a(UserError);
|
||||
});
|
||||
it('creates an Error', function () {
|
||||
expect(new UserError()).to.be.an(Error);
|
||||
});
|
||||
it('uses its argument in its message', function () {
|
||||
var err = new UserError('potato');
|
||||
expect(err.message).to.contain('potato');
|
||||
});
|
||||
it('uses its message in its stack trace', function () {
|
||||
var err = new UserError('potato');
|
||||
expect(err.stack).to.contain(err.message);
|
||||
});
|
||||
it('uses its name in its stack trace', function () {
|
||||
var err = new UserError('potato');
|
||||
expect(err.stack).to.contain(name);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -0,0 +1,45 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 120, es5: true */
|
||||
/*global require, module, describe, it, beforeEach */
|
||||
(function () {
|
||||
'use strict';
|
||||
var sinon = require('sinon'),
|
||||
expect = require('expect.js'),
|
||||
mockuire;
|
||||
|
||||
mockuire = require('mockuire')(module, {
|
||||
'js': {compile: function (src) {
|
||||
return 'var applicationContext = require("applicationContext");\n' + src;
|
||||
}}
|
||||
});
|
||||
|
||||
describe('setup.js', function () {
|
||||
var db = {}, ctx = {};
|
||||
|
||||
beforeEach(function () {
|
||||
ctx.collectionName = sinon.stub();
|
||||
db._collection = sinon.stub();
|
||||
db._create = sinon.stub();
|
||||
});
|
||||
|
||||
it('creates a users collection if it does not exist', function () {
|
||||
ctx.collectionName.withArgs('users').returns('magic');
|
||||
db._collection.returns(null);
|
||||
mockuire('../setup', {
|
||||
applicationContext: ctx,
|
||||
'org/arangodb': {db: db}
|
||||
});
|
||||
expect(db._create.callCount).to.equal(1);
|
||||
expect(db._create.args[0]).to.eql(['magic']);
|
||||
});
|
||||
|
||||
it('does not overwrite an existing collection', function () {
|
||||
ctx.collectionName.returns('magic');
|
||||
db._collection.returns({});
|
||||
mockuire('../setup', {
|
||||
applicationContext: ctx,
|
||||
'org/arangodb': {db: db}
|
||||
});
|
||||
expect(db._create.callCount).to.equal(0);
|
||||
});
|
||||
});
|
||||
}());
|
Loading…
Reference in New Issue