<commit_before>'use strict'

const controller = require('./../lib/connectController')

const userCtr = {
    'index': function () {return 'I am index'},
    'index_id': function (id) {return id}, 
    'index_id_members':  function () {return 'I am index_id_members'},
    'dummy_nr_members':  function (nr) {return nr}
}

/**
 * mws is an Array of Middlewares (Router objects).
 * Each mws element is a Router corresponding to each controller.
 * In this case there is a single Router corresponding to userCtr source.
 * In turn, each Router contains a Middleware for each method of the controller. 
 */
const mws = controller(userCtr)

module.exports.testLoadControllers = function(test) {
    test.expect(1)
    test.equal(mws.length, 1)    // 1 controller for userCtr object
    test.done() 
}

module.exports.testControllerIndex = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, 'I am index')}
    router(req, res)
    test.done()
}

module.exports.testControllerIndexId = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/27', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, '27')}
    router(req, res)
    test.done()
}

module.exports.testControllerDummyNrMembers = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/dummy/31/members', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, '31')}
    router(req, res)
    test.done()
}<commit_msg>Unit Test for parsing query-string<commit_after>'use strict'

const controller = require('./../lib/connectController')

const userCtr = {
    'index': function () {return 'I am index'},
    'index_id': function (id) {return id}, 
    'index_id_members':  function () {return 'I am index_id_members'},
    'dummy_nr_members':  function (nr) {return nr},
    'dummy_nr_teams':  function (nr, arg1, arg2) {return {
        'nr': nr, 'arg1': arg1, 'arg2': arg2
    }},
}

/**
 * mws is an Array of Middlewares (Router objects).
 * Each mws element is a Router corresponding to each controller.
 * In this case there is a single Router corresponding to userCtr source.
 * In turn, each Router contains a Middleware for each method of the controller. 
 */
const mws = controller(userCtr)

module.exports.testLoadControllers = function(test) {
    test.expect(1)
    test.equal(mws.length, 1)    // 1 controller for userCtr object
    test.done() 
}

module.exports.testControllerIndex = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, 'I am index')}
    router(req, res)
    test.done()
}

module.exports.testControllerIndexId = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/27', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, '27')}
    router(req, res)
    test.done()
}

module.exports.testControllerDummyNrMembers = function(test) {
    test.expect(1)
    const router = mws[0]
    const req = { 'url': '/dummy/31/members', 'method': 'get'}
    const res = { 'render': (view, ctx) => test.equal(ctx, '31')}
    router(req, res)
    test.done()
}

module.exports.testControllerRouteAndQueryParameters = function(test) {
    test.expect(3)
    const router = mws[0]
    const req = { 
        'url': '/dummy/71/teams?arg1=abc&arg2=super', 
        'method': 'get',
        'query': {'arg1': 'abc', 'arg2': 'super'}
    }
    const res = { 'render': (view, ctx) => {
        test.equal(ctx.nr, '71')
        test.equal(ctx.arg1, 'abc')
        test.equal(ctx.arg2, 'super')
        test.done()
    }}
    router(req, res)
}
{'fraction_non_alphanumeric': 0.16058777223825768, 'fraction_numerical': 0.013644712673838887, 'mean_word_length': 3.2639821029082774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, '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': '5881306', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1281, 'n_words': 353}