'use strict';
const Code = require('code');
const Hoek = require('hoek');
const Lab = require('lab');

// Internals
const Suite = require('../test/user.suite');
const Forger = require('forger');
const Sinon = require('sinon');

// Helpers
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const before = lab.before;
const beforeEach = lab.beforeEach;
const afterEach = lab.afterEach;
const after = lab.after;
const it = lab.it;
const expect = Code.expect;

before(Suite.setupServer);
before(Suite.db.connect);
after(Suite.db.dropDatabase);
after(Suite.db.disconnect);

describe('POST /auth/signup', () => {

	beforeEach(Suite.db.resetDatabase);

	it('should reply successfully (200) with token', (done) => {
		Suite.server.inject({
Example #2
0
var Handlebars = require('handlebars');
var Hapi = require('..');
var Hoek = require('hoek');
var Inert = require('inert');
var Lab = require('lab');
var Vision = require('vision');


// Declare internals

var internals = {};


// Test shortcuts

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;


describe('handler', function () {

    describe('execute()', function () {

        it('returns 500 on handler exception (same tick)', function (done) {

            var server = new Hapi.Server({ debug: false });
            server.connection();

            var handler = function (request) {
Example #3
0
import empty        from '../src';
import { expect }   from './instrument';
import Lab          from 'lab';

var lab = Lab.script();
var { describe
    , it } = lab;
export { lab };

var throwing = function(schema, err = Error) {
  var f = function() {
    return empty(schema);
  };

  expect(f).to.throw(err);
};


describe('errors', function() {

  it('should error on unknown type', function(done) {
    throwing({
      type: 'bla'
    });
    done();
  });

  it('should error when no schema is passed', function(done) {
    throwing();
    done();
  });
Example #4
0
"use strict";
var Hapi = require('hapi');
var Code = require('code');
var Lab = require('lab');
var Sinon = require('sinon');
var AmmaDb = require('../../../index');
var Mongoose = require('mongoose');
var lab = exports.lab = Lab.script(), before = lab.before, beforeEach = lab.beforeEach, afterEach = lab.afterEach, after = lab.after, expect = Code.expect, suite = lab.suite, test = lab.test;
suite('Test DB Server', function () {
    var server;
    suite('Test ConnectDB function', function () {
        beforeEach(function (next) {
            server = new Hapi.Server({
                app: {
                    db: {
                        uri: 'test',
                        options: {}
                    }
                }
            });
            next();
        });
        test('Successful connection', function (next) {
            var stub = Sinon.stub(Mongoose, 'connect', function (uri, options, done) {
                return done();
            });
            server.register({ register: AmmaDb }, function (err) {
                expect(err).to.equal(undefined);
                stub.restore();
                next();
            });
function apiv2 (settings) {
  var si = settings.seneca
  var script = settings.script || Lab.script()

  var describe = script.describe
  var before = script.before
  var it = script.it

  describe('Sql extended support', function () {
    before(function (done) {
      var Product = si.make('product')

      Async.series([
        function clear (next) {
          Product.remove$({all$: true}, next)
        },
        function create (next) {
          var products = [
            Product.make$({name: 'apple', price: 100}),
            Product.make$({name: 'pear', price: 200}),
            Product.make$({name: 'cherry', price: 300})
          ]

          function saveproduct (product, saved) {
            product.save$(saved)
          }

          Async.forEach(products, saveproduct, next)
        }
      ], function (err) {
        assert(!err)
        done()
      })
    })

    it('use not equal ne$', function (done) {
      var product = si.make('product')

      product.list$({price: {ne$: 200}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('apple', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use not equal ne$ string', function (done) {
      var product = si.make('product')

      product.list$({name: {ne$: 'pear'}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('apple', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use eq$', function (done) {
      var product = si.make('product')

      product.list$({price: {eq$: 200}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('pear', lst[0].name)
        done()
      })
    })

    it('use eq$ string', function (done) {
      var product = si.make('product')

      product.list$({name: {eq$: 'pear'}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('pear', lst[0].name)
        done()
      })
    })

    it('use gte$', function (done) {
      var product = si.make('product')

      product.list$({price: {gte$: 200}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('pear', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use gt$', function (done) {
      var product = si.make('product')

      product.list$({price: {gt$: 200}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('cherry', lst[0].name)
        done()
      })
    })

    it('use lte$', function (done) {
      var product = si.make('product')

      product.list$({price: {lte$: 200}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('apple', lst[0].name)
        assert.equal('pear', lst[1].name)
        done()
      })
    })

    it('use lt$', function (done) {
      var product = si.make('product')

      product.list$({price: {lt$: 200}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('apple', lst[0].name)
        done()
      })
    })

    it('use in$', function (done) {
      var product = si.make('product')

      product.list$({price: {in$: [200, 300]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('pear', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use in$ string', function (done) {
      var product = si.make('product')

      product.list$({name: {in$: ['cherry', 'pear']}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('pear', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use in$ one matching', function (done) {
      var product = si.make('product')

      product.list$({price: {in$: [200, 500, 700]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('pear', lst[0].name)
        done()
      })
    })

    it('use in$ no matching', function (done) {
      var product = si.make('product')

      product.list$({price: {in$: [250, 500, 700]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(0, lst.length)
        done()
      })
    })

    it('use nin$ three matching', function (done) {
      var product = si.make('product')

      product.list$({price: {nin$: [250, 500, 700]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(3, lst.length)
        done()
      })
    })

    it('use nin$ one matching', function (done) {
      var product = si.make('product')

      product.list$({price: {nin$: [200, 500, 300]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('apple', lst[0].name)
        done()
      })
    })

    it('use complex in$ and nin$', function (done) {
      var product = si.make('product')

      product.list$({price: {nin$: [250, 500, 300], in$: [200, 300]}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('pear', lst[0].name)
        done()
      })
    })

    it('use nin$ string', function (done) {
      var product = si.make('product')

      product.list$({name: {nin$: ['cherry', 'pear']}, sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('apple', lst[0].name)
        done()
      })
    })

    it('use or$', function (done) {
      var product = si.make('product')

      product.list$({or$: [{name: 'cherry'}, {price: 200}], sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('pear', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use and$', function (done) {
      var product = si.make('product')

      product.list$({and$: [{name: 'cherry'}, {price: 300}], sort$: {price: 1}}, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('cherry', lst[0].name)
        done()
      })
    })

    it('use and$ & or$', function (done) {
      var product = si.make('product')

      product.list$({
        or$: [{price: {gte$: 200}}, {and$: [{name: 'cherry'}, {price: 300}]}],
        sort$: {price: 1}
      }, function (err, lst) {
        assert(!err)

        assert.equal(2, lst.length)
        assert.equal('pear', lst[0].name)
        assert.equal('cherry', lst[1].name)
        done()
      })
    })

    it('use and$ & or$ and limit$', function (done) {
      var product = si.make('product')

      product.list$({
        or$: [{price: {gte$: 200}}, {and$: [{name: 'cherry'}, {price: 300}]}],
        sort$: {price: 1},
        limit$: 1,
        fields$: ['name']
      }, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('pear', lst[0].name)
        assert(!lst[0].price)
        done()
      })
    })

    it('use and$ & or$ and limit$, fields$ and skip$', function (done) {
      var product = si.make('product')

      product.list$({
        price: {gte$: 200},
        sort$: {price: 1},
        limit$: 1,
        fields$: ['name', 'id'],
        skip$: 1
      }, function (err, lst) {
        assert(!err)

        assert.equal(1, lst.length)
        assert.equal('cherry', lst[0].name)
        assert(!lst[0].price)
        done()
      })
    })
  })

  return script
}
Example #6
0
var Code    = require('code'),
    Lab     = require('lab'),
    lab     = exports.lab 
            = Lab.script();

var describe    = lab.describe,
    it          = lab.it,
    before      = lab.before,
    after       = lab.after,
    expect      = Code.expect;

var StatsHandler    = require('../js/utils/statshandler'),
    testRatings     = require('./data/test_ratings.json');

describe('stats', function () {
    it('should create data', function (done) {
        StatsHandler.transformRatingsToChart(testRatings);
        var data = StatsHandler.getData();

        expect(data.labels.length).to.equal(data.charts[0].length);

        done();
    });

    it('should create tow identical charts', function (done) {
        StatsHandler.resetData();

        StatsHandler.transformRatingsToChart(testRatings);
        StatsHandler.transformRatingsToChart(testRatings);

        var data = StatsHandler.getData();
Example #7
0
const Path = require('path');
const Stream = require('stream');

const Code = require('code');
const Handlebars = require('handlebars');
const Hapi = require('..');
const Inert = require('inert');
const Lab = require('lab');
const Teamwork = require('teamwork');
const Vision = require('vision');


const internals = {};


const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;


describe('Toolkit', () => {

    describe('Manager', () => {

        describe('decorate()', () => {

            it('decorates toolkit with non function', async () => {

                const server = Hapi.server();

                server.decorate('toolkit', 'abc', 123);
'use strict';

const Code = require('code');
const Lab = require('lab');
const lab = (exports.lab = Lab.script());
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const dbmUtil = require('db-migrate-shared').util;

const rmdir = require('rimraf');

function wipeMigrations (callback) {
  const dir = path.join(__dirname, 'migrations');
  rmdir(dir, callback);
}

function dbMigrate () {
  const args = dbmUtil.toArray(arguments);
  const dbm = path.join(__dirname, '..', '..', 'bin', 'db-migrate');
  args.unshift(dbm);
  return cp.spawn('node', args, { cwd: __dirname });
}

lab.experiment('create', function () {
  lab.experiment('without a migration directory', function () {
    let exitCode;

    lab.before(function (done) {
      wipeMigrations(function (err) {
        Code.expect(err).to.be.null();
Example #9
0
import Lab from "lab";
import RSVP from "rsvp";
import assert from "assert";
import * as serverLib from "../../src/server";
import * as Post from "../../src/models/posts";
import * as Revision from "../../src/models/posts";
import * as testCommon from "./commons";


export const lab = Lab.script();


const { describe, it } = lab;
const { createModel } = testCommon;


describe("Posts", () => {

  let server = null;

  const username = "******";
  const password = "******";

  lab.before(async done => {
    const hapiInstance = await serverLib.getServer({
      ENV: "test",
      //
      // hopefully zero log output
      //
      LOG_LEVEL: "fatal",
      DB_URL: "mongodb://localhost:27017/akst-io-test",
"use strict";
var Hapi = require('hapi');
var Code = require('code');
var Lab = require('lab');
var Sinon = require('sinon');
var EventLoader = require('../../services/event.loader');
var lab = exports.lab = Lab.script(), expect = Code.expect, before = lab.before, suite = lab.suite, test = lab.test;
var SampleClass = (function () {
    function SampleClass() {
        this.method = function () {
        };
    }
    return SampleClass;
}());
var SampleConfig = [{
        methodName: 'method',
        type: 'onRequest',
        options: {}
    }];
suite('Event Loader', function () {
    var server = new Hapi.Server();
    var eventLoader = new EventLoader.default();
    var cls = new SampleClass();
    before(function (next) {
        eventLoader.setServer(server);
        next();
    });
    test('Load Events', function (next) {
        var cls = new SampleClass();
        var stub = Sinon.stub(server, 'ext', function (type, func, options) {
            expect(type).to.be.equal('onRequest');
Example #11
0
'use strict'

var Lab = require('lab')

var lab = (exports.lab = Lab.script())
var describe = lab.describe

var CacheTest = require('../')

describe('No Tests', function() {})