var chai = require('chai')
	expect = chai.expect,
	should = chai.should(),
	chaiAsPromised = require('chai-as-promised'),
	rewire = require('rewire'),
	cornelius = rewire('../index');

chai.use(chaiAsPromised);

// Mock data - MLB response from player search using surname 'young'
let mlbSearchResponse = require('./mock.search.json');

let findPlayerInResults = cornelius.__get__('findPlayerInResults');

describe('findPlayerInResults', function () {
	let options = {
		data: mlbSearchResponse,
		validKey: 'bos',
		unmatchedKey: 'inv',
		invalidKey: 123
	}
	it('should return a player object', function () {
		let foundPlayer = findPlayerInResults(options.data, options.validKey);
		expect(foundPlayer).to.be.an('object').and.have.property('name_display_first_last');
		expect(foundPlayer.name_display_first_last).to.equal('Chris Young');
	});
	it('should return an error when not given a key', function () {
		let error = findPlayerInResults(options.data);
		expect(error).to.be.an('error');
		expect(error.message).to.equal('findPlayerInResults wasn\'t given a key.')
	});
	it('should return an error when given an unmatched key', function () {
		let error = findPlayerInResults(options.data, options.unmatchedKey);
		expect(error).to.be.an('error');
		expect(error.message).to.equal('No player found with matching key.');
	});
	it('should return an error when given an invalid key type', function() {
		let error = findPlayerInResults(options.data, options.invalidKey);
		expect(error).to.be.an('error');
		expect(error.message).to.equal(`findPlayerInResults expected key to be a string, but was given a ${typeof(options.invalidKey)}.`)
	});
});

@@ -500,17 +500,44 @@
 alid
+Team
 Key: '
-bos
+kc',%0A%09%09validIDKey: '455759
 ',%0A%09
@@ -602,23 +602,440 @@
 urn 
-a player object
+the correct player object when given a team_abbrev key', function () %7B%0A%09%09let foundPlayer = findPlayerInResults(options.data, options.validTeamKey);%0A%09%09expect(foundPlayer).to.be.an('object').and.have.property('name_display_first_last');%0A%09%09expect(foundPlayer.name_display_first_last).to.equal('Chris Young');%0A%09%09expect(foundPlayer.team_abbrev).to.equal('KC');%0A%09%7D);%0A%09it('should return the correct player object when given a player_id key
 ', f
@@ -1110,24 +1110,26 @@
 ptions.valid
+ID
 Key);%0A%09%09expe
@@ -1276,24 +1276,75 @@
 is Young');%0A
+%09%09expect(foundPlayer.team_abbrev).to.equal('BOS');%0A
 %09%7D);%0A%09it('sh

update tests to use player ID and team abbreviation