diff --git a/js/apps/system/sessions/.gitignore b/js/apps/system/sessions/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/js/apps/system/sessions/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/js/apps/system/sessions/errors.js b/js/apps/system/sessions/errors.js index b55816c382..b6b1686244 100644 --- a/js/apps/system/sessions/errors.js +++ b/js/apps/system/sessions/errors.js @@ -2,14 +2,19 @@ /*global require, exports */ (function () { 'use strict'; - function SessionNotFound(sid) { 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(); function SessionExpired(sid) { 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); diff --git a/js/apps/system/sessions/package.json b/js/apps/system/sessions/package.json new file mode 100644 index 0000000000..b0ca357fbe --- /dev/null +++ b/js/apps/system/sessions/package.json @@ -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" + } +} diff --git a/js/apps/system/sessions/test/errors.js b/js/apps/system/sessions/test/errors.js new file mode 100644 index 0000000000..f56fd29f6c --- /dev/null +++ b/js/apps/system/sessions/test/errors.js @@ -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); + }); + }); + }); + }); +}()); \ No newline at end of file diff --git a/js/apps/system/sessions/test/setup.js b/js/apps/system/sessions/test/setup.js new file mode 100644 index 0000000000..be55a700e9 --- /dev/null +++ b/js/apps/system/sessions/test/setup.js @@ -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); + }); + }); +}()); \ No newline at end of file diff --git a/js/apps/system/users/errors.js b/js/apps/system/users/errors.js index b8fb47e405..ed9ee667e9 100644 --- a/js/apps/system/users/errors.js +++ b/js/apps/system/users/errors.js @@ -2,7 +2,6 @@ /*global require, exports */ (function () { 'use strict'; - function UserNotFound(uid) { this.message = 'User with user id ' + uid + ' not found.'; var err = new Error(this.message); diff --git a/js/apps/system/users/package.json b/js/apps/system/users/package.json index e05d10d5ca..b0ca357fbe 100644 --- a/js/apps/system/users/package.json +++ b/js/apps/system/users/package.json @@ -2,11 +2,9 @@ "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" + "sinon": "^1.10.3" }, "scripts": { "test": "mocha --growl"