<commit_before>var ip = '127.0.0.1';
var port = '8000';
var address = ip + ':' + port;

var oneDay = 86400;

function runClient() {

    if (!Date.now) {
        Date.now = function() { return new Date().getTime(); };
    }
    var currentTime = Date.now();
    var tomorrow = currentTime + oneDay;

    var addcheduleParameters = {
                                    msgType: 'addSchedule',
                                    usersid: '1',
                                    eventsid: '1',
                                    availability: [ { start: currentTime, end: currentTime },
                                                    { start: currentTime, end: currentTime } ]
                            };

    var addEventParameters = {
                                msgType: 'addEvent',
                                eventName: 'meeting',
                                eventStartDate: currentTime,
                                eventEndDate: tomorrow,
                                eventDescription: 'this meeting needs to be today'
                            };

    var updateEventParameters = {
                                msgType: 'updateEvent',
                                eventName: 'gathering',
                                eventStartDate: currentTime,
                                eventEndDate: tomorrow,
                                eventDescription: 'this meeting needs to be tomorrow',
                                eventsid: '2'
                            };

    send(updateEventParameters);
    //send(addEventParameters);
    //send(addScheduleParameters);
}

function send(msgParameters) {
    var sendRequest = new XMLHttpRequest();

    sendRequest.onreadystatechange = function(event) {
        if (sendRequest.readyState === 4) {
            if (sendRequest.status === 200) {
                //response from server
                handleData(sendRequest.responseText);
            }
        }
    };

    sendRequest.open('POST', address, true);
    sendRequest.send(JSON.stringify(msgParameters));
}

function handleData(response) {
    document.getElementById('return').innerHTML = response;
}<commit_msg>#14 - fix the typo chedule<commit_after>var ip = '127.0.0.1';
var port = '8000';
var address = ip + ':' + port;

var oneDay = 86400;

function runClient() {

    if (!Date.now) {
        Date.now = function() { return new Date().getTime(); };
    }
    var currentTime = Date.now();
    var tomorrow = currentTime + oneDay;

    var addScheduleParameters = {
                                    msgType: 'addSchedule',
                                    usersid: '1',
                                    eventsid: '1',
                                    availability: [ { start: currentTime, end: currentTime },
                                                    { start: currentTime, end: currentTime } ]
                            };

    var addEventParameters = {
                                msgType: 'addEvent',
                                eventName: 'meeting',
                                eventStartDate: currentTime,
                                eventEndDate: tomorrow,
                                eventDescription: 'this meeting needs to be today'
                            };

    var updateEventParameters = {
                                msgType: 'updateEvent',
                                eventName: 'gathering',
                                eventStartDate: currentTime,
                                eventEndDate: tomorrow,
                                eventDescription: 'this meeting needs to be tomorrow',
                                eventsid: '2'
                            };

    send(updateEventParameters);
    //send(addEventParameters);
    //send(addScheduleParameters);
}

function send(msgParameters) {
    var sendRequest = new XMLHttpRequest();

    sendRequest.onreadystatechange = function(event) {
        if (sendRequest.readyState === 4) {
            if (sendRequest.status === 200) {
                //response from server
                handleData(sendRequest.responseText);
            }
        }
    };

    sendRequest.open('POST', address, true);
    sendRequest.send(JSON.stringify(msgParameters));
}

function handleData(response) {
    document.getElementById('return').innerHTML = response;
}<|endoftext|>


<commit_before>describe('type', function() {

    it('isExisty()', function() {
        var o1 = null,
            o2 = 3,
            o3 = 0,
            o4 = {},
            o5 = false,
            o6 = isNaN,
            o7;

        expect(ne.util.isExisty(o1)).toBe(false);
        expect(ne.util.isExisty(o2)).toBe(true);
        expect(ne.util.isExisty(o3)).toBe(true);
        expect(ne.util.isExisty(o4.test)).toBe(false);
        expect(ne.util.isExisty(o5)).toBe(true);
        expect(ne.util.isExisty(o6)).toBe(true);
        expect(ne.util.isExisty(o7)).toBe(false);
    });

    it('isExisty() second params', function() {
        var o1 = { a: 10 },
            o2 = { a: { b: '10' }};

        expect(ne.util.isExisty(o1, 'a')).toBeTruthy();
        expect(ne.util.isExisty(o2, 'a.b')).toBeTruthy();
        expect(ne.util.isExisty(o2, 'a.c')).toBeFalsy();
        expect(ne.util.isExisty()).toBeFalsy();

    });

    it('isTruthy()', function() {
        var o1 = 0,
            o2 = false,
            o3 = '',
            o4 = null,
            o5;

        expect(ne.util.isTruthy(o1)).toBe(true);
        expect(ne.util.isTruthy(o2)).toBe(false);
        expect(ne.util.isTruthy(o3)).toBe(true);
        expect(ne.util.isTruthy(o4)).toBe(false);
        expect(ne.util.isTruthy(o5)).toBe(false);
    });

    it('isFalsy()', function() {
        var o1 = 0,
            o2 = false,
            o3 = '',
            o4 = null,
            o5;

        expect(ne.util.isFalsy(o1)).toBe(false);
        expect(ne.util.isFalsy(o2)).toBe(true);
        expect(ne.util.isFalsy(o3)).toBe(false);
        expect(ne.util.isFalsy(o4)).toBe(true);
        expect(ne.util.isFalsy(o5)).toBe(true);
    });

    it('isArguments()', function() {
        var o1,
            o2 = [];

        (function() {
            o1 = arguments;
        })();

        expect(ne.util.isArguments(o1)).toBe(true);
        expect(ne.util.isArguments(o2)).toBe(false);
    });

    it('isArray()', function() {
        var o1 = new Array(3),
            o2 = [],
            o3 = 'array',
            o4 = 3,
            o5 = function() {},
            o6 = new Object(),
            o7 = {};

        expect(ne.util.isArray(o1)).toBe(true);
        expect(ne.util.isArray(o2)).toBe(true);
        expect(ne.util.isArray(o3)).toBe(false);
        expect(ne.util.isArray(o4)).toBe(false);
        expect(ne.util.isArray(o5)).toBe(false);
        expect(ne.util.isArray(o6)).toBe(false);
        expect(ne.util.isArray(o7)).toBe(false);
    });

    it('isObject()', function() {
        var o1 = new Object(),
            o2 = {},
            o3 = { test: {} },
            o4 = 'a',
            o5 = function() {},
            o6 = new o5(),
            o7 = /xyz/g,
            o8 = new Date(),
            o9 = new Function('x', 'y', 'return x + y');

        expect(ne.util.isObject(o1)).toBe(true);
        expect(ne.util.isObject(o2)).toBe(true);
        expect(ne.util.isObject(o3.test)).toBe(true);
        expect(ne.util.isObject(o4)).toBe(false);
        expect(ne.util.isObject(o5)).toBe(true);
        expect(ne.util.isObject(o6)).toBe(true);
        expect(ne.util.isObject(o7)).toBe(true);
        expect(ne.util.isObject(o8)).toBe(true);
        expect(ne.util.isObject(o9)).toBe(true);
    });

    it('isFunction()', function() {
        var o1 = function() {},
            o2 = {},
            o3 = '',
            o4 = [],
            o5 = 1,
            o6 = true,
            o7 = /xyz/g,
            o8 = new Function(),
            o9 = function test() {};

        expect(ne.util.isFunction(o1)).toBe(true);
        expect(ne.util.isFunction(o2)).toBe(false);
        expect(ne.util.isFunction(o3)).toBe(false);
        expect(ne.util.isFunction(o4)).toBe(false);
        expect(ne.util.isFunction(o5)).toBe(false);
        expect(ne.util.isFunction(o6)).toBe(false);
        expect(ne.util.isFunction(o7)).toBe(false);
        expect(ne.util.isFunction(o8)).toBe(true);
        expect(ne.util.isFunction(o9)).toBe(true);
    });

    it('isNumber()', function() {
        var o1 = 1,
            o2 = new Number(2),
            o3 = { test: 1 },
            o4 = [],
            o5 = 'string',
            o6 = true,
            o7 = /xyz/g,
            o8 = 4 + 5,
            o9 = parseFloat('12.5'),
            o10 = 0x15,
            o11 = parseInt('00101', 2);

        expect(ne.util.isNumber(o1)).toBe(true);
        expect(ne.util.isNumber(o2)).toBe(true);
        expect(ne.util.isNumber(o3.test)).toBe(true);
        expect(ne.util.isNumber(o3)).toBe(false);
        expect(ne.util.isNumber(o4)).toBe(false);
        expect(ne.util.isNumber(o5)).toBe(false);
        expect(ne.util.isNumber(o6)).toBe(false);
        expect(ne.util.isNumber(o7)).toBe(false);
        expect(ne.util.isNumber(o8)).toBe(true);
        expect(ne.util.isNumber(o9)).toBe(true);
        expect(ne.util.isNumber(o11)).toBe(true);

    });

    it('isString()', function() {
        var o1 = {},
            o2 = new String('a'),
            o3 = 'string',
            o4 = [],
            o5 = '',
            o6 = true,
            o7 = /xyz/g;

        expect(ne.util.isString(o1)).toBe(false);
        expect(ne.util.isString(o2)).toBe(true);
        expect(ne.util.isString(o3)).toBe(true);
        expect(ne.util.isString(o4)).toBe(false);
        expect(ne.util.isString(o5)).toBe(true);
        expect(ne.util.isString(o6)).toBe(false);
        expect(ne.util.isString(o7)).toBe(false);
    });

    it('isBoolean()', function() {
        var o1 = {},
            o2 = new Boolean('true'),
            o3 = 1,
            o4 = true,
            o5 = false,
            o6 = undefined,
            o7 = null;

        expect(ne.util.isBoolean(o1)).toBe(false);
        expect(ne.util.isBoolean(o2)).toBe(true);
        expect(ne.util.isBoolean(o3)).toBe(false);
        expect(ne.util.isBoolean(o4)).toBe(true);
        expect(ne.util.isBoolean(o5)).toBe(true);
        expect(ne.util.isBoolean(o6)).toBe(false);
        expect(ne.util.isBoolean(o7)).toBe(false);
    });

    it('isHTMLNode()', function() {

        var text = document.createTextNode("Hello World"),
            el1 = document.createElement("H1"),
            el2 = document.createElement("A"),
            el3 = document.createElement("SPAN"),
            el4 = document.createElement("P"),
            el5 = document.createElement("PRE"),
            el6 = document.createElement("DIV"),
            el7 = document.createElement("INPUT"),
            myObj = 3,
            testObj = {};

        expect(ne.util.isHTMLNode(el1)).toBe(true);
        expect(ne.util.isHTMLNode(el2)).toBe(true);
        expect(ne.util.isHTMLNode(el3)).toBe(true);
        expect(ne.util.isHTMLNode(el4)).toBe(true);
        expect(ne.util.isHTMLNode(el5)).toBe(true);
        expect(ne.util.isHTMLNode(el6)).toBe(true);
        expect(ne.util.isHTMLNode(el7)).toBe(true);
        expect(ne.util.isHTMLNode(text)).toBe(true);
        expect(ne.util.isHTMLNode(myObj)).toBe(false);
        expect(ne.util.isHTMLNode(testObj)).toBe(false);
    });

    it('isHTMLTag()', function() {
        var text = document.createTextNode("Hello World"),
            el1 = document.createElement("H1"),
            el2 = document.createElement("A"),
            el3 = document.createElement("SPAN"),
            el4 = document.createElement("P"),
            el5 = document.createElement("PRE"),
            el6 = document.createElement("DIV"),
            el7 = document.createElement("INPUT"),
            myObj = 3,
            testObj = {};

        expect(ne.util.isHTMLTag(el1)).toBe(true);
        expect(ne.util.isHTMLTag(el2)).toBe(true);
        expect(ne.util.isHTMLTag(el3)).toBe(true);
        expect(ne.util.isHTMLTag(el4)).toBe(true);
        expect(ne.util.isHTMLTag(el5)).toBe(true);
        expect(ne.util.isHTMLTag(el6)).toBe(true);
        expect(ne.util.isHTMLTag(el7)).toBe(true);

        expect(ne.util.isHTMLTag(text)).toBe(false);
        expect(ne.util.isHTMLTag(myObj)).toBe(false);
        expect(ne.util.isHTMLTag(testObj)).toBe(false);
    });

    it('isEmpty()', function() {
        var o1 = {},
            o2 = { test: 1},
            o3 = new Object(),
            o4 = [],
            o5 = new Array(),
            o6 = [1, 3],
            o7 = function() {},
            o8,
            o9 = void 0,
            o10 = null,
            o11;

        (function() {
            o8 = arguments;
        })(2, 4);

        (function() {
            o11 = arguments;
        })();

        expect(ne.util.isEmpty(o1)).toBe(true);
        expect(ne.util.isEmpty(o2)).toBe(false);
        expect(ne.util.isEmpty(o3)).toBe(true);
        expect(ne.util.isEmpty(o4)).toBe(true);
        expect(ne.util.isEmpty(o5)).toBe(true);
        expect(ne.util.isEmpty(o6)).toBe(false);
        expect(ne.util.isEmpty(o7)).toBe(true);
        expect(ne.util.isEmpty(o8)).toBe(false);
        expect(ne.util.isEmpty(o9)).toBe(true);
        expect(ne.util.isEmpty(o10)).toBe(true);
        expect(ne.util.isEmpty(o11)).toBe(true);

    });

});
<commit_msg>type test추가<commit_after>describe('type', function() {

    it('isExisty()', function() {
        var o1 = null,
            o2 = 3,
            o3 = 0,
            o4 = {},
            o5 = false,
            o6 = isNaN,
            o7;

        expect(ne.util.isExisty(o1)).toBe(false);
        expect(ne.util.isExisty(o2)).toBe(true);
        expect(ne.util.isExisty(o3)).toBe(true);
        expect(ne.util.isExisty(o4.test)).toBe(false);
        expect(ne.util.isExisty(o5)).toBe(true);
        expect(ne.util.isExisty(o6)).toBe(true);
        expect(ne.util.isExisty(o7)).toBe(false);
    });

    it('isExisty() second params', function() {
        var o1 = { a: 10 },
            o2 = { a: { b: '10' }};

        expect(ne.util.isExisty(o1, 'a')).toBeTruthy();
        expect(ne.util.isExisty(o2, 'a.b')).toBeTruthy();
        expect(ne.util.isExisty(o2, ['a','b'])).toBeTruthy();
        expect(ne.util.isExisty(o2, 'a.c')).toBeFalsy();
        expect(ne.util.isExisty()).toBeFalsy();

    });

    it('isTruthy()', function() {
        var o1 = 0,
            o2 = false,
            o3 = '',
            o4 = null,
            o5;

        expect(ne.util.isTruthy(o1)).toBe(true);
        expect(ne.util.isTruthy(o2)).toBe(false);
        expect(ne.util.isTruthy(o3)).toBe(true);
        expect(ne.util.isTruthy(o4)).toBe(false);
        expect(ne.util.isTruthy(o5)).toBe(false);
    });

    it('isFalsy()', function() {
        var o1 = 0,
            o2 = false,
            o3 = '',
            o4 = null,
            o5;

        expect(ne.util.isFalsy(o1)).toBe(false);
        expect(ne.util.isFalsy(o2)).toBe(true);
        expect(ne.util.isFalsy(o3)).toBe(false);
        expect(ne.util.isFalsy(o4)).toBe(true);
        expect(ne.util.isFalsy(o5)).toBe(true);
    });

    it('isArguments()', function() {
        var o1,
            o2 = [];

        (function() {
            o1 = arguments;
        })();

        expect(ne.util.isArguments(o1)).toBe(true);
        expect(ne.util.isArguments(o2)).toBe(false);
    });

    it('isArray()', function() {
        var o1 = new Array(3),
            o2 = [],
            o3 = 'array',
            o4 = 3,
            o5 = function() {},
            o6 = new Object(),
            o7 = {};

        expect(ne.util.isArray(o1)).toBe(true);
        expect(ne.util.isArray(o2)).toBe(true);
        expect(ne.util.isArray(o3)).toBe(false);
        expect(ne.util.isArray(o4)).toBe(false);
        expect(ne.util.isArray(o5)).toBe(false);
        expect(ne.util.isArray(o6)).toBe(false);
        expect(ne.util.isArray(o7)).toBe(false);
    });

    it('isObject()', function() {
        var o1 = new Object(),
            o2 = {},
            o3 = { test: {} },
            o4 = 'a',
            o5 = function() {},
            o6 = new o5(),
            o7 = /xyz/g,
            o8 = new Date(),
            o9 = new Function('x', 'y', 'return x + y');

        expect(ne.util.isObject(o1)).toBe(true);
        expect(ne.util.isObject(o2)).toBe(true);
        expect(ne.util.isObject(o3.test)).toBe(true);
        expect(ne.util.isObject(o4)).toBe(false);
        expect(ne.util.isObject(o5)).toBe(true);
        expect(ne.util.isObject(o6)).toBe(true);
        expect(ne.util.isObject(o7)).toBe(true);
        expect(ne.util.isObject(o8)).toBe(true);
        expect(ne.util.isObject(o9)).toBe(true);
    });

    it('isFunction()', function() {
        var o1 = function() {},
            o2 = {},
            o3 = '',
            o4 = [],
            o5 = 1,
            o6 = true,
            o7 = /xyz/g,
            o8 = new Function(),
            o9 = function test() {};

        expect(ne.util.isFunction(o1)).toBe(true);
        expect(ne.util.isFunction(o2)).toBe(false);
        expect(ne.util.isFunction(o3)).toBe(false);
        expect(ne.util.isFunction(o4)).toBe(false);
        expect(ne.util.isFunction(o5)).toBe(false);
        expect(ne.util.isFunction(o6)).toBe(false);
        expect(ne.util.isFunction(o7)).toBe(false);
        expect(ne.util.isFunction(o8)).toBe(true);
        expect(ne.util.isFunction(o9)).toBe(true);
    });

    it('isNumber()', function() {
        var o1 = 1,
            o2 = new Number(2),
            o3 = { test: 1 },
            o4 = [],
            o5 = 'string',
            o6 = true,
            o7 = /xyz/g,
            o8 = 4 + 5,
            o9 = parseFloat('12.5'),
            o10 = 0x15,
            o11 = parseInt('00101', 2);

        expect(ne.util.isNumber(o1)).toBe(true);
        expect(ne.util.isNumber(o2)).toBe(true);
        expect(ne.util.isNumber(o3.test)).toBe(true);
        expect(ne.util.isNumber(o3)).toBe(false);
        expect(ne.util.isNumber(o4)).toBe(false);
        expect(ne.util.isNumber(o5)).toBe(false);
        expect(ne.util.isNumber(o6)).toBe(false);
        expect(ne.util.isNumber(o7)).toBe(false);
        expect(ne.util.isNumber(o8)).toBe(true);
        expect(ne.util.isNumber(o9)).toBe(true);
        expect(ne.util.isNumber(o11)).toBe(true);

    });

    it('isString()', function() {
        var o1 = {},
            o2 = new String('a'),
            o3 = 'string',
            o4 = [],
            o5 = '',
            o6 = true,
            o7 = /xyz/g;

        expect(ne.util.isString(o1)).toBe(false);
        expect(ne.util.isString(o2)).toBe(true);
        expect(ne.util.isString(o3)).toBe(true);
        expect(ne.util.isString(o4)).toBe(false);
        expect(ne.util.isString(o5)).toBe(true);
        expect(ne.util.isString(o6)).toBe(false);
        expect(ne.util.isString(o7)).toBe(false);
    });

    it('isBoolean()', function() {
        var o1 = {},
            o2 = new Boolean('true'),
            o3 = 1,
            o4 = true,
            o5 = false,
            o6 = undefined,
            o7 = null;

        expect(ne.util.isBoolean(o1)).toBe(false);
        expect(ne.util.isBoolean(o2)).toBe(true);
        expect(ne.util.isBoolean(o3)).toBe(false);
        expect(ne.util.isBoolean(o4)).toBe(true);
        expect(ne.util.isBoolean(o5)).toBe(true);
        expect(ne.util.isBoolean(o6)).toBe(false);
        expect(ne.util.isBoolean(o7)).toBe(false);
    });

    it('isHTMLNode()', function() {

        var text = document.createTextNode("Hello World"),
            el1 = document.createElement("H1"),
            el2 = document.createElement("A"),
            el3 = document.createElement("SPAN"),
            el4 = document.createElement("P"),
            el5 = document.createElement("PRE"),
            el6 = document.createElement("DIV"),
            el7 = document.createElement("INPUT"),
            myObj = 3,
            testObj = {};

        expect(ne.util.isHTMLNode(el1)).toBe(true);
        expect(ne.util.isHTMLNode(el2)).toBe(true);
        expect(ne.util.isHTMLNode(el3)).toBe(true);
        expect(ne.util.isHTMLNode(el4)).toBe(true);
        expect(ne.util.isHTMLNode(el5)).toBe(true);
        expect(ne.util.isHTMLNode(el6)).toBe(true);
        expect(ne.util.isHTMLNode(el7)).toBe(true);
        expect(ne.util.isHTMLNode(text)).toBe(true);
        expect(ne.util.isHTMLNode(myObj)).toBe(false);
        expect(ne.util.isHTMLNode(testObj)).toBe(false);
    });

    it('isHTMLTag()', function() {
        var text = document.createTextNode("Hello World"),
            el1 = document.createElement("H1"),
            el2 = document.createElement("A"),
            el3 = document.createElement("SPAN"),
            el4 = document.createElement("P"),
            el5 = document.createElement("PRE"),
            el6 = document.createElement("DIV"),
            el7 = document.createElement("INPUT"),
            myObj = 3,
            testObj = {};

        expect(ne.util.isHTMLTag(el1)).toBe(true);
        expect(ne.util.isHTMLTag(el2)).toBe(true);
        expect(ne.util.isHTMLTag(el3)).toBe(true);
        expect(ne.util.isHTMLTag(el4)).toBe(true);
        expect(ne.util.isHTMLTag(el5)).toBe(true);
        expect(ne.util.isHTMLTag(el6)).toBe(true);
        expect(ne.util.isHTMLTag(el7)).toBe(true);

        expect(ne.util.isHTMLTag(text)).toBe(false);
        expect(ne.util.isHTMLTag(myObj)).toBe(false);
        expect(ne.util.isHTMLTag(testObj)).toBe(false);
    });

    it('isEmpty()', function() {
        var o1 = {},
            o2 = { test: 1},
            o3 = new Object(),
            o4 = [],
            o5 = new Array(),
            o6 = [1, 3],
            o7 = function() {},
            o8,
            o9 = void 0,
            o10 = null,
            o11;

        (function() {
            o8 = arguments;
        })(2, 4);

        (function() {
            o11 = arguments;
        })();

        expect(ne.util.isEmpty(o1)).toBe(true);
        expect(ne.util.isEmpty(o2)).toBe(false);
        expect(ne.util.isEmpty(o3)).toBe(true);
        expect(ne.util.isEmpty(o4)).toBe(true);
        expect(ne.util.isEmpty(o5)).toBe(true);
        expect(ne.util.isEmpty(o6)).toBe(false);
        expect(ne.util.isEmpty(o7)).toBe(true);
        expect(ne.util.isEmpty(o8)).toBe(false);
        expect(ne.util.isEmpty(o9)).toBe(true);
        expect(ne.util.isEmpty(o10)).toBe(true);
        expect(ne.util.isEmpty(o11)).toBe(true);

    });

});
<|endoftext|>


<commit_before>var assert = require('assert');
var connectMongoDBSession = require('../');
var ee = require('events').EventEmitter;
var mongodb = require('mongodb');
var strawman = require('strawman');

describe('connectMongoDBSession', function() {
  var db;
  var StoreStub;

  beforeEach(function() {
    db = strawman({
      collection: { argumentNames: ['collection'], chain: true },
      ensureIndex: { argumentNames: ['index', 'options', 'callback'] },
      findOne: { argumentNames: ['query', 'callback'] },
      remove: { argumentNames: ['query', 'callback'] },
      update: { argumentNames: ['query', 'update', 'options', 'callback' ] }
    });

    mongodb.MongoClient.connect = function(uri, options, callback) {
      process.nextTick(function() { callback(null, db); });
    };

    StoreStub = function() {};
    StoreStub.prototype = { connectMongoDB: 1 };
  });

  describe('options', function() {
    it('can specify uri', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ uri: 'mongodb://host:port/db' });
      assert.equal(session.options.uri, 'mongodb://host:port/db');
      assert.equal(session.options.idField, '_id');
      done();
    });

    it('can specify collection', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ collection: 'notSessions' });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.equal(session.options.collection, 'notSessions');
      done();
    });

    it('can specify expires', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ expires: 25 });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.equal(session.options.expires, 25);
      done();
    });

    it('can specify idField', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ idField: 'sessionId' });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.deepEqual(session._generateQuery('1234'), { sessionId: '1234' });
      done();
    });
  });

  it('can get Store object from Express 3', function(done) {
    var SessionStore = connectMongoDBSession({ session: { Store: StoreStub } });
    assert.ok(SessionStore.prototype.connectMongoDB);
    done();
  });

  it('specifying options is optional', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback();
    });

    var session = new SessionStore(function(error) {
      assert.ifError(error);
      done();
    });
    assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
  });

  it('uses default options and no callback if no args passed', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback();
    });

    var session = new SessionStore();
    assert.equal(session.options.uri, 'mongodb://localhost:27017/test');

    session.on('connected', function() {
      done();
    });
  });

  it('throws an error when connection fails and no callback', function(done) {
    mongodb.MongoClient.connect = function(uri, options, callback) {
      // purposely make callback sync
      callback(new Error('Cant connect'));
    };

    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    assert.throws(
      function() {
        new SessionStore();
      },
      'Error connecting to db: Cant connect');
    done();
  });

  it('passes error to callback if specified', function(done) {
    mongodb.MongoClient.connect = function(uri, options, callback) {
      process.nextTick(function() { callback(new Error('Cant connect')); });
    };

    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numSources = 2;
    var store = new SessionStore(function(error) {
      assert.ok(error);
      --numSources || done();
    });
    store.once('error', function(error) {
      assert.ok(error);
      --numSources || done();
    });
  });

  it('handles index errors', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback(new Error('Index fail'));
    });

    var session = new SessionStore(function(error) {
      assert.equal(error.message, 'Error creating index: Index fail');
      done();
    });
  });

  describe('get()', function() {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers get() calls', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.findOne.on('called', function(args) {
        args.callback(null,
          { expires: new Date('2040-06-01T00:00:00.000Z'), session: { data: 1 } });
      });
      session.get('1234', function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('handles get() errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.get('1234', function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error finding 1234: fail!');
        done();
      });
    });

    it('calls destroy() on stale sessions', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var numRemoveCalls = 0;

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(null, { expires: new Date('2011-06-01T00:00:00.000Z') });
      });

      db.remove.on('called', function(args) {
        ++numRemoveCalls;
        assert.equal(args.query._id, '1234');
        args.callback();
      });

      session.get('1234', function(error, doc) {
        assert.ifError(error);
        assert.ok(!doc);
        assert.equal(numRemoveCalls, 1);
        done();
      });
    });

    it('returns empty if no session found', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(null, null);
      });

      session.get('1234', function(error, doc) {
        assert.ifError(error);
        assert.ok(!doc);
        done();
      });
    });
  });

  describe('destroy()', function() {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers until connected', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.remove.on('called', function(args) {
        args.callback(null);
      });
      session.destroy('1234', function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('reports driver errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.remove.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.destroy('1234', function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error destroying 1234: fail!');
        done();
      });
    });
  });

  describe('set()', function(done) {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers until connected', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.update.on('called', function(args) {
        args.callback(null);
      });
      session.set('1234', { test: 1 }, function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('converts expires to a date', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.ok(args.update.expires instanceof Date);
        assert.equal(args.update.expires.getTime(),
          new Date('2011-06-01T00:00:00.000Z').getTime());
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { expires: '2011-06-01T00:00:00.000Z' }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });

    it('handles set() errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.update.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.set('1234', {}, function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error setting 1234 to {}: fail!');
        done();
      });
    });

    /** For backwards compatibility with connect-mongo */
    it('converts cookies to JSON strings', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.equal(args.update.session.cookie, 'put that cookie down!');
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { toJSON: function() { return 'put that cookie down!'; } }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });

    /** For backwards compatibility with connect-mongo */
    it('unless they do not have a toJSON()', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.deepEqual(args.update.session.cookie, { test: 2 });
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { test: 2 }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });
  });
});<commit_msg>Added missing unit test.<commit_after>var assert = require('assert');
var connectMongoDBSession = require('../');
var ee = require('events').EventEmitter;
var mongodb = require('mongodb');
var strawman = require('strawman');

describe('connectMongoDBSession', function() {
  var db;
  var StoreStub;

  beforeEach(function() {
    db = strawman({
      collection: { argumentNames: ['collection'], chain: true },
      ensureIndex: { argumentNames: ['index', 'options', 'callback'] },
      findOne: { argumentNames: ['query', 'callback'] },
      remove: { argumentNames: ['query', 'callback'] },
      update: { argumentNames: ['query', 'update', 'options', 'callback' ] }
    });

    mongodb.MongoClient.connect = function(uri, options, callback) {
      process.nextTick(function() { callback(null, db); });
    };

    StoreStub = function() {};
    StoreStub.prototype = { connectMongoDB: 1 };
  });

  describe('options', function() {
    it('can specify uri', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ uri: 'mongodb://host:port/db' });
      assert.equal(session.options.uri, 'mongodb://host:port/db');
      assert.equal(session.options.idField, '_id');
      done();
    });

    it('can specify collection', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ collection: 'notSessions' });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.equal(session.options.collection, 'notSessions');
      done();
    });

    it('can specify expires', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ expires: 25 });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.equal(session.options.expires, 25);
      done();
    });

    it('can specify idField', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var session = new SessionStore({ idField: 'sessionId' });
      assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
      assert.deepEqual(session._generateQuery('1234'), { sessionId: '1234' });
      done();
    });
  });

  it('can get Store object from Express 3', function(done) {
    var SessionStore = connectMongoDBSession({ session: { Store: StoreStub } });
    assert.ok(SessionStore.prototype.connectMongoDB);
    done();
  });

  it('specifying options is optional', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback();
    });

    var session = new SessionStore(function(error) {
      assert.ifError(error);
      done();
    });
    assert.equal(session.options.uri, 'mongodb://localhost:27017/test');
  });

  it('uses default options and no callback if no args passed', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback();
    });

    var session = new SessionStore();
    assert.equal(session.options.uri, 'mongodb://localhost:27017/test');

    session.on('connected', function() {
      done();
    });
  });

  it('throws an error when connection fails and no callback', function(done) {
    mongodb.MongoClient.connect = function(uri, options, callback) {
      // purposely make callback sync
      callback(new Error('Cant connect'));
    };

    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    assert.throws(
      function() {
        new SessionStore();
      },
      'Error connecting to db: Cant connect');
    done();
  });

  it('passes error to callback if specified', function(done) {
    mongodb.MongoClient.connect = function(uri, options, callback) {
      process.nextTick(function() { callback(new Error('Cant connect')); });
    };

    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numSources = 2;
    var store = new SessionStore(function(error) {
      assert.ok(error);
      --numSources || done();
    });
    store.once('error', function(error) {
      assert.ok(error);
      --numSources || done();
    });
  });

  it('handles index errors', function(done) {
    var SessionStore = connectMongoDBSession({ Store: StoreStub });
    var numIndexCalls = 0;
    db.ensureIndex.on('called', function(args) {
      assert.equal(++numIndexCalls, 1);
      assert.equal(args.index.expires, 1);
      args.callback(new Error('Index fail'));
    });

    var session = new SessionStore(function(error) {
      assert.equal(error.message, 'Error creating index: Index fail');
      done();
    });
  });

  describe('get()', function() {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers get() calls', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.findOne.on('called', function(args) {
        args.callback(null,
          { expires: new Date('2040-06-01T00:00:00.000Z'), session: { data: 1 } });
      });
      session.get('1234', function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('handles get() errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.get('1234', function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error finding 1234: fail!');
        done();
      });
    });

    it('calls destroy() on stale sessions', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var numRemoveCalls = 0;

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(null, { expires: new Date('2011-06-01T00:00:00.000Z') });
      });

      db.remove.on('called', function(args) {
        ++numRemoveCalls;
        assert.equal(args.query._id, '1234');
        args.callback();
      });

      session.get('1234', function(error, doc) {
        assert.ifError(error);
        assert.ok(!doc);
        assert.equal(numRemoveCalls, 1);
        done();
      });
    });

    it('returns empty if no session found', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.findOne.on('called', function(args) {
        args.callback(null, null);
      });

      session.get('1234', function(error, doc) {
        assert.ifError(error);
        assert.ok(!doc);
        done();
      });
    });
  });

  describe('destroy()', function() {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers until connected', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.remove.on('called', function(args) {
        args.callback(null);
      });
      session.destroy('1234', function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('reports driver errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.remove.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.destroy('1234', function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error destroying 1234: fail!');
        done();
      });
    });
  });

  describe('set()', function(done) {
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('buffers until connected', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });
      var emitter = new ee();

      mongodb.MongoClient.connect = function(uri, options, callback) {
        emitter.on('success', function() {
          callback(null, db);
        });
      };

      var session = new SessionStore();

      db.update.on('called', function(args) {
        args.callback(null);
      });
      session.set('1234', { test: 1 }, function(error) {
        assert.ifError(error);
        assert.equal(numIndexCalls, 1);
        done();
      });

      setImmediate(function() {
        emitter.emit('success');
      });
    });

    it('converts expires to a date', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.ok(args.update.expires instanceof Date);
        assert.equal(args.update.expires.getTime(),
          new Date('2011-06-01T00:00:00.000Z').getTime());
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { expires: '2011-06-01T00:00:00.000Z' }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });

    it('handles set() errors', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.update.on('called', function(args) {
        args.callback(new Error('fail!'));
      });

      session.set('1234', {}, function(error) {
        assert.ok(error);
        assert.equal(error.message, 'Error setting 1234 to {}: fail!');
        done();
      });
    });

    /** For backwards compatibility with connect-mongo */
    it('converts cookies to JSON strings', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.equal(args.update.session.cookie, 'put that cookie down!');
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { toJSON: function() { return 'put that cookie down!'; } }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });

    /** For backwards compatibility with connect-mongo */
    it('unless they do not have a toJSON()', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();

      db.update.on('called', function(args) {
        assert.deepEqual(args.update.session.cookie, { test: 2 });
        args.callback(null);
      });
      var update = {
        test: 1,
        cookie: { test: 2 }
      };
      session.set('1234', update, function(error) {
        assert.ifError(error);
        assert.equal(db.update.calls.length, 1);
        done();
      });
    });
  });

  describe('clear()', function(done){
    var numIndexCalls;

    beforeEach(function() {
      numIndexCalls = 0;

      db.ensureIndex.on('called', function(args) {
        assert.equal(++numIndexCalls, 1);
        assert.equal(args.index.expires, 1);
        args.callback();
      });
    });

    it('clears the session store', function(done) {
      var SessionStore = connectMongoDBSession({ Store: StoreStub });

      var session = new SessionStore();
      db.remove.on('called', function(args) {
        args.callback(null);
      });

      session.clear(function(error) {
        assert.ifError(error);
        done();
      });
    });
  });

});<|endoftext|>


<commit_before>module.exports = {
    // 'http://sherlocked.allizom.org/api/'
    API_URL: 'http://localhost:1077/api/'
};
<commit_msg>fix config<commit_after>module.exports = {
    // 'http://localhost:1077/api/'
    API_URL: 'http://sherlocked.dev.mozaws.net/api/'
};
<|endoftext|>


<commit_before>$.fn.throttledInput = function(fn) {
  return $(this).each(function() {
    var prev = undefined
    var timeout = null
    var $input = $(this).on('keyup', function() {
      var txt = $input.val()
      var that = this
      if (timeout) clearTimeout(timeout)
      timeout = setTimeout(function() {
        if (prev == txt) return
        prev = txt
        fn.call(that, txt)
      }, 400)
    })
    $input.on('reset', reset)
    $input.on('fire', function() {
      reset()
      fn.call(this, prev)
    })

    function reset() {
      if (timeout) clearTimeout(timeout)
      prev = $input.val()
    }
  })
}

$.fn.labeledText = function(txt) {
  this.text(txt).add(this.prev('label')).toggleClass('hide', !txt)
  return this
}

function renderWarningSummary(summary) {
  if (!summary) return undefined
  return $('#templates > .warning-summary').clone()
    .find('.agelimit').attr('src', ageLimitIcon(summary)).end()
    .find('.warnings').html(warningIcons(summary)).end()
}

function ageLimitIcon(summary) {
  return 'images/agelimit-'+summary.age+'.png'
}

function warningIcons(summary) {
  return summary.warnings.map(function(w) { return $('<span>', { class:'warning ' + w.category }) })
}

function hasRole(role) {
  return utils.hasRole(window.user, role)
}

function loadTemplates(callback) {
  $.get('/templates.html').done(function(html) {
    $('#templates').html(html)
    callback()
  })
}

function setLocation(path) {
  history.replaceState(null, null, path)
}

function parseLocationHash() {
  if (!location.hash) return undefined
  return location.hash.split('/').map(decodeURIComponent)
}
<commit_msg>Added input event handling to throttledInput<commit_after>$.fn.throttledInput = function(fn) {
  return $(this).each(function() {
    var prev = undefined
    var timeout = null
    var $input = $(this).on('keyup input', function() {
      var txt = $input.val()
      var that = this
      if (timeout) clearTimeout(timeout)
      timeout = setTimeout(function() {
        if (prev == txt) return
        prev = txt
        fn.call(that, txt)
      }, 400)
    })
    $input.on('reset', reset)
    $input.on('fire', function() {
      reset()
      fn.call(this, prev)
    })

    function reset() {
      if (timeout) clearTimeout(timeout)
      prev = $input.val()
    }
  })
}

$.fn.labeledText = function(txt) {
  this.text(txt).add(this.prev('label')).toggleClass('hide', !txt)
  return this
}

function renderWarningSummary(summary) {
  if (!summary) return undefined
  return $('#templates > .warning-summary').clone()
    .find('.agelimit').attr('src', ageLimitIcon(summary)).end()
    .find('.warnings').html(warningIcons(summary)).end()
}

function ageLimitIcon(summary) {
  return 'images/agelimit-'+summary.age+'.png'
}

function warningIcons(summary) {
  return summary.warnings.map(function(w) { return $('<span>', { class:'warning ' + w.category }) })
}

function hasRole(role) {
  return utils.hasRole(window.user, role)
}

function loadTemplates(callback) {
  $.get('/templates.html').done(function(html) {
    $('#templates').html(html)
    callback()
  })
}

function setLocation(path) {
  history.replaceState(null, null, path)
}

function parseLocationHash() {
  if (!location.hash) return undefined
  return location.hash.split('/').map(decodeURIComponent)
}
<|endoftext|>


<commit_before>import _ from "lodash";
import jQuery from "jquery";
import moment from "moment";

import Config from "./config.js";
import DText from "./dtext.js";
import Resource from "./resource.js";
import UI from "./ui.js";
import "./danbooru-ex.css";

export default class EX {
  static get Config() { return Config; }
  static get DText() { return DText; }
  static get Resource() { return Resource; }
  static get UI() { return UI; }

  static search(url, search, { limit, page } = {}) {
    return $.getJSON(url, { search, limit: limit || 1000, page: page || 1 });
  }

  static initialize() {
    $("footer").append(
      ` – Danbooru EX (<a href="/users/${$('meta[name="current-user-id"]').attr("content")}/edit#ex-settings">settings</a>)`
    );

    EX.config.enableHeader && UI.Header.initialize();

    EX.UI.initialize();
    EX.config.enableNotesLivePreview && EX.UI.Notes.initialize();

    EX.config.artistsRedesign && EX.UI.Artists.initialize();
    EX.config.commentsRedesign && EX.UI.Comments.initialize();
    EX.config.forumRedesign && EX.UI.ForumPosts.initialize();
    EX.config.poolsRedesign && EX.UI.Pools.initialize();
    EX.config.postsRedesign && EX.UI.Posts.initialize();
    EX.config.postVersionsRedesign && EX.UI.PostVersions.initialize();
    EX.config.wikiRedesign && EX.UI.WikiPages.initialize();
  }
}

window.EX = EX;
window.moment = moment;

console.timeEnd("booted");
$(function () {
  try {
    console.timeEnd("loaded");

    EX.config = new EX.Config();
    EX.initialize();

    console.timeEnd("initialized");
  } catch(e) {
    $("footer").append(`<div class="ex-error">Danbooru EX error: ${e}</div>`);
    throw e;
  }
});

<commit_msg>[fix] Include version in footer.<commit_after>import _ from "lodash";
import jQuery from "jquery";
import moment from "moment";

import Config from "./config.js";
import DText from "./dtext.js";
import Resource from "./resource.js";
import UI from "./ui.js";
import "./danbooru-ex.css";

export default class EX {
  static get Config() { return Config; }
  static get DText() { return DText; }
  static get Resource() { return Resource; }
  static get UI() { return UI; }

  static search(url, search, { limit, page } = {}) {
    return $.getJSON(url, { search, limit: limit || 1000, page: page || 1 });
  }

  static initialize() {
    $("footer").append(
      `| Danbooru EX <a href="https://github.com/evazion/danbooru-ex">v${GM_info.script.version}</a> – <a href="/users/${$('meta[name="current-user-id"]').attr("content")}/edit#ex-settings">Settings</a>`
    );

    EX.config.enableHeader && UI.Header.initialize();

    EX.UI.initialize();
    EX.config.enableNotesLivePreview && EX.UI.Notes.initialize();

    EX.config.artistsRedesign && EX.UI.Artists.initialize();
    EX.config.commentsRedesign && EX.UI.Comments.initialize();
    EX.config.forumRedesign && EX.UI.ForumPosts.initialize();
    EX.config.poolsRedesign && EX.UI.Pools.initialize();
    EX.config.postsRedesign && EX.UI.Posts.initialize();
    EX.config.postVersionsRedesign && EX.UI.PostVersions.initialize();
    EX.config.wikiRedesign && EX.UI.WikiPages.initialize();
  }
}

window.EX = EX;
window.moment = moment;

console.timeEnd("booted");
$(function () {
  try {
    console.timeEnd("loaded");

    EX.config = new EX.Config();
    EX.initialize();

    console.timeEnd("initialized");
  } catch(e) {
    $("footer").append(`<div class="ex-error">Danbooru EX error: ${e}</div>`);
    throw e;
  }
});

<|endoftext|>


<commit_before>var hunt = require('hunt'),
  hrw = require('./../index.js'),
  model = require('./../example/model/article.model.js'),
  populateDb = require('./../example/lib/populateDatabase.js'),
  should = require('should'),
  Hunt,
  rootKey = 'i_am_prep',
  articleId,
  bookName = 'Da book' + Date.now(),
  request = require('request');

function isArticle(a) {
  a.id.should.be.a.String
  a.name.should.be.a.String;
  a.content.should.be.a.String;
  should.not.exists(a.author);
}

describe('Testing REST api as user', function () {
  before(function (done) {
    Hunt = hunt({
      'port': 3003,
      'disableCsrf': true,
      'huntKey': true,
      'mongoUrl': 'mongodb://localhost/hrw_dev'
    });

    Hunt.extendModel('Article', model);

    hrw(Hunt, { 'modelName': 'Article', 'methods': ['doSmth'], 'statics': 'doSmth'});

    Hunt.once('start', function (evnt) {
      populateDb(Hunt, done);
    });

    Hunt.startWebServer();
  });

  it('returns list of articles for GET /', function (done) {
    request({
        'method': 'GET',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article',
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.should.be.an.Array;
          body.data.map(isArticle);
          done();
        }
      });
  });

  it('creates article for POST /', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': bookName,
          'content': 'some content',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(201);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some content');
          body.data.id.should.be.a.String;
          response.headers.location.should.be.equal('/api/v1/article/' + body.data.id);
          articleId = body.data.id;
          done();
        }
      });
  });

  it('returns article needed for GET /:id', function (done) {
    request({
        'method': 'GET',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some content');
          body.data.id.should.be.a.equal(articleId);
          done();
        }
      });
  });

  it('Updates content for PUT /:id', function (done) {
    request({
        'method': 'PUT',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
        'headers': {'huntKey': rootKey},
        'form': {
          'content': 'some new content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some new content');
          body.data.id.should.be.a.equal(articleId);
          request({
              'method': 'GET',
              'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
              'headers': {'huntKey': rootKey},
              'json': true
            },
            function (error, response, body) {
              if (error) {
                done(error);
              } else {
                response.statusCode.should.be.equal(200);
                body.status.should.be.equal('Ok');
                body.data.name.should.be.equal(bookName);
                body.data.content.should.be.equal('some new content');
                body.data.id.should.be.a.equal(articleId);
                done();
              }
            });
        }
      });
  });

  it('returns `Method not allowed` for POST /:id',  function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/53b43aded6202872e0e3371f',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': 'Da book',
          'content': 'some content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(405);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(405);
          body.errors[0].message.should.be.equal('Method not allowed!');
          done();
        }
      });
  });

  it('returns `This API endpoint do not exists!` for some stupid requests',  function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/someStupidApiEndpointThatDoNotExists',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': 'Da book',
          'content': 'some content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('This API endpoint do not exists!');
          done();
        }
      });
  });

  it('Allows to call existent static method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(202);
          body.body.payload.should.be.equal('Da book');
          body.user.id.should.be.a.String;
          done();
        }
      });
  });

  it('Disallows to call non existent static method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doNotDoSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('Unknown static method!');
          done();
        }
      });
  });

  it('Allows to call existent instance method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId+'/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(202);
          body.body.payload.should.be.equal('Da book');
          body.user.id.should.be.a.String;
          body.article._id.should.be.equal(articleId);
          done();
        }
      });
  });

  it('Disallows to call non existent instance method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId+'/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doNotDoSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('Unknown instance method!');
          done();
        }
      });
  });

  it('Allows to delete article by DELETE /:id', function (done) {
    request({
        'method': 'DELETE',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId,
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('deleted');
          request({
              'method': 'GET',
              'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
              'headers': {'huntKey': rootKey},
              'json': true
            },
            function (error, response, body) {
              if (error) {
                done(error);
              } else {
                response.statusCode.should.be.equal(404);
                body.status.should.be.equal('Error');
                body.errors.should.be.an.Array;
                body.errors.length.should.be.equal(1);
                body.errors[0].code.should.be.equal(404);
                body.errors[0].message.should.be.equal('Not found!');
                done();
              }
            });
        }
      });
  });
});<commit_msg>https://oselot.atlassian.net/browse/ACR-211<commit_after>var hunt = require('hunt'),
  hrw = require('./../index.js'),
  model = require('./../example/model/article.model.js'),
  populateDb = require('./../example/lib/populateDatabase.js'),
  should = require('should'),
  Hunt,
  rootKey = 'i_am_prep',
  articleId,
  bookName = 'Da book' + Date.now(),
  request = require('request');

function isArticle(a) {
  a.id.should.be.a.String
  a.name.should.be.a.String;
  a.content.should.be.a.String;
  should.not.exists(a.author);
}

describe('Testing REST api as user', function () {
  before(function (done) {
    Hunt = hunt({
      'port': 3003,
      'disableCsrf': true,
      'huntKey': true,
      'mongoUrl': 'mongodb://localhost/hrw_dev'
    });

    Hunt.extendModel('Article', model);

    hrw(Hunt, { 'modelName': 'Article', 'methods': ['doSmth'], 'statics': 'doSmth'});

    Hunt.once('start', function (evnt) {
      populateDb(Hunt, done);
    });

    Hunt.startWebServer();
  });

  it('returns list of articles for GET /', function (done) {
    request({
        'method': 'GET',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article',
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.should.be.an.Array;
          body.data.map(isArticle);
          done();
        }
      });
  });

  it('creates article for POST /', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': bookName,
          'content': 'some content',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(201);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some content');
          body.data.id.should.be.a.String;
          response.headers.location.should.be.equal('/api/v1/article/' + body.data.id);
          articleId = body.data.id;
          done();
        }
      });
  });

  it('returns article needed for GET /:id', function (done) {
    request({
        'method': 'GET',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some content');
          body.data.id.should.be.a.equal(articleId);
          done();
        }
      });
  });

  it('Updates content for PUT /:id', function (done) {
    request({
        'method': 'PUT',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
        'headers': {'huntKey': rootKey},
        'form': {
          'content': 'some new content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('Ok');
          body.data.name.should.be.equal(bookName);
          body.data.content.should.be.equal('some new content');
          body.data.id.should.be.a.equal(articleId);
          request({
              'method': 'GET',
              'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
              'headers': {'huntKey': rootKey},
              'json': true
            },
            function (error, response, body) {
              if (error) {
                done(error);
              } else {
                response.statusCode.should.be.equal(200);
                body.status.should.be.equal('Ok');
                body.data.name.should.be.equal(bookName);
                body.data.content.should.be.equal('some new content');
                body.data.id.should.be.a.equal(articleId);
                done();
              }
            });
        }
      });
  });

  it('returns `Method not allowed` for POST /:id',  function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/53b43aded6202872e0e3371f',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': 'Da book',
          'content': 'some content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(405);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(405);
          body.errors[0].message.should.be.equal('Method not allowed!');
          done();
        }
      });
  });

  it('returns `This API endpoint do not exists!` for some stupid requests',  function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/someStupidApiEndpointThatDoNotExists',
        'headers': {'huntKey': rootKey},
        'form': {
          'name': 'Da book',
          'content': 'some content'
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('This API endpoint do not exists!');
          done();
        }
      });
  });

  it('Allows to call existent static method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(202);
          body.body.payload.should.be.equal('Da book');
          body.user.id.should.be.a.String;
          done();
        }
      });
  });

  it('Disallows to call non existent static method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doNotDoSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('Unknown static method!');
          done();
        }
      });
  });

  it('Allows to call existent instance method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId+'/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(202);
          body.body.payload.should.be.equal('Da book');
          body.user.id.should.be.a.String;
          body.article._id.should.be.equal(articleId);
          done();
        }
      });
  });

  it('Disallows to call method of non existent instance', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/53b43aded6202872e0e3371f/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doNotDoSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('Not found!');
          done();
        }
      });
  });

  it('Disallows to call non existent instance method', function (done) {
    request({
        'method': 'POST',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId+'/method',
        'headers': {'huntKey': rootKey},
        'form': {
          'method': 'doNotDoSmth',
          'payload': 'Da book',
        },
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(404);
          body.status.should.be.equal('Error');
          body.errors.should.be.an.Array;
          body.errors.length.should.be.equal(1);
          body.errors[0].code.should.be.equal(404);
          body.errors[0].message.should.be.equal('Unknown instance method!');
          done();
        }
      });
  });

  it('Allows to delete article by DELETE /:id', function (done) {
    request({
        'method': 'DELETE',
        'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/'+articleId,
        'headers': {'huntKey': rootKey},
        'json': true
      },
      function (error, response, body) {
        if (error) {
          done(error);
        } else {
          response.statusCode.should.be.equal(200);
          body.status.should.be.equal('deleted');
          request({
              'method': 'GET',
              'url': 'http://localhost:' + Hunt.config.port + '/api/v1/article/' + articleId,
              'headers': {'huntKey': rootKey},
              'json': true
            },
            function (error, response, body) {
              if (error) {
                done(error);
              } else {
                response.statusCode.should.be.equal(404);
                body.status.should.be.equal('Error');
                body.errors.should.be.an.Array;
                body.errors.length.should.be.equal(1);
                body.errors[0].code.should.be.equal(404);
                body.errors[0].message.should.be.equal('Not found!');
                done();
              }
            });
        }
      });
  });
});<|endoftext|>


<commit_before>const Browser = require('zombie');
const ms      = require('ms');
const server  = require('./helpers/server');

const checksURL = 'http://localhost:3000/_healthchecks';

describe('User runs checks', function() {

  const browser = new Browser();

  before(function(done) {
    server.ready(done);
  });

  describe('all healthy', function() {

    it('should see a list of passing tests', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'Passed');
        browser.assert.text('.passed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(2)', /error \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(3)', /expected \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(5)', /status \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(6)', /timeout \d[.\d]* ms/);
        done();
      });
    });
  });

  describe('redirect', function() {
    describe('to healthy page', function() {
      before(function() {
        server.locals.redirect = '/status';
      });

      it('should see a list of passing tests', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'Passed');
          browser.assert.text('.passed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(2)', /error \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(3)', /expected \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(5)', /status \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(6)', /timeout \d[.\d]* ms/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to page with errors', function() {
      before(function() {
        server.locals.redirect = '/error';
        server.locals.error    = true;
      });

      it('should see a failed test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'FailedPassed');
          browser.assert.elements('.failed li', 2);
          browser.assert.text('.failed li:nth-of-type(2)', /redirect => socket hang up \d[.\d]* ms/);
          browser.assert.elements('.passed li', 4);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
        server.locals.error    = false;
      });
    });

    describe('loop', function() {
      before(function() {
        server.locals.redirect = '/redirect';
      });

      it('should see a failed test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'FailedPassed');
          browser.assert.text('.failed li:nth-of-type(1)', /redirect => too many redirects \d[.\d]* ms/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to a subdomain', function() {
      before(function() {
        server.locals.redirect = 'https://subdomain.localhost/error';
      });

      describe('healthy', function() {
        it('should see a passing test', function(done) {
          browser.visit(checksURL, function() {
            browser.assert.text('h1', 'Passed');
            browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
            done();
          });
        });

      });

      describe('failing', function() {
        before(function() {
          server.locals.error = true;
        });

        it('should see a failing test', function(done) {
          browser.visit(checksURL, function() {
            browser.assert.text('h1', 'FailedPassed');
            browser.assert.text('.failed li:nth-of-type(2)', /redirect => socket hang up \d[.\d]* ms/);
            done();
          });
        });

        after(function() {
          server.locals.error = false;
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to a different domain', function() {
      before(function() {
        server.locals.redirect = 'https://www.google.com';
      });

      it('should see a passing test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'Passed');
          browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });
  });

  describe('URL not accessible', function() {
    before(function() {
      server.locals.error = true;
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /error => socket hang up \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.error = false;
    });
  });

  describe('response times out', function() {
    before(function() {
      server.locals.timeout = ms('3s');
    });

    it('should see a failed test', function(done) {
      this.timeout(ms('4s'));

      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /timeout => timeout \d[.\d]* s/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.timeout = 0;
    });
  });

  describe('response is 400', function() {
    before(function() {
      server.locals.status = 400;
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /status => 400 \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.status = 200;
    });
  });

  describe('response missing expected content', function() {
    before(function() {
      server.locals.expected = 'Expected to see foo and also bar';
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /expected => body \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.expected = 'Expected to see foo and bar';
    });
  });

  describe('subdomain not accessible', function() {
    before(function() {
      server.locals.subdomain = '';
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain => 404 \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.subdomain = 'admin';
    });
  });

});

<commit_msg>Redirects can be very fast on Travis.<commit_after>const Browser = require('zombie');
const ms      = require('ms');
const server  = require('./helpers/server');

const checksURL = 'http://localhost:3000/_healthchecks';

describe('User runs checks', function() {

  const browser = new Browser();

  before(function(done) {
    server.ready(done);
  });

  describe('all healthy', function() {

    it('should see a list of passing tests', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'Passed');
        browser.assert.text('.passed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(2)', /error \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(3)', /expected \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(5)', /status \d[.\d]* ms/);
        browser.assert.text('.passed li:nth-of-type(6)', /timeout \d[.\d]* ms/);
        done();
      });
    });
  });

  describe('redirect', function() {
    describe('to healthy page', function() {
      before(function() {
        server.locals.redirect = '/status';
      });

      it('should see a list of passing tests', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'Passed');
          browser.assert.text('.passed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(2)', /error \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(3)', /expected \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(5)', /status \d[.\d]* ms/);
          browser.assert.text('.passed li:nth-of-type(6)', /timeout \d[.\d]* ms/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to page with errors', function() {
      before(function() {
        server.locals.redirect = '/error';
        server.locals.error    = true;
      });

      it('should see a failed test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'FailedPassed');
          browser.assert.elements('.failed li', 2);
          browser.assert.text('.failed li:nth-of-type(2)', /redirect => socket hang up \d[.\d]* ms/);
          browser.assert.elements('.passed li', 4);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
        server.locals.error    = false;
      });
    });

    describe('loop', function() {
      before(function() {
        server.locals.redirect = '/redirect';
      });

      it('should see a failed test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'FailedPassed');
          browser.assert.text('.failed li:nth-of-type(1)', /redirect => too many redirects \d[.\d]* .s/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to a subdomain', function() {
      before(function() {
        server.locals.redirect = 'https://subdomain.localhost/error';
      });

      describe('healthy', function() {
        it('should see a passing test', function(done) {
          browser.visit(checksURL, function() {
            browser.assert.text('h1', 'Passed');
            browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
            done();
          });
        });

      });

      describe('failing', function() {
        before(function() {
          server.locals.error = true;
        });

        it('should see a failing test', function(done) {
          browser.visit(checksURL, function() {
            browser.assert.text('h1', 'FailedPassed');
            browser.assert.text('.failed li:nth-of-type(2)', /redirect => socket hang up \d[.\d]* ms/);
            done();
          });
        });

        after(function() {
          server.locals.error = false;
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });

    describe('to a different domain', function() {
      before(function() {
        server.locals.redirect = 'https://www.google.com';
      });

      it('should see a passing test', function(done) {
        browser.visit(checksURL, function() {
          browser.assert.text('h1', 'Passed');
          browser.assert.text('.passed li:nth-of-type(4)', /redirect \d[.\d]* ms/);
          done();
        });
      });

      after(function() {
        server.locals.redirect = false;
      });
    });
  });

  describe('URL not accessible', function() {
    before(function() {
      server.locals.error = true;
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /error => socket hang up \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.error = false;
    });
  });

  describe('response times out', function() {
    before(function() {
      server.locals.timeout = ms('3s');
    });

    it('should see a failed test', function(done) {
      this.timeout(ms('4s'));

      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /timeout => timeout \d[.\d]* s/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.timeout = 0;
    });
  });

  describe('response is 400', function() {
    before(function() {
      server.locals.status = 400;
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /status => 400 \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.status = 200;
    });
  });

  describe('response missing expected content', function() {
    before(function() {
      server.locals.expected = 'Expected to see foo and also bar';
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /expected => body \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.expected = 'Expected to see foo and bar';
    });
  });

  describe('subdomain not accessible', function() {
    before(function() {
      server.locals.subdomain = '';
    });

    it('should see a failed test', function(done) {
      browser.visit(checksURL, function() {
        browser.assert.text('h1', 'FailedPassed');
        browser.assert.elements('.failed li', 1);
        browser.assert.text('.failed li:nth-of-type(1)', /\/\/admin.localhost\/subdomain => 404 \d[.\d]* ms/);
        browser.assert.elements('.passed li', 5);
        done();
      });
    });

    after(function() {
      server.locals.subdomain = 'admin';
    });
  });

});

<|endoftext|>