<commit_before>// testing modules
var request = require('supertest'),
    chai = require("chai"),
    sinon = require("sinon"),
    expect = chai.expect;

// for mocking
var projectAwesome = require('project-awesome');

// web app
var app = require('../../../app.js');
var server;

describe('v1 API', function() {

    before(function(done) {
        server = app.listen(app.get('port'),function() {
            done();
        });
    });

    after(function() {
        server.close();
    });

    describe('GET /list', function() {
        var listStub;
        beforeEach(function() {
            listStub = sinon.stub(projectAwesome, 'list');
            listStub.withArgs('invalid-type').throws("Illegal Argument");
            listStub.withArgs('valid-type').returns('list-response');
        });
        afterEach(function() {
            listStub.restore();
        });
        describe('response body', function() {
            var resBody;
            beforeEach(function(done) {
                request(app)
                    .get('/v1/list?type=valid-type')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        resBody = res.body;
                        done();
                    });
            });
            it('should be a json object', function() {
                expect(resBody).to.be.an('object');
            });
            it('should contain a list property with the appropriate result', function() {
                expect(resBody.list).to.equal('list-response');
            });
        });
        describe('when projectAwesome.list throws an error', function() {
            it('should respond with error code 400 and a message', function(done) {
                request(app)
                    .get('/v1/list?type=invalid-type')
                    .expect(400)
                    .end(function(err, res) {
                        if (err) return done(err);
                        expect(res.body).to.eql({"error":{"name":"Illegal Argument"}});
                        done();
                    });
            });
        });
    });

    describe('GET /check', function() {

        it('should validate correct seeds', function(done) {
        request(app)
                .get('/v1/check?type=seed&value=abcd1234')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":true});
                    done();
                });
        });

        it('should validate incorrect seeds', function(done) {
            request(app)
                .get('/v1/check?type=seed&value=incorrectSeedV2')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":false});
                    done();
                });
        });
        
        describe('when projectAwesome.check throws an error', function() {
            it('should respond with error code 400', function(done) {
                request(app)
                    .get('/v1/check?type=invalid-type')
                    .expect(400)
                     .end(function(err, res) {
                        if (err) return done(err);
                        expect(res.body).eql({ error: 'Illegal Argument: invalid-type'});
                        done();
                    });
            });
        });
        
        describe('when projectAwesome.check recieves no type', function() {
            it('should respond with error code 400 and include a message', function(done) {
                request(app)
                    .get('/v1/check?type=')
                    .expect(400)
                    .end(done);
            });
        });
        
        
        it('should validate correct questionTypes', function(done) {
            request(app)
                .get('/v1/check?type=questionType&value=mc-change-of-base')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":true});
                    done();
                });
        });

        it('should validate incorrect questionTypes', function(done) {
            request(app)
                .get('/v1/check?type=questionType&value=incorrectQuestionType')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":false});
                    done();
                });<commit_msg>MC/PC updated tests to reflect rename of questionType to problemType in project-awesome itself<commit_after>// testing modules
var request = require('supertest'),
    chai = require("chai"),
    sinon = require("sinon"),
    expect = chai.expect;

// for mocking
var projectAwesome = require('project-awesome');

// web app
var app = require('../../../app.js');
var server;

describe('v1 API', function() {

    before(function(done) {
        server = app.listen(app.get('port'),function() {
            done();
        });
    });

    after(function() {
        server.close();
    });

    describe('GET /list', function() {
        var listStub;
        beforeEach(function() {
            listStub = sinon.stub(projectAwesome, 'list');
            listStub.withArgs('invalid-type').throws("Illegal Argument");
            listStub.withArgs('valid-type').returns('list-response');
        });
        afterEach(function() {
            listStub.restore();
        });
        describe('response body', function() {
            var resBody;
            beforeEach(function(done) {
                request(app)
                    .get('/v1/list?type=valid-type')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        resBody = res.body;
                        done();
                    });
            });
            it('should be a json object', function() {
                expect(resBody).to.be.an('object');
            });
            it('should contain a list property with the appropriate result', function() {
                expect(resBody.list).to.equal('list-response');
            });
        });
        describe('when projectAwesome.list throws an error', function() {
            it('should respond with error code 400 and a message', function(done) {
                request(app)
                    .get('/v1/list?type=invalid-type')
                    .expect(400)
                    .end(function(err, res) {
                        if (err) return done(err);
                        expect(res.body).to.eql({"error":{"name":"Illegal Argument"}});
                        done();
                    });
            });
        });
    });

    describe('GET /check', function() {

        it('should validate correct seeds', function(done) {
        request(app)
                .get('/v1/check?type=seed&value=abcd1234')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":true});
                    done();
                });
        });

        it('should validate incorrect seeds', function(done) {
            request(app)
                .get('/v1/check?type=seed&value=incorrectSeedV2')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":false});
                    done();
                });
        });
        
        describe('when projectAwesome.check throws an error', function() {
            it('should respond with error code 400', function(done) {
                request(app)
                    .get('/v1/check?type=invalid-type')
                    .expect(400)
                     .end(function(err, res) {
                        if (err) return done(err);
                        expect(res.body).eql({ error: 'Illegal Argument: invalid-type'});
                        done();
                    });
            });
        });
        
        describe('when projectAwesome.check recieves no type', function() {
            it('should respond with error code 400 and include a message', function(done) {
                request(app)
                    .get('/v1/check?type=')
                    .expect(400)
                    .end(done);
            });
        });
        
        
        it('should validate correct problemTypes', function(done) {
            request(app)
                .get('/v1/check?type=problemType&value=mc-change-of-base')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":true});
                    done();
                });
        });

        it('should validate incorrect problemTypes', function(done) {
            request(app)
                .get('/v1/check?type=problemType&value=incorrectProblemType')
                .expect(200)
                .end(function(err, res) {
                    if (err) return done(err);
                    expect(res.body).to.eql({"valid":false});
                    done();
                });
{'fraction_non_alphanumeric': 0.13985720285594289, 'fraction_numerical': 0.009869802603947922, 'mean_word_length': 1.3282815937423613, 'pattern_counts': {'":': 12, '<': 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': '6233944', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2363, 'n_words': 466}