mirror of https://gitee.com/bigwinds/arangodb
Added more Foxx app unit tests.
This commit is contained in:
parent
cc58900515
commit
172e1b936d
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
|
@ -2,14 +2,19 @@
|
||||||
/*global require, exports */
|
/*global require, exports */
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function SessionNotFound(sid) {
|
function SessionNotFound(sid) {
|
||||||
this.message = 'Session with session id ' + sid + ' not found.';
|
this.message = 'Session with session id ' + sid + ' not found.';
|
||||||
|
var err = new Error(this.message);
|
||||||
|
err.name = this.constructor.name;
|
||||||
|
this.stack = err.stack;
|
||||||
}
|
}
|
||||||
SessionNotFound.prototype = new Error();
|
SessionNotFound.prototype = new Error();
|
||||||
|
|
||||||
function SessionExpired(sid) {
|
function SessionExpired(sid) {
|
||||||
this.message = 'Session with session id ' + sid + ' has expired.';
|
this.message = 'Session with session id ' + sid + ' has expired.';
|
||||||
|
var err = new Error(this.message);
|
||||||
|
err.name = this.constructor.name;
|
||||||
|
this.stack = err.stack;
|
||||||
}
|
}
|
||||||
SessionExpired.prototype = Object.create(SessionNotFound.prototype);
|
SessionExpired.prototype = Object.create(SessionNotFound.prototype);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"devDependencies": {
|
||||||
|
"expect.js": "^0.3.1",
|
||||||
|
"mocha": "^1.21.4",
|
||||||
|
"mockuire": "^0.1.0",
|
||||||
|
"sinon": "^1.10.3"
|
||||||
|
},
|
||||||
|
"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 () {
|
||||||
|
['SessionNotFound', 'SessionExpired'].forEach(function (name) {
|
||||||
|
describe(name, function () {
|
||||||
|
var SessionError = errors[name];
|
||||||
|
it('is a constructor', function () {
|
||||||
|
expect(new SessionError()).to.be.a(SessionError);
|
||||||
|
});
|
||||||
|
it('creates an Error', function () {
|
||||||
|
expect(new SessionError()).to.be.an(Error);
|
||||||
|
});
|
||||||
|
it('uses its argument in its message', function () {
|
||||||
|
var err = new SessionError('potato');
|
||||||
|
expect(err.message).to.contain('potato');
|
||||||
|
});
|
||||||
|
it('uses its message in its stack trace', function () {
|
||||||
|
var err = new SessionError('potato');
|
||||||
|
expect(err.stack).to.contain(err.message);
|
||||||
|
});
|
||||||
|
it('uses its name in its stack trace', function () {
|
||||||
|
var err = new SessionError();
|
||||||
|
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 sessions collection if it does not exist', function () {
|
||||||
|
ctx.collectionName.withArgs('sessions').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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}());
|
|
@ -2,7 +2,6 @@
|
||||||
/*global require, exports */
|
/*global require, exports */
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function UserNotFound(uid) {
|
function UserNotFound(uid) {
|
||||||
this.message = 'User with user id ' + uid + ' not found.';
|
this.message = 'User with user id ' + uid + ' not found.';
|
||||||
var err = new Error(this.message);
|
var err = new Error(this.message);
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"expect.js": "^0.3.1",
|
"expect.js": "^0.3.1",
|
||||||
"joi": "^4.6.2",
|
|
||||||
"mocha": "^1.21.4",
|
"mocha": "^1.21.4",
|
||||||
"mockuire": "^0.1.0",
|
"mockuire": "^0.1.0",
|
||||||
"sinon": "^1.10.3",
|
"sinon": "^1.10.3"
|
||||||
"underscore": "^1.6.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --growl"
|
"test": "mocha --growl"
|
||||||
|
|
Loading…
Reference in New Issue