<commit_before>const API_USER_LOGIN_URL = require('../../data/constants').API_USER_LOGIN_URL;
const API_GAME_GET_GAME_BY_ID_URL = require('../../data/constants').API_GAME_GET_GAME_BY_ID_URL;
const API_GAME_GET_GAMES_URL = require('../../data/constants').API_GAME_GET_GAMES_URL;

const knex = require('../../../app/lib/db');
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../../../app');

const should = chai.should();

chai.use(chaiHttp);
let userToken = null;

describe('Game Retrieval API Tests', () => {
  before((done) => {
    // Get and set valid auth token for user requests
    function getUserToken() {
      chai.request(server)
          .post(`${API_USER_LOGIN_URL}`)
          .send({
            username: 'test_user_professor',
            password: 'password',
          })
          .end((err, res) => {
            userToken = res.body.token;
            done();
          });
    }

    // Run initial migrations and seed db
    knex.migrate.rollback()
      .then(() => {
        knex.migrate.latest()
          .then(() => {
            knex.seed.run()
              .then(() => getUserToken());
          });
      });
  });

  describe('Success', () => {
    it('A Game can be retrieved withRelated teams, storyteller', (done) => {
      const gameId = 1;
      chai.request(server)
          .get(`${API_GAME_GET_GAME_BY_ID_URL}${gameId}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ withRelated: ['teams', 'storyteller'] })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.id.should.equal(gameId);
            res.body.teams.should.be.an('array');
            res.body.storyteller_id.should.equal(res.body.storyteller.id);
            done();
          });
    });
    it('All Games can be retrieved withRelated teams, storyteller', (done) => {
      chai.request(server)
          .get(`${API_GAME_GET_GAMES_URL}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ withRelated: ['teams', 'storyteller'] })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.should.be.an('array');
            // check first game for teams and storyteller
            res.body[0].teams.should.be.an('array');
            res.body[0].storyteller_id.should.equal(res.body[0].storyteller.id);
            done();
          });
    });
  });


  describe('Fail', () => {

  });
});<commit_msg>Add tests for storyteller_id query param.<commit_after>const API_USER_LOGIN_URL = require('../../data/constants').API_USER_LOGIN_URL;
const API_GAME_GET_GAME_BY_ID_URL = require('../../data/constants').API_GAME_GET_GAME_BY_ID_URL;
const API_GAME_GET_GAMES_URL = require('../../data/constants').API_GAME_GET_GAMES_URL;

const knex = require('../../../app/lib/db');
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../../../app');

const should = chai.should();

chai.use(chaiHttp);
let userToken = null;

describe('Game Retrieval API Tests', () => {
  before((done) => {
    // Get and set valid auth token for user requests
    function getUserToken() {
      chai.request(server)
          .post(`${API_USER_LOGIN_URL}`)
          .send({
            username: 'test_user_professor',
            password: 'password',
          })
          .end((err, res) => {
            userToken = res.body.token;
            done();
          });
    }

    // Run initial migrations and seed db
    knex.migrate.rollback()
      .then(() => {
        knex.migrate.latest()
          .then(() => {
            knex.seed.run()
              .then(() => getUserToken());
          });
      });
  });

  describe('Success', () => {
    it('A Game can be retrieved withRelated teams, storyteller', (done) => {
      const gameId = 1;
      chai.request(server)
          .get(`${API_GAME_GET_GAME_BY_ID_URL}${gameId}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ withRelated: ['teams', 'storyteller'] })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.id.should.equal(gameId);
            res.body.teams.should.be.an('array');
            res.body.storyteller_id.should.equal(res.body.storyteller.id);
            done();
          });
    });
    it('All Games can be retrieved withRelated teams, storyteller', (done) => {
      chai.request(server)
          .get(`${API_GAME_GET_GAMES_URL}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ withRelated: ['teams', 'storyteller'] })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.should.be.an('array');
            // check first game for teams and storyteller
            res.body[0].teams.should.be.an('array');
            res.body[0].storyteller_id.should.equal(res.body[0].storyteller.id);
            done();
          });
    });
    it('All Games can be retrieved given a valid storyteller id', (done) => {
      const storytellerId = 1;
      chai.request(server)
          .get(`${API_GAME_GET_GAMES_URL}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ storyteller_id: storytellerId })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.should.be.an('array');
            res.body.length.should.equal(1);
            done();
          });
    });
  });


  describe('Fail', () => {
    it('No Games can be retrieved given an invalid storyteller id', (done) => {
      const storytellerId = 100;
      chai.request(server)
          .get(`${API_GAME_GET_GAMES_URL}`)
          .set('Authorization', `Bearer ${userToken}`)
          .query({ storyteller_id: storytellerId })
          .end((err, res) => {
            should.not.exist(err);
            res.statusCode.should.equal(200);
            res.body.should.be.an('array');
            res.body.length.should.equal(0);
            done();
          });
    });
  });
});
{'fraction_non_alphanumeric': 0.17259128196879525, 'fraction_numerical': 0.005147177095061927, 'mean_word_length': 2.118355065195587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '7134557', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1977, 'n_words': 329}