diff --git a/js/apps/system/users/.gitignore b/js/apps/system/users/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/js/apps/system/users/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/js/apps/system/users/package.json b/js/apps/system/users/package.json new file mode 100644 index 0000000000..e05d10d5ca --- /dev/null +++ b/js/apps/system/users/package.json @@ -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" + } +} diff --git a/js/apps/system/users/test/errors.js b/js/apps/system/users/test/errors.js new file mode 100644 index 0000000000..bab4135536 --- /dev/null +++ b/js/apps/system/users/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 () { + ['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); + }); + }); + }); + }); +}()); \ No newline at end of file diff --git a/js/apps/system/users/test/setup.js b/js/apps/system/users/test/setup.js new file mode 100644 index 0000000000..a87fdbf57b --- /dev/null +++ b/js/apps/system/users/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 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); + }); + }); +}()); \ No newline at end of file