<commit_before>var dotEnv = require('dotenv').config();
var db = require("../modules/testDB");
var shift = require("../modules/shiftManager");
var assert = require('assert');

// Point the busManager DB reference to modules/testDB
// Note that the scope of the path is busManager, NOT
// this file.
shift.setDB('./testDB');

describe('shiftManager', function(){
  // Gross chain of SQL inserts... If we can clean this up, we should.
  before(function() {
    db.query("ALTER SEQUENCE driver_id_seq RESTART;");
    db.query("ALTER SEQUENCE shift_id_seq RESTART;");
    db.query("DELETE FROM shift;")
    db.query("DELETE FROM driver;")
    db.query("DELETE FROM bus;");
    db.query("DELETE FROM route;");
    var insertRoute = "INSERT INTO route (number, valid_bus_types) VALUES (30, ARRAY['a', 'b']);";
    db.query(insertRoute);
    var insertBus = "INSERT INTO bus (id, type, defects) VALUES ('bus1', 'type1', 'none');";
    db.query(insertBus);
    var insertDriver = "INSERT INTO driver (name, phone, late_count) VALUES ('andrew', '1234567890', 0);";
    db.query(insertDriver);

    var insertShift = "INSERT INTO shift (start_time, end_time, start_location, \
      end_location, driver_id, bus_id, route) VALUES \
      (make_timestamptz(2017, 4, 17, 8, 0, 0), make_timestamptz(2017, 4, 17, 12, 0, 0), \
      'start location 1', 'end location 1', 1,'bus1', 30);";
    return db.query(insertShift);
  });

  describe('#setStartTime()', function() {
		it('should change the start time of a shift', function() {
      time = new Date(2017,3,1,8,0,0,0);
      return shift.setStartTime(1, time)
      .then(function(res) {
        var res_start_time = res.rows[0].start_time;
        assert.equal('2017-04-01T08:00:00.000Z',res_start_time.toISOString());
      });
		});
	});

  describe('#setEndTime()', function() {
		it('should change the end time of a shift', function() {
      time = new Date(2017,3,1,8,0,0,0);<commit_msg>added three tests for getShiftByDay, testing all options for parameters passed<commit_after>var dotEnv = require('dotenv').config();
var db = require("../modules/testDB");
var shift = require("../modules/shiftManager");
var assert = require('assert');

// Point the busManager DB reference to modules/testDB
// Note that the scope of the path is busManager, NOT
// this file.
shift.setDB('./testDB');

describe('shiftManager', function(){
  // Gross chain of SQL inserts... If we can clean this up, we should.
  before(function() {
    db.query("ALTER SEQUENCE driver_id_seq RESTART;");
    db.query("ALTER SEQUENCE shift_id_seq RESTART;");
    db.query("DELETE FROM shift;")
    db.query("DELETE FROM driver;")
    db.query("DELETE FROM bus;");
    db.query("DELETE FROM route;");
    var insertRoute = "INSERT INTO route (number, valid_bus_types) VALUES (30, ARRAY['a', 'b']);";
    db.query(insertRoute);
    var insertBus = "INSERT INTO bus (id, type, defects) VALUES ('bus1', 'type1', 'none');";
    db.query(insertBus);
    var insertDriver = "INSERT INTO driver (name, phone, late_count) VALUES ('andrew', '1234567890', 0);";
    db.query(insertDriver);

    var insertShift = "INSERT INTO shift (start_time, end_time, start_location, \
      end_location, driver_id, bus_id, route) VALUES \
      (make_timestamptz(2017, 4, 17, 8, 0, 0), make_timestamptz(2017, 4, 17, 12, 0, 0), \
      'start location 1', 'end location 1', 1,'bus1', 30);";
    return db.query(insertShift);
  });

  describe('#getShiftByDay()', function() {
    it('should return the shifts given a day', function() {
      date = new Date(2017,3,17,8,0,0,0);
      return shift.getShiftByDay(date)
      .then(function(res) {
        assert.equal(1,res.rowCount);
      });
    });
  });

  describe('#getShiftByDay()', function() {
    it('should not return anything if there are no shifts today', function() {
      date = new Date(2015,5,21,9,0,0,0);
      return shift.getShiftByDay(date)
      .then(function(res) {
        assert.equal(0,res.rowCount);
      });
    });
  });

  describe('#getShiftByDay()', function() {
    before(function() {
      d = new Date();
      var insertShift = `INSERT INTO shift (start_time, end_time, start_location,
        end_location, driver_id, bus_id, route) VALUES
        (make_timestamptz($1, $2, $3, 8, 0, 0),
        make_timestamptz($1, $2, $3, 10, 0, 0),
        'EXAMPLE', 'end location 1', 1,'bus1', 30);`;
      return db.query(insertShift, [d.getFullYear(), d.getMonth() + 1, d.getDate()]);
    });

    it('should get todays shifts by default', function() {
      return shift.getShiftByDay()
      .then(function(res) {
        assert.equal(1,res.rowCount);
      });
    });

    after(function() {
      db.query("DELETE FROM shift WHERE start_location = 'EXAMPLE' ")
    })
  });

  describe('#setStartTime()', function() {
		it('should change the start time of a shift', function() {
      time = new Date(2017,3,1,8,0,0,0);
      return shift.setStartTime(1, time)
      .then(function(res) {
        var res_start_time = res.rows[0].start_time;
        assert.equal('2017-04-01T08:00:00.000Z',res_start_time.toISOString());
      });
		});
	});

  describe('#setEndTime()', function() {
		it('should change the end time of a shift', function() {
      time = new Date(2017,3,1,8,0,0,0);
{'fraction_non_alphanumeric': 0.1668567084758647, 'fraction_numerical': 0.039148612694792854, 'mean_word_length': 3.5924956369982546, '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': '2711006', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1725, 'n_words': 461}