<commit_before>const knex = require('../../../../app/lib/db');
const chai = require('chai');
const EventController = require('../../../../app/controllers/event');
const MockExpressResponse = require('mock-express-response');

const should = chai.should();
const assert = chai.assert;

// Timeout to be used for checking controller responses
const timeout = 250;

function getMockCreateEventReq() {
  return {
    body: {
      name: 'Hey! Im testin here!',
      description: 'New event for testing!',
      default_damage: 100,
      disabled: false,
    },
  };
}

describe('Event Controller Tests', () => {
  describe('event controller createEvent', () => {
    before((done) => {
      knex.migrate.rollback()
        .then(() => {
          knex.migrate.latest()
            .then(() => {
              knex.seed.run()
                .then(() => {
                  done();
                });
            });
        });
    });
    after((done) => {
      knex.migrate.rollback()
        .then(() => {
          knex.migrate.latest()
            .then(() => {
              knex.seed.run()
                .then(() => {
                  done();
                });
            });
        });
    });

    describe('event controller createEvent success', () => {
      it('should succeed createEvent', (done) => {
        const mockReq = getMockCreateEventReq();
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(200);
          mockRes.statusMessage.should.equal('OK');
          done();
        }, timeout);
      });
    });

    describe('event controller createEvent fail', () => {
      it('should fail createEvent missing name', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.name;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
      it('should fail createEvent missing description', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.description;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
      it('should fail createEvent missing default_damage', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.default_damage;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
    });
  });

  describe('event controller getEvents', () => {
    describe('event Controller getEvents success', () => {
      it('should succeed getEvents', (done) => {
        const mockReq = {
          body: { },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEvents(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(200);
          const resJSON = mockRes._getJSON();
          resJSON.should.be.an('array');
          done();
        }, timeout);
      });
    });
  });

  describe('event controller getEventById', () => {
    describe('event Controller getEventById success', () => {
      it('should succeed getEventById', (done) => {
        const mockReq = {
          params: { id: 1 },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEventById(mockReq, mockRes);
        setTimeout(() => {
          console.log(mockRes._getJSON());
          mockRes.statusCode.should.equal(200);
          const resJSON = mockRes._getJSON();
          resJSON.id.should.equal(1);
          done();
        }, timeout);
      });
    });
    describe('event Controller getEventById fail', () => {
      it('should fail getEventById', (done) => {
        const mockReq = {
          params: { id: 100 },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEventById(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(404);
          const resJSON = mockRes._getJSON();
          resJSON.error.should.equal('An Event with that ID could not be found.');
          assert.deepEqual(resJSON.request, mockReq);
          done();
        }, timeout);
      });
    });
  });
});<commit_msg>Removed a console.log output in a test<commit_after>const knex = require('../../../../app/lib/db');
const chai = require('chai');
const EventController = require('../../../../app/controllers/event');
const MockExpressResponse = require('mock-express-response');

const should = chai.should();
const assert = chai.assert;

// Timeout to be used for checking controller responses
const timeout = 250;

function getMockCreateEventReq() {
  return {
    body: {
      name: 'Hey! Im testin here!',
      description: 'New event for testing!',
      default_damage: 100,
      disabled: false,
    },
  };
}

describe('Event Controller Tests', () => {
  describe('event controller createEvent', () => {
    before((done) => {
      knex.migrate.rollback()
        .then(() => {
          knex.migrate.latest()
            .then(() => {
              knex.seed.run()
                .then(() => {
                  done();
                });
            });
        });
    });
    after((done) => {
      knex.migrate.rollback()
        .then(() => {
          knex.migrate.latest()
            .then(() => {
              knex.seed.run()
                .then(() => {
                  done();
                });
            });
        });
    });

    describe('event controller createEvent success', () => {
      it('should succeed createEvent', (done) => {
        const mockReq = getMockCreateEventReq();
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(200);
          mockRes.statusMessage.should.equal('OK');
          done();
        }, timeout);
      });
    });

    describe('event controller createEvent fail', () => {
      it('should fail createEvent missing name', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.name;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
      it('should fail createEvent missing description', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.description;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
      it('should fail createEvent missing default_damage', (done) => {
        const mockReq = getMockCreateEventReq();
        delete mockReq.body.default_damage;
        const mockRes = new MockExpressResponse();
        EventController.createEvent(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(400);
          mockRes.statusMessage.should.equal('Bad Request');
          done();
        }, timeout);
      });
    });
  });

  describe('event controller getEvents', () => {
    describe('event Controller getEvents success', () => {
      it('should succeed getEvents', (done) => {
        const mockReq = {
          body: { },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEvents(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(200);
          const resJSON = mockRes._getJSON();
          resJSON.should.be.an('array');
          done();
        }, timeout);
      });
    });
  });

  describe('event controller getEventById', () => {
    describe('event Controller getEventById success', () => {
      it('should succeed getEventById', (done) => {
        const mockReq = {
          params: { id: 1 },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEventById(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(200);
          const resJSON = mockRes._getJSON();
          resJSON.id.should.equal(1);
          done();
        }, timeout);
      });
    });
    describe('event Controller getEventById fail', () => {
      it('should fail getEventById', (done) => {
        const mockReq = {
          params: { id: 100 },
        };
        const mockRes = new MockExpressResponse();
        EventController.getEventById(mockReq, mockRes);
        setTimeout(() => {
          mockRes.statusCode.should.equal(404);
          const resJSON = mockRes._getJSON();
          resJSON.error.should.equal('An Event with that ID could not be found.');
          assert.deepEqual(resJSON.request, mockReq);
          done();
        }, timeout);
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.1495443247721624, 'fraction_numerical': 0.006628003314001657, 'mean_word_length': 2.0744985673352434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 65, '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': '1365525', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2561, 'n_words': 525}