<commit_before>'use strict';

/**
 * Using mock for connect.
 * Mock includes additional methods for testing as .get(), .end(), etc.
 * To be able to check http respond right away
 *
 * Example:
 *
 *     http.middleware.request().get('/favicon.ico').end(function(res) {
 *         res.statusCode.should.equal(200);
 *         ac.check(done);
 *     });
 *
 */
require('../../helpers/connect');

var path           = require('path'),
    connect        = require('connect'),
    httpFunc       = require( path.join(process.env.PWD, 'lib/http/index') ),
    http           = null,
    app            = null,
    ac             = require('../../helpers/assertionCounter'),
    utils          = require('../../helpers/utils.js'),
    sessionStore   = new connect.session.MemoryStore,
    settings       = {        // User-configurable settings with sensible defaults
      "static": {
        maxAge: 2592000000    // (30 * 24 * 60 * 60 * 1000) cache static assets in the browser for 30 days
      },
      secure: false           // allow setting of the 'secure' cookie attribute when using SSL - see https://github.com/socketstream/socketstream/issues/349
    },
    sessionOptions = {
        maxAge: 2592000000
    },
    root           = path.join(process.cwd(), 'test/fixtures/project'); // replace '\' with '/' to support Windows

function testPrependMiddleware(req, res, next) {
    next();
}

function testAppendMiddleware(req, res, next) {
    if (req) {
        next();
    }
}

describe('lib/http/index', function () {

    beforeEach(function (done) {
        ac.reset();
        http = null;
        app  = null;
        done();
    });

    describe('module.exports', function () {
        it('should return a {Function} instance', function (done) {
            ac.expect(1);

            httpFunc.should.be.type('function').andCheck();
            ac.check(done);
        });
    });

    describe('module.exports()', function () {
        it('should return http {Object} instance', function (done) {
            ac.expect(3);

            http = httpFunc(root);

            http.set.should.be.type('function').andCheck();
            http.load.should.be.type('function').andCheck();
            http.route.should.be.type('function').andCheck();

            ac.check(done);
        });
    });

    describe('.set()', function () {
        it('should set newSettings into private settings object');
    });

    describe('.route()', function () {
        it('should add event listener for the url');
    });

    describe('.load()', function () {
        var staticPath = '';

        function setUp(done) {
            staticPath = 'client/static';

            /* Loading http function */
            http = httpFunc(root);

            /* adding some test middlewars */
            http.middleware.prepend(testPrependMiddleware);
            http.middleware.append(testAppendMiddleware);

            /* loading http server assets */
            app = http.load(staticPath, sessionStore, sessionOptions);
<commit_msg> 2nd phase of linting/testing 'lib/http' - Added tests for .set()<commit_after>/*jshint immed: false */

'use strict';

/**
 * Using mock for connect.
 * Mock includes additional methods for testing as .get(), .end(), etc.
 * To be able to check http respond right away
 *
 * Example:
 *
 *     http.middleware.request().get('/favicon.ico').end(function(res) {
 *         res.statusCode.should.equal(200);
 *         ac.check(done);
 *     });
 *
 */
require('../../helpers/connect');

var path           = require('path'),
    connect        = require('connect'),
    httpFunc       = require( path.join(process.env.PWD, 'lib/http/index') ),
    http           = null,
    app            = null,
    ac             = require('../../helpers/assertionCounter'),
    utils          = require('../../helpers/utils.js'),
    sessionStore   = new connect.session.MemoryStore,
    settings       = {        // User-configurable settings with sensible defaults
      "static": {
        maxAge: 2592000000    // (30 * 24 * 60 * 60 * 1000) cache static assets in the browser for 30 days
      },
      secure: false           // allow setting of the 'secure' cookie attribute when using SSL - see https://github.com/socketstream/socketstream/issues/349
    },
    sessionOptions = {
        maxAge: 2592000000
    },
    root           = path.join(process.cwd(), 'test/fixtures/project'); // replace '\' with '/' to support Windows

function testPrependMiddleware(req, res, next) {
    next();
}

function testAppendMiddleware(req, res, next) {
    if (req) {
        next();
    }
}

describe('lib/http/index', function () {

    beforeEach(function (done) {
        ac.reset();
        http = null;
        app  = null;
        done();
    });

    describe('module.exports', function () {
        it('should return a {Function} instance', function (done) {
            ac.expect(1);

            httpFunc.should.be.type('function').andCheck();
            ac.check(done);
        });
    });

    describe('module.exports()', function () {
        it('should return http {Object} instance', function (done) {
            ac.expect(3);

            http = httpFunc(root);

            http.set.should.be.type('function').andCheck();
            http.load.should.be.type('function').andCheck();
            http.route.should.be.type('function').andCheck();

            ac.check(done);
        });
    });

    describe('.set()', function () {
        beforeEach(function (done) {
          http = httpFunc(root);
          done();
        });

        it('should set newSettings into the private settings object', function (done) {
            var newSettings = {
                secure: true
            };

            ac.expect(0);
            /* Should now throw an error */
            http.set(newSettings);
            ac.check(done);
        });

        it('should throw an error if passed argument is not an object', function (done) {
            var newSettings = '';

            ac.expect(0);

            /* Should throw an error */
            (function() {
                http.set(newSettings);
            }).should.throw('ss.http.set() takes an object e.g. {static: {maxAge: 60000}}');

            ac.check(done);
        });
    });

    describe('.route()', function () {
        it('should add event listener for the url');
    });

    describe('.load()', function () {
        var staticPath = '';

        function setUp(done) {
            staticPath = 'client/static';

            /* Loading http function */
            http = httpFunc(root);

            /* adding some test middlewars */
            http.middleware.prepend(testPrependMiddleware);
            http.middleware.append(testAppendMiddleware);

            /* loading http server assets */
            app = http.load(staticPath, sessionStore, sessionOptions);

{'fraction_non_alphanumeric': 0.14700755374782104, 'fraction_numerical': 0.01336432306798373, 'mean_word_length': 1.9423076923076923, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1854181', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1849, 'n_words': 449}