<commit_before>describe('job-controller: getAvailable tests', function(){

    var mockery = require('mockery');
    var expect = require('chai').expect;

    before(function() {
        mockery.enable({
            useCleanCache: true,
            warnOnUnregistered: false
        });
    });

    beforeEach(function() {
        mockery.resetCache();
    });

    afterEach(function() {
        mockery.deregisterAll();
    });

    it('should call jobManager findAvailableJob on getAvailable action', function(done){
        var expectedCodes = ['somecode'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes){
                    expect(codes).to.eql(expectedCodes);
                    done();
                }
            };
        };

        var mockResponse = {
            json: function(){}
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: expectedCodes[0]
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should split codes into an array before calling findAvailableJob', function(done){
        var expectedCodes = ['code1', 'code2'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes){
                    expect(codes).to.eql(expectedCodes);
                    done();
                }
            };
        };

        var mockResponse = {
            json: function(){}
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should return result using the json method of the response', function(done){
        var job = {
            found: 'me'
        };
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, callback){
                    callback(null, job);
                }
            };
        };

        var mockResponse = {
            json: function(response) {
                expect(response).to.eql(job);
                done();
            }
        };

        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should call next with err when findAvailableJob gets an error', function(done){
        var error = new Error('uh oh');
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, callback){
                    callback(error, null);
                }
            };
        };

        var mockResponse = {

        };

        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(err) {
            expect(err).to.eql(error);
            done();
        });
    });

    it('should set statuscode to 404 when available job is not found', function(done){
        var expectedCodes = ['code1', 'code2'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, callback){
                    callback(null);
                }
            };
        };

        var mockResponse = {
            status: function(value){
                expect(value).to.eql(404);
                return {
                    json: function(response){
                        expect(response.message).to.eql('available job not found');
                        done();
                    }
                }
            }
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);<commit_msg>fix tests<commit_after>describe('job-controller: getAvailable tests', function(){

    var mockery = require('mockery');
    var expect = require('chai').expect;

    before(function() {
        mockery.enable({
            useCleanCache: true,
            warnOnUnregistered: false
        });
    });

    beforeEach(function() {
        mockery.resetCache();
    });

    afterEach(function() {
        mockery.deregisterAll();
    });

    it('should call jobManager findAvailableJob on getAvailable action', function(done){
        var expectedCodes = ['somecode'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes){
                    expect(codes).to.eql(expectedCodes);
                    done();
                }
            };
        };

        var mockResponse = {
            json: function(){}
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: expectedCodes[0]
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should split codes into an array before calling findAvailableJob', function(done){
        var expectedCodes = ['code1', 'code2'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes){
                    expect(codes).to.eql(expectedCodes);
                    done();
                }
            };
        };

        var mockResponse = {
            json: function(){}
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should return result using the json method of the response', function(done){
        var job = {
            found: 'me'
        };
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, caller, callback){
                    callback(null, job);
                }
            };
        };

        var mockResponse = {
            json: function(response) {
                expect(response).to.eql(job);
                done();
            }
        };

        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(){});
    });

    it('should call next with err when findAvailableJob gets an error', function(done){
        var error = new Error('uh oh');
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, caller, callback){
                    callback(error, null);
                }
            };
        };

        var mockResponse = {

        };

        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);

        var JobController = require('../../../src/api/controllers/job.js');
        var controller = new JobController({});

        controller.getAvailable(mockRequest, mockResponse, function(err) {
            expect(err).to.eql(error);
            done();
        });
    });

    it('should set statuscode to 404 when available job is not found', function(done){
        var expectedCodes = ['code1', 'code2'];
        var mockManager = function(){
            return {
                findAvailableJob: function(codes, caller, callback){
                    callback(null);
                }
            };
        };

        var mockResponse = {
            status: function(value){
                expect(value).to.eql(404);
                return {
                    json: function(response){
                        expect(response.message).to.eql('available job not found');
                        done();
                    }
                }
            }
        };
        var mockRequest = {
            checkQuery: function(){
                return {
                    notEmpty: function(){}
                }
            },
            validationErrors: function(){},
            query: {
                codes: 'code1,code2'
            }
        };

        mockery.registerMock('../../managers/job-manager.js', mockManager);
{'fraction_non_alphanumeric': 0.12460429124164615, 'fraction_numerical': 0.003341540626099191, 'mean_word_length': 1.3319663727701456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6542049', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2609, 'n_words': 553}