From 8eb590ce29d1dfd1f9e6df2e9147f5e69664992e Mon Sep 17 00:00:00 2001 From: ncousineau Date: Thu, 4 Aug 2022 10:39:50 -0600 Subject: [PATCH] tmp add out for testing --- out/lib/node-sportsdata.js | 60 ++++ out/lib/sport-api.js | 299 ++++++++++++++++++ out/lib/v1/ncaafb.js | 115 +++++++ out/lib/v1/nfl.js | 28 ++ out/lib/v1/v1.js | 73 +++++ out/lib/v3/mlb.js | 54 ++++ out/lib/v3/ncaamb.js | 128 ++++++++ out/lib/v3/ncaawb.js | 24 ++ out/lib/v7/ncaafb.js | 24 ++ out/lib/v7/v7.js | 140 ++++++++ out/test/node-sportsdata_test.js | 206 ++++++++++++ out/test/v1/ncaafb-extended-boxscore_test.js | 97 ++++++ out/test/v1/ncaafb-play-by-play_test.js | 95 ++++++ out/test/v1/ncaafb-standings_test.js | 80 +++++ out/test/v1/ncaafb-teams-hierarchy_test.js | 64 ++++ out/test/v1/ncaafb-weekly-schedule_test.js | 69 ++++ out/test/v1/nfl-extended-boxscore_test.js | 97 ++++++ out/test/v1/nfl-play-by-play_test.js | 95 ++++++ out/test/v1/nfl-teams-hierarchy_test.js | 56 ++++ out/test/v1/nfl-weekly-schedule_test.js | 69 ++++ out/test/v3/mlb-3day-schedule_test.js | 49 +++ out/test/v3/mlb-daily-boxscore_test.js | 100 ++++++ out/test/v3/mlb-daily-events_test.js | 103 ++++++ out/test/v3/mlb-daily-schedule_test.js | 94 ++++++ out/test/v3/mlb-event-boxscore_test.js | 77 +++++ out/test/v3/mlb-event-pbp_test.js | 77 +++++ out/test/v3/mlb-event-statistics_test.js | 81 +++++ out/test/v3/mlb-event_test.js | 77 +++++ out/test/v3/mlb-glossary_test.js | 51 +++ out/test/v3/mlb-league-schedule_test.js | 79 +++++ out/test/v3/mlb-player-profile_test.js | 77 +++++ out/test/v3/mlb-player-stats_test.js | 79 +++++ out/test/v3/mlb-standings_test.js | 79 +++++ out/test/v3/mlb-team-rosters-active_test.js | 81 +++++ out/test/v3/mlb-team-rosters-full_test.js | 81 +++++ out/test/v3/mlb-team-stats_test.js | 81 +++++ out/test/v3/mlb-teams-hierarchy_test.js | 79 +++++ out/test/v3/mlb-venue-info_test.js | 48 +++ out/test/v3/ncaamb-daily-schedule_test.js | 98 ++++++ out/test/v3/ncaamb-game-boxscore_test.js | 77 +++++ out/test/v3/ncaamb-game-summary_test.js | 77 +++++ out/test/v3/ncaamb-schedule_test.js | 71 +++++ out/test/v3/ncaamb-standings_test.js | 81 +++++ out/test/v3/ncaamb-tournament-list_test.js | 72 +++++ .../v3/ncaamb-tournament-schedule_test.js | 73 +++++ 45 files changed, 3815 insertions(+) create mode 100644 out/lib/node-sportsdata.js create mode 100644 out/lib/sport-api.js create mode 100644 out/lib/v1/ncaafb.js create mode 100644 out/lib/v1/nfl.js create mode 100644 out/lib/v1/v1.js create mode 100644 out/lib/v3/mlb.js create mode 100644 out/lib/v3/ncaamb.js create mode 100644 out/lib/v3/ncaawb.js create mode 100644 out/lib/v7/ncaafb.js create mode 100644 out/lib/v7/v7.js create mode 100644 out/test/node-sportsdata_test.js create mode 100644 out/test/v1/ncaafb-extended-boxscore_test.js create mode 100644 out/test/v1/ncaafb-play-by-play_test.js create mode 100644 out/test/v1/ncaafb-standings_test.js create mode 100644 out/test/v1/ncaafb-teams-hierarchy_test.js create mode 100644 out/test/v1/ncaafb-weekly-schedule_test.js create mode 100644 out/test/v1/nfl-extended-boxscore_test.js create mode 100644 out/test/v1/nfl-play-by-play_test.js create mode 100644 out/test/v1/nfl-teams-hierarchy_test.js create mode 100644 out/test/v1/nfl-weekly-schedule_test.js create mode 100644 out/test/v3/mlb-3day-schedule_test.js create mode 100644 out/test/v3/mlb-daily-boxscore_test.js create mode 100644 out/test/v3/mlb-daily-events_test.js create mode 100644 out/test/v3/mlb-daily-schedule_test.js create mode 100644 out/test/v3/mlb-event-boxscore_test.js create mode 100644 out/test/v3/mlb-event-pbp_test.js create mode 100644 out/test/v3/mlb-event-statistics_test.js create mode 100644 out/test/v3/mlb-event_test.js create mode 100644 out/test/v3/mlb-glossary_test.js create mode 100644 out/test/v3/mlb-league-schedule_test.js create mode 100644 out/test/v3/mlb-player-profile_test.js create mode 100644 out/test/v3/mlb-player-stats_test.js create mode 100644 out/test/v3/mlb-standings_test.js create mode 100644 out/test/v3/mlb-team-rosters-active_test.js create mode 100644 out/test/v3/mlb-team-rosters-full_test.js create mode 100644 out/test/v3/mlb-team-stats_test.js create mode 100644 out/test/v3/mlb-teams-hierarchy_test.js create mode 100644 out/test/v3/mlb-venue-info_test.js create mode 100644 out/test/v3/ncaamb-daily-schedule_test.js create mode 100644 out/test/v3/ncaamb-game-boxscore_test.js create mode 100644 out/test/v3/ncaamb-game-summary_test.js create mode 100644 out/test/v3/ncaamb-schedule_test.js create mode 100644 out/test/v3/ncaamb-standings_test.js create mode 100644 out/test/v3/ncaamb-tournament-list_test.js create mode 100644 out/test/v3/ncaamb-tournament-schedule_test.js diff --git a/out/lib/node-sportsdata.js b/out/lib/node-sportsdata.js new file mode 100644 index 0000000..3892f96 --- /dev/null +++ b/out/lib/node-sportsdata.js @@ -0,0 +1,60 @@ +/* + +node-sportsdata +https://github.com/pac12/node-sportsdata + +Copyright (c) 2013 PAC-12 +Licensed under the MIT license. +*/ + + +(function() { + 'use strict'; + var MLB, NCAAFB, NCAAFBv7, NCAAMB, NCAAWB, NFL; + + MLB = require('./v3/mlb'); + + NCAAFB = require('./v1/ncaafb'); + + NCAAMB = require('./v3/ncaamb'); + + NCAAWB = require('./v3/ncaawb'); + + NFL = require('./v1/nfl'); + + NCAAFBv7 = require('./v7/ncaafb'); + + exports.awesome = function() { + return 'awesome'; + }; + + exports.v7 = { + ncaafb: function(apiKey, accessLevel, testLeague) { + return new NCAAFBv7(apiKey, accessLevel, testLeague); + } + }; + + exports.v3 = { + mlb: function(apiKey, accessLevel, testLeague) { + return new MLB(apiKey, accessLevel, testLeague); + }, + ncaamb: function(apiKey, accessLevel, testLeague) { + return new NCAAMB(apiKey, accessLevel, testLeague); + }, + ncaawb: function(apiKey, accessLevel, testLeague) { + return new NCAAWB(apiKey, accessLevel, testLeague); + } + }; + + exports.v2 = {}; + + exports.v1 = { + ncaafb: function(apiKey, accessLevel, testLeague) { + return new NCAAFB(apiKey, accessLevel, testLeague); + }, + nfl: function(apiKey, accessLevel, testLeague) { + return new NFL(apiKey, accessLevel, testLeague); + } + }; + +}).call(this); diff --git a/out/lib/sport-api.js b/out/lib/sport-api.js new file mode 100644 index 0000000..0fd4230 --- /dev/null +++ b/out/lib/sport-api.js @@ -0,0 +1,299 @@ +(function() { + var SportApi, http, moment, sprintf, xml2js; + + http = require('http'); + + sprintf = require('sprintf-js').sprintf; + + xml2js = require('xml2js'); + + moment = require('moment'); + + SportApi = (function() { + SportApi.prototype.domain = 'api.sportsdatallc.org'; + + SportApi.prototype.parser = new xml2js.Parser({ + trim: true, + normalize: true, + mergeAttrs: true, + explicitArray: false + }); + + function SportApi(apiKey, accessLevel, testLeague) { + this.apiKey = apiKey; + this.accessLevel = accessLevel; + this.testLeague = testLeague != null ? testLeague : false; + if (!apiKey) { + throw new Error('You must provide an API Key'); + } + if (!accessLevel) { + throw new Error('You must provide an Access Level'); + } + } + + SportApi.prototype.getRollingThreeDaySchedule = function(callback) { + return this.getResource('/schedule-3day', callback); + }; + + SportApi.prototype.getGlossary = function(callback) { + return this.getResource('/glossary/glossary.xml', callback); + }; + + /* + + Year based functions + */ + + + SportApi.prototype.getLeagueSchedule = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/schedule/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getTeamsHierarchy = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/teams/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getStandings = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/standings/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getTeamRostersActive = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/rosters/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getTeamRostersFull = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/rosters-full/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getTeamSeasonalStatistics = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/seasontd/teams/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getPlayersSeasonalStatistics = function(year, callback) { + var params, _ref; + _ref = this.getYearParams(year, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/seasontd/players/%(year)s.xml', params, callback); + }; + + SportApi.prototype.getYearParams = function(year, callback) { + if (typeof year === 'function') { + callback = year; + year = null; + } + if (!year) { + year = new Date().getFullYear(); + } + if (!year.year) { + year = { + year: year + }; + } + return [year, callback]; + }; + + /* + + EventID based functions + */ + + + SportApi.prototype.getEvent = function(eventId, callback) { + var params, _ref; + _ref = this.getEventParams(eventId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/event/%(eventId)s.xml', params, callback); + }; + + SportApi.prototype.getEventStatistics = function(eventId, callback) { + var params, _ref; + _ref = this.getEventParams(eventId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/statistics/%(eventId)s.xml', params, callback); + }; + + SportApi.prototype.getEventPlayByPlay = function(eventId, callback) { + var params, _ref; + _ref = this.getEventParams(eventId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/pbp/%(eventId)s.xml', params, callback); + }; + + SportApi.prototype.getEventBoxscore = function(eventId, callback) { + var params, _ref; + _ref = this.getEventParams(eventId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/boxscore/%(eventId)s.xml', params, callback); + }; + + SportApi.prototype.getEventParams = function(eventId, callback) { + if (!eventId || !callback) { + throw new Error('eventId and callback are required parameters'); + } + if (!eventId.eventId) { + eventId = { + eventId: eventId + }; + } + return [eventId, callback]; + }; + + /* + + GameID based functions + */ + + + SportApi.prototype.getGameBoxscore = function(gameId, callback) { + var params, _ref; + _ref = this.getGameParams(gameId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/games/%(gameId)s/boxscore.xml', params, callback); + }; + + SportApi.prototype.getGameSummary = function(gameId, callback) { + var params, _ref; + _ref = this.getGameParams(gameId, callback), params = _ref[0], callback = _ref[1]; + return this.getResource('/games/%(gameId)s/summary.xml', params, callback); + }; + + SportApi.prototype.getGameParams = function(gameId, callback) { + if (!gameId || !callback) { + throw new Error('gameId and callback are required parameters'); + } + if (!gameId.gameId) { + gameId = { + gameId: gameId + }; + } + return [gameId, callback]; + }; + + /* + + PlayerID based functions + */ + + + SportApi.prototype.getPlayerProfile = function(playerId, callback) { + if (!playerId || !callback) { + throw new Error('playerId and callback are required parameters'); + } + if (!playerId.playerId) { + playerId = { + playerId: playerId + }; + } + return this.getResource('/player/profile/%(playerId)s.xml', playerId, callback); + }; + + /* + + HELPER FUNCTIONS + */ + + + SportApi.prototype.getDailyParams = function(date, callback) { + var e, params; + if (typeof date === 'function') { + callback = date; + date = null; + } + if (!date) { + date = new Date(); + } + if (!date.date) { + date = { + date: date + }; + } + if (!(date.date instanceof Date)) { + try { + date.date = new Date(date.date); + } catch (_error) { + e = _error; + date.date = new Date(); + } + } + date = moment(date.date); + params = { + year: date.format('YYYY'), + month: date.format('MM'), + day: date.format('DD') + }; + return [params, callback]; + }; + + SportApi.prototype.getResource = function(pattern, params, callback) { + var e, options; + if (typeof params === 'function') { + callback = params; + params = {}; + } + try { + options = this.getHttpOptions(pattern, params); + } catch (_error) { + e = _error; + return callback(e); + } + return this.performHttpGet(options, callback); + }; + + SportApi.prototype.getHttpOptions = function(pattern, params) { + var options, path; + if (typeof params === 'undefined') { + params = {}; + } + path = "/" + this.league + "-"; + if (this.testLeague) { + path += "test-"; + } + path += "" + (this.accessLevel + this.version + sprintf(pattern, params) + sprintf('?api_key=%s', this.apiKey)); + return options = { + hostname: this.domain, + path: path + }; + }; + + SportApi.prototype.performHttpGet = function(options, callback) { + var req, + _this = this; + this.parser.reset(); + console.log(options); + return req = http.get(options, function(res) { + var data; + res.setEncoding('utf8'); + data = ''; + res.on('data', function(body) { + return data += body; + }); + res.on('end', function() { + if (200 !== res.statusCode) { + return callback('GET returned HTTP ' + res.statusCode); + } + return _this.parser.parseString(data, function(err, result) { + if (err) { + return callback('Parse error: ' + err); + } + return callback(null, result); + }); + }); + return req.on('error', function(e) { + return callback('Could not get ' + options + ': ' + err.message); + }); + }); + }; + + return SportApi; + + })(); + + module.exports = SportApi; + +}).call(this); diff --git a/out/lib/v1/ncaafb.js b/out/lib/v1/ncaafb.js new file mode 100644 index 0000000..7be7194 --- /dev/null +++ b/out/lib/v1/ncaafb.js @@ -0,0 +1,115 @@ +(function() { + var NCAAFB, V1, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + V1 = require('./v1'); + + NCAAFB = (function(_super) { + __extends(NCAAFB, _super); + + function NCAAFB() { + _ref = NCAAFB.__super__.constructor.apply(this, arguments); + return _ref; + } + + NCAAFB.prototype.league = 'ncaafb'; + + NCAAFB.prototype.getTeamsHierarchy = function(division, callback) { + var params, _ref1; + _ref1 = this.getDivisionParams(division, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/teams/%(division)s/hierarchy.xml', params, callback); + }; + + NCAAFB.prototype.getDivisionParams = function(division, callback) { + if (typeof division === 'function') { + callback = division; + division = null; + } + if (!division) { + division = 'FBS'; + } + if (!division.division) { + division = { + division: division + }; + } + return [division, callback]; + }; + + NCAAFB.prototype.getStandings = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/teams/FBS/%(year)s/%(season)s/standings.xml', params, callback); + }; + + NCAAFB.prototype.getYearSeasonParams = function(params, callback) { + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.year) { + params.year = new Date().getFullYear(); + } + if (!params.season) { + params.season = 'REG'; + } + return [params, callback]; + }; + + NCAAFB.prototype.getRankings = function(params, callback) { + var _ref1; + _ref1 = this.getYearWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/polls/AP25/%(year)s/%(week)s/rankings.xml', params, callback); + }; + + NCAAFB.prototype.getCfpRankings = function(params, callback) { + var _ref1; + _ref1 = this.getYearWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/polls/CFP25/%(year)s/%(week)s/rankings.xml', params, callback); + }; + + NCAAFB.prototype.getYearWeekParams = function(params, callback) { + var seasonWeek, week; + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.week) { + week = new Date(); + week.setHours(0, 0, 0); + week.setDate(week.getDate() + 1 - (week.getDay() || 7)); + week = Math.ceil((((week - new Date(week.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7); + if (week < 10) { + seasonWeek = (week + 52) - 34; + } else if (week < 35) { + seasonWeek = 1; + } else { + seasonWeek = week - 34; + } + params.week = seasonWeek; + } + if (!params.year) { + if (week < 10) { + params.year = new Date().getFullYear() - 1; + } + if (week >= 10) { + params.year = new Date().getFullYear(); + } + } + return [params, callback]; + }; + + return NCAAFB; + + })(V1); + + module.exports = NCAAFB; + +}).call(this); diff --git a/out/lib/v1/nfl.js b/out/lib/v1/nfl.js new file mode 100644 index 0000000..aebe149 --- /dev/null +++ b/out/lib/v1/nfl.js @@ -0,0 +1,28 @@ +(function() { + var NFL, V1, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + V1 = require('./v1'); + + NFL = (function(_super) { + __extends(NFL, _super); + + function NFL() { + _ref = NFL.__super__.constructor.apply(this, arguments); + return _ref; + } + + NFL.prototype.league = 'nfl'; + + NFL.prototype.getTeamsHierarchy = function(callback) { + return this.getResource('/teams/hierarchy.xml', callback); + }; + + return NFL; + + })(V1); + + module.exports = NFL; + +}).call(this); diff --git a/out/lib/v1/v1.js b/out/lib/v1/v1.js new file mode 100644 index 0000000..d0aefc4 --- /dev/null +++ b/out/lib/v1/v1.js @@ -0,0 +1,73 @@ +(function() { + var SportApi, V1, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + SportApi = require('../sport-api'); + + V1 = (function(_super) { + __extends(V1, _super); + + function V1() { + _ref = V1.__super__.constructor.apply(this, arguments); + return _ref; + } + + V1.prototype.version = 1; + + V1.prototype.getWeeklySchedule = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/%(year)s/%(season)s/%(week)s/schedule.xml', params, callback); + }; + + V1.prototype.getExtendedBoxscore = function(params, callback) { + var away, home, _ref1, _this; + home = params.home; + away = params.away; + _this = this; + _ref1 = this.getYearSeasonWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/%(year)s/%(season)s/%(week)s/%(away)s/%(home)s/extended-boxscore.xml', params, function(err, response) { + if (err === 'GET returned HTTP 404') { + params.home = away; + params.away = home; + return _this.getResource('/%(year)s/%(season)s/%(week)s/%(away)s/%(home)s/extended-boxscore.xml', params, callback); + } else { + return callback(null, response); + } + }); + }; + + V1.prototype.getPlayByPlay = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/%(year)s/%(season)s/%(week)s/%(away)s/%(home)s/pbp.xml', params, callback); + }; + + V1.prototype.getYearSeasonWeekParams = function(params, callback) { + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.year) { + params.year = new Date().getFullYear(); + } + if (!params.season) { + params.season = 'REG'; + } + if (!params.week) { + params.week = 1; + } + return [params, callback]; + }; + + return V1; + + })(SportApi); + + module.exports = V1; + +}).call(this); diff --git a/out/lib/v3/mlb.js b/out/lib/v3/mlb.js new file mode 100644 index 0000000..99480d0 --- /dev/null +++ b/out/lib/v3/mlb.js @@ -0,0 +1,54 @@ +(function() { + var MLB, SportApi, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + SportApi = require('../sport-api'); + + MLB = (function(_super) { + __extends(MLB, _super); + + function MLB() { + _ref = MLB.__super__.constructor.apply(this, arguments); + return _ref; + } + + MLB.prototype.league = 'mlb'; + + MLB.prototype.version = 3; + + MLB.prototype.getVenueInfo = function(callback) { + return this.getResource('/venues/venues.xml', callback); + }; + + /* + + Date based functions + */ + + + MLB.prototype.getDailySchedule = function(date, callback) { + var params, _ref1; + _ref1 = this.getDailyParams(date, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/daily/schedule/%(year)s/%(month)s/%(day)s.xml', params, callback); + }; + + MLB.prototype.getDailyEvents = function(date, callback) { + var params, _ref1; + _ref1 = this.getDailyParams(date, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/daily/event/%(year)s/%(month)s/%(day)s.xml', params, callback); + }; + + MLB.prototype.getDailyBoxscore = function(date, callback) { + var params, _ref1; + _ref1 = this.getDailyParams(date, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/daily/boxscore/%(year)s/%(month)s/%(day)s.xml', params, callback); + }; + + return MLB; + + })(SportApi); + + module.exports = MLB; + +}).call(this); diff --git a/out/lib/v3/ncaamb.js b/out/lib/v3/ncaamb.js new file mode 100644 index 0000000..0a43ac8 --- /dev/null +++ b/out/lib/v3/ncaamb.js @@ -0,0 +1,128 @@ +(function() { + var NCAAMB, SportApi, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + SportApi = require('../sport-api'); + + NCAAMB = (function(_super) { + __extends(NCAAMB, _super); + + function NCAAMB() { + _ref = NCAAMB.__super__.constructor.apply(this, arguments); + return _ref; + } + + NCAAMB.prototype.league = 'ncaamb'; + + NCAAMB.prototype.version = 3; + + /* + + Date based functions + */ + + + NCAAMB.prototype.getDailySchedule = function(date, callback) { + var params, _ref1; + _ref1 = this.getDailyParams(date, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/games/%(year)s/%(month)s/%(day)s/schedule.xml', params, callback); + }; + + /* + + Year / Season based functions + */ + + + NCAAMB.prototype.getSchedule = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/games/%(year)s/%(season)s/schedule.xml', params, callback); + }; + + NCAAMB.prototype.getStandings = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/seasontd/%(year)s/%(season)s/standings.xml', params, callback); + }; + + NCAAMB.prototype.getTournamentList = function(params, callback) { + var _ref1; + _ref1 = this.getYearSeasonParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/tournaments/%(year)s/%(season)s/schedule.xml', params, callback); + }; + + NCAAMB.prototype.getYearSeasonParams = function(params, callback) { + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.year) { + params.year = new Date().getFullYear(); + } + if (!params.season) { + params.season = 'REG'; + } + return [params, callback]; + }; + + NCAAMB.prototype.getRankings = function(params, callback) { + var _ref1; + _ref1 = this.getYearWeekParams(params, callback), params = _ref1[0], callback = _ref1[1]; + return this.getResource('/polls/AP/%(year)s/rankings.xml', params, callback); + }; + + NCAAMB.prototype.getYearWeekParams = function(params, callback) { + var day, diff, now, oneDay, start, year; + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.year) { + now = new Date(); + year = now.getFullYear(); + start = new Date(now.getFullYear(), 0, 0); + diff = now - start; + oneDay = 1000 * 60 * 60 * 24; + day = Math.floor(diff / oneDay); + if (day > 180) { + params.year = year; + } else { + params.year = year - 1; + } + } + return [params, callback]; + }; + + /* + + TournamentID based functions + */ + + + NCAAMB.prototype.getTournamentSchedule = function(tournamentId, callback) { + if (!tournamentId || !callback) { + throw new Error('tournamentId and callback are required parameters'); + } + if (!tournamentId.tournamentId) { + tournamentId = { + tournamentId: tournamentId + }; + } + return this.getResource('/tournaments/%(tournamentId)s/schedule.xml', tournamentId, callback); + }; + + return NCAAMB; + + })(SportApi); + + module.exports = NCAAMB; + +}).call(this); diff --git a/out/lib/v3/ncaawb.js b/out/lib/v3/ncaawb.js new file mode 100644 index 0000000..399d09e --- /dev/null +++ b/out/lib/v3/ncaawb.js @@ -0,0 +1,24 @@ +(function() { + var NCAAMB, NCAAWB, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + NCAAMB = require('./ncaamb'); + + NCAAWB = (function(_super) { + __extends(NCAAWB, _super); + + function NCAAWB() { + _ref = NCAAWB.__super__.constructor.apply(this, arguments); + return _ref; + } + + NCAAWB.prototype.league = 'ncaawb'; + + return NCAAWB; + + })(NCAAMB); + + module.exports = NCAAWB; + +}).call(this); diff --git a/out/lib/v7/ncaafb.js b/out/lib/v7/ncaafb.js new file mode 100644 index 0000000..3fdbc59 --- /dev/null +++ b/out/lib/v7/ncaafb.js @@ -0,0 +1,24 @@ +(function() { + var NCAAFBv7, V7, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + V7 = require('./v7'); + + NCAAFBv7 = (function(_super) { + __extends(NCAAFBv7, _super); + + function NCAAFBv7() { + _ref = NCAAFBv7.__super__.constructor.apply(this, arguments); + return _ref; + } + + NCAAFBv7.prototype.league = 'ncaafb'; + + return NCAAFBv7; + + })(V7); + + module.exports = NCAAFBv7; + +}).call(this); diff --git a/out/lib/v7/v7.js b/out/lib/v7/v7.js new file mode 100644 index 0000000..b1784ae --- /dev/null +++ b/out/lib/v7/v7.js @@ -0,0 +1,140 @@ +(function() { + var SportApi, V7, sprintf, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + sprintf = require('sprintf-js').sprintf; + + SportApi = require('../sport-api'); + + V7 = (function(_super) { + __extends(V7, _super); + + function V7() { + _ref = V7.__super__.constructor.apply(this, arguments); + return _ref; + } + + V7.prototype.version = 7; + + V7.prototype.getWeeklySchedule = function(params, callback) { + params = this.getYearSeasonWeekParams(params); + return this.getResource('/games/%(year)s/%(season)s/%(week)s/schedule.xml', params, callback); + }; + + V7.prototype.getExtendedBoxscore = function(params, callback) { + return this.getResource('/games/%(gameId)s/boxscore.xml', params, callback); + }; + + V7.prototype.getGameStatistics = function(params, callback) { + return this.getResource('/games/%(gameId)s/statistics.xml', params, callback); + }; + + V7.prototype.getPlayByPlay = function(params, callback) { + return this.getResource('/games/%(gameId)s/pbp.xml', params, callback); + }; + + V7.prototype.getRankings = function(params, callback) { + params = this.getYearWeekParams(params)[0]; + return this.getResource('/polls/AP25/%(year)s/%(week)s/rankings.xml', params, callback); + }; + + V7.prototype.getCfpRankings = function(params, callback) { + params = this.getYearWeekParams(params)[0]; + return this.getResource('/polls/CFP25/%(year)s/%(week)s/rankings.xml', params, callback); + }; + + V7.prototype.getYearSeasonWeekParams = function(params, callback) { + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.year) { + params.year = new Date().getFullYear(); + } + if (!params.season) { + params.season = 'REG'; + } + if (!params.week) { + params.week = 1; + } + return params; + }; + + V7.prototype.getYearWeekParams = function(params, callback) { + var seasonWeek, week; + if (typeof params === 'function') { + callback = params; + params = {}; + } + if (!params) { + params = {}; + } + if (!params.week) { + week = new Date(); + week.setHours(0, 0, 0); + week.setDate(week.getDate() + 1 - (week.getDay() || 7)); + week = Math.ceil((((week - new Date(week.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7); + if (week < 10) { + seasonWeek = (week + 52) - 34; + } else if (week < 35) { + seasonWeek = 1; + } else { + seasonWeek = week - 34; + } + params.week = seasonWeek; + } + if (!params.year) { + if (week < 10) { + params.year = new Date().getFullYear() - 1; + } + if (week >= 10) { + params.year = new Date().getFullYear(); + } + } + return [params]; + }; + + V7.prototype.getResource = function(pattern, params, callback) { + var e, options; + if (typeof params === 'function') { + callback = params; + params = {}; + } + try { + options = this.getHttpOptions(pattern, params); + } catch (_error) { + e = _error; + return callback(e); + } + return this.performHttpGet(options, callback); + }; + + V7.prototype.getHttpOptions = function(pattern, params) { + var options, path; + if (typeof params === 'undefined') { + params = {}; + } + path = "/" + this.league; + if (this.testLeague) { + path += "-test"; + } + path += "/" + this.accessLevel + "/v" + this.version + "/en"; + path += sprintf(pattern, params); + path += sprintf('?api_key=%s', this.apiKey); + return options = { + hostname: this.domain, + path: path + }; + }; + + return V7; + + })(SportApi); + + module.exports = V7; + +}).call(this); diff --git a/out/test/node-sportsdata_test.js b/out/test/node-sportsdata_test.js new file mode 100644 index 0000000..7908d65 --- /dev/null +++ b/out/test/node-sportsdata_test.js @@ -0,0 +1,206 @@ +(function() { + 'use strict'; + var node_sportsdata; + + node_sportsdata = require('../lib/node-sportsdata'); + + /* + ======== A Handy Little Mocha Reference ======== + https://github.com/visionmedia/should.js + https://github.com/visionmedia/mocha + + Mocha hooks: + before ()-> # before describe + after ()-> # after describe + beforeEach ()-> # before each it + afterEach ()-> # after each it + + Should assertions: + should.exist('hello') + should.fail('expected an error!') + true.should.be.ok + true.should.be.true + false.should.be.false + + (()-> arguments)(1,2,3).should.be.arguments + [1,2,3].should.eql([1,2,3]) + should.strictEqual(undefined, value) + user.age.should.be.within(5, 50) + username.should.match(/^\w+$/) + + user.should.be.a('object') + [].should.be.an.instanceOf(Array) + + user.should.have.property('age', 15) + + user.age.should.be.above(5) + user.age.should.be.below(100) + user.pets.should.have.length(5) + + res.should.have.status(200) #res.statusCode should be 200 + res.should.be.json + res.should.be.html + res.should.have.header('Content-Length', '123') + + [].should.be.empty + [1,2,3].should.include(3) + 'foo bar baz'.should.include('foo') + { name: 'TJ', pet: tobi }.user.should.include({ pet: tobi, name: 'TJ' }) + { foo: 'bar', baz: 'raz' }.should.have.keys('foo', 'bar') + + (()-> throw new Error('failed to baz')).should.throwError(/^fail.+/) + + user.should.have.property('pets').with.lengthOf(4) + user.should.be.a('object').and.have.property('name', 'tj') + */ + + + describe('Awesome', function() { + return describe('#of()', function() { + return it('awesome', function() { + return node_sportsdata.awesome().should.eql('awesome'); + }); + }); + }); + + describe('Node SportsData API', function() { + describe('v3', function() { + it('should be an object', function() { + return node_sportsdata.v3.should.be.a('object'); + }); + it('should have a MLB function', function() { + return node_sportsdata.v3.mlb.should.be.a('function'); + }); + it('should have a NCAAMB function', function() { + return node_sportsdata.v3.ncaamb.should.be.a('function'); + }); + describe('#mlb()', function() { + it('should return an MLB object', function() { + return node_sportsdata.v3.mlb('api-key', 't').should.be.a('object'); + }); + it('should throw an error without api key', function() { + return (function() { + return node_sportsdata.v3.mlb(); + }).should.throwError(/You must provide an API Key/); + }); + it('should throw an error without access level', function() { + return (function() { + return node_sportsdata.v3.mlb('api-key'); + }).should.throwError(/You must provide an Access Level/); + }); + it('should default to not test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v3.mlb('api-key', 't').getHttpOptions(); + return httpOptions.path.should.match(/mlb-t3/); + }); + return it('should support test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v3.mlb('api-key', 't', true).getHttpOptions(); + return httpOptions.path.should.match(/mlb-test-t3/); + }); + }); + describe('#ncaamb()', function() { + it('should return an NCAAMB object', function() { + return node_sportsdata.v3.ncaamb('api-key', 't').should.be.a('object'); + }); + it('should throw an error without api key', function() { + return (function() { + return node_sportsdata.v3.ncaamb(); + }).should.throwError(/You must provide an API Key/); + }); + it('should throw an error without access level', function() { + return (function() { + return node_sportsdata.v3.ncaamb('api-key'); + }).should.throwError(/You must provide an Access Level/); + }); + it('should default to not test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v3.ncaamb('api-key', 't').getHttpOptions(); + return httpOptions.path.should.match(/ncaamb-t3/); + }); + return it('should support test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v3.ncaamb('api-key', 't', true).getHttpOptions(); + return httpOptions.path.should.match(/ncaamb-test-t3/); + }); + }); + return describe('#ncaawb()', function() { + it('should return an NCAAWB object', function() { + return node_sportsdata.v3.ncaawb('api-key', 't').should.be.a('object'); + }); + return it('should have a path of /ncaawb', function() { + var httpOptions; + httpOptions = node_sportsdata.v3.ncaawb('api-key', 't').getHttpOptions(); + return httpOptions.path.should.match(/ncaawb-t3/); + }); + }); + }); + describe('v2', function() { + return it('should be an object', function() { + return node_sportsdata.v2.should.be.a('object'); + }); + }); + return describe('v1', function() { + it('should be an object', function() { + return node_sportsdata.v1.should.be.a('object'); + }); + it('should have an NCAAF function', function() { + return node_sportsdata.v1.ncaafb.should.be.a('function'); + }); + describe('#ncaafb()', function() { + it('should return an NCAAFB object', function() { + return node_sportsdata.v1.ncaafb('api-key', 't').should.be.a('object'); + }); + it('should throw an error without api key', function() { + return (function() { + return node_sportsdata.v1.ncaafb(); + }).should.throwError(/You must provide an API Key/); + }); + it('should throw an error without access level', function() { + return (function() { + return node_sportsdata.v1.ncaafb('api-key'); + }).should.throwError(/You must provide an Access Level/); + }); + it('should default to not test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v1.ncaafb('api-key', 't').getHttpOptions(); + return httpOptions.path.should.match(/ncaafb-t1/); + }); + return it('should support test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v1.ncaafb('api-key', 't', true).getHttpOptions(); + return httpOptions.path.should.match(/ncaafb-test-t1/); + }); + }); + it('should have an NFL function', function() { + return node_sportsdata.v1.nfl.should.be.a('function'); + }); + return describe('#nfl', function() { + it('should return an NFL object', function() { + return node_sportsdata.v1.nfl('api-key', 't').should.be.a('object'); + }); + it('should return an error without api key', function() { + return (function() { + return node_sportsdata.v1.nfl(); + }).should.throwError(/You must provide an API Key/); + }); + it('should throw an error without access level', function() { + return (function() { + return node_sportsdata.v1.nfl('api-key'); + }).should.throwError(/You must provide an Access Level/); + }); + it('should default to not test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v1.nfl('api-key', 't').getHttpOptions(); + return httpOptions.path.should.match(/nfl-t1/); + }); + return it('should support test league mode', function() { + var httpOptions; + httpOptions = node_sportsdata.v1.nfl('api-key', 't', true).getHttpOptions(); + return httpOptions.path.should.match(/nfl-test-t1/); + }); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/ncaafb-extended-boxscore_test.js b/out/test/v1/ncaafb-extended-boxscore_test.js new file mode 100644 index 0000000..c55ec5b --- /dev/null +++ b/out/test/v1/ncaafb-extended-boxscore_test.js @@ -0,0 +1,97 @@ +(function() { + 'use strict'; + var NCAAFB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAFB = require('../../lib/v1/ncaafb.js'); + + describe('V1 NCAAFB', function() { + var badNcaafb, ncaafb; + ncaafb = new NCAAFB('api-key', 't'); + badNcaafb = new NCAAFB('bad-key', 't'); + return describe('#getExtendedBoxscore()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaafb-t1/2013/REG/1/MICH/MSU/extended-boxscore.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/ncaafb-t1/" + (new Date().getFullYear()) + "/REG/1/MICH/MSU/extended-boxscore.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-extended-boxscore-200.txt').get("/ncaafb-t1/2013/REG/1/MICH/MSU/extended-boxscore.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-extended-boxscore-200.txt').get("/ncaafb-t1/2013/REG/1/MICH/OSU/extended-boxscore.xml?api_key=api-key").reply(404); + }); + it('should be a function', function() { + return ncaafb.getExtendedBoxscore.should.be.a('function'); + }); + it('should pass error and no result with missing away param', function(done) { + return ncaafb.getExtendedBoxscore(function(err, result) { + err.should.match(/property "away" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with missing home param', function(done) { + return ncaafb.getExtendedBoxscore({ + away: 'MICH' + }, function(err, result) { + err.should.match(/property "home" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaafb.getExtendedBoxscore({ + year: 2013, + away: 'MICH', + home: 'MSU' + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return ncaafb.getExtendedBoxscore({ + away: 'MICH', + home: 'MSU' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaafb.getExtendedBoxscore({ + year: 2013, + away: 'MICH', + home: 'MSU' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.home.should.match(/MSU/); + result.game.away.should.match(/MICH/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team.should.have.length(2); + result.game.possession.should.be.a('object'); + result.game.last_event.should.be.a('object'); + result.game.scoring_drives.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad param', function(done) { + return ncaafb.getExtendedBoxscore({ + year: 2013, + away: 'MICH', + home: 'OSU' + }, function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/ncaafb-play-by-play_test.js b/out/test/v1/ncaafb-play-by-play_test.js new file mode 100644 index 0000000..c2ab174 --- /dev/null +++ b/out/test/v1/ncaafb-play-by-play_test.js @@ -0,0 +1,95 @@ +(function() { + 'use strict'; + var NCAAFB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAFB = require('../../lib/v1/ncaafb.js'); + + describe('V1 NCAAFB', function() { + var badNcaafb, ncaafb; + ncaafb = new NCAAFB('api-key', 't'); + badNcaafb = new NCAAFB('bad-key', 't'); + return describe('#getPlayByPlay()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaafb-t1/2013/REG/1/MICH/MSU/pbp.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/ncaafb-t1/" + (new Date().getFullYear()) + "/REG/1/MICH/MSU/pbp.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-pbp-200.txt').get("/ncaafb-t1/2013/REG/1/MICH/MSU/pbp.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-pbp-200.txt').get("/ncaafb-t1/2013/REG/1/MICH/OSU/pbp.xml?api_key=api-key").reply(404); + }); + it('should be a function', function() { + return ncaafb.getPlayByPlay.should.be.a('function'); + }); + it('should pass error and no result with missing away param', function(done) { + return ncaafb.getPlayByPlay(function(err, result) { + err.should.match(/property "away" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with missing home param', function(done) { + return ncaafb.getPlayByPlay({ + away: 'MICH' + }, function(err, result) { + err.should.match(/property "home" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaafb.getPlayByPlay({ + year: 2013, + away: 'MICH', + home: 'MSU' + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return ncaafb.getPlayByPlay({ + away: 'MICH', + home: 'MSU' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaafb.getPlayByPlay({ + year: 2013, + away: 'MICH', + home: 'MSU' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.home.should.match(/MSU/); + result.game.away.should.match(/MICH/); + result.game.quarter.should.be.an.instanceOf(Array); + result.game.quarter.should.have.length(4); + result.game.summary.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad param', function(done) { + return ncaafb.getPlayByPlay({ + year: 2013, + away: 'MICH', + home: 'OSU' + }, function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/ncaafb-standings_test.js b/out/test/v1/ncaafb-standings_test.js new file mode 100644 index 0000000..b356b5a --- /dev/null +++ b/out/test/v1/ncaafb-standings_test.js @@ -0,0 +1,80 @@ +(function() { + 'use strict'; + var NCAAFB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + NCAAFB = require('../../lib/v1/ncaafb.js'); + + describe('V1 NCAAFB', function() { + var badNcaafb, ncaafb; + ncaafb = new NCAAFB('api-key', 't'); + badNcaafb = new NCAAFB('bad-key', 't'); + return describe('#getStandings()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/ncaafb-t1/teams/FBS/" + (now.format('YYYY')) + "/REG/standings.xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaafb-t1/teams/FBS/2013/REG/standings.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get(nowUrl).replyWithFile(200, __dirname + '/replies/ncaafb-standings-200.txt').get('/ncaafb-t1/teams/FBS/2013/REG/standings.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaafb-standings-200.txt').get('/ncaafb-t1/teams/FBS/2011/REG/standings.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaafb-standings-200-empty.txt'); + }); + it('should be a function', function() { + return ncaafb.getStandings.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaafb.getStandings({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year and REG', function(done) { + return ncaafb.getStandings(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and standings as result on 200', function(done) { + return ncaafb.getStandings({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.standings.should.be.a('object'); + result.standings.season.should.match(/2013/); + result.standings.type.should.match(/REG/); + result.standings.division.id.should.match(/FBS/); + result.standings.division.conference.should.be.an.instanceOf(Array); + result.standings.division.conference[9].id.should.match(/PAC-12/); + result.standings.division.conference[9].team.should.be.an.instanceOf(Array); + result.standings.division.conference[9].team.should.have.length(12); + return done(); + }); + }); + it('should pass no error and empty standings as result on 200 and no standings', function(done) { + return ncaafb.getStandings({ + year: 2011 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.standings.should.be.a('object'); + result.standings.season.should.match(/2011/); + result.standings.type.should.match(/REG/); + should.not.exist(result.standings.division.conference[9].team); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/ncaafb-teams-hierarchy_test.js b/out/test/v1/ncaafb-teams-hierarchy_test.js new file mode 100644 index 0000000..c5542ce --- /dev/null +++ b/out/test/v1/ncaafb-teams-hierarchy_test.js @@ -0,0 +1,64 @@ +(function() { + 'use strict'; + var NCAAFB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAFB = require('../../lib/v1/ncaafb.js'); + + describe('V1 NCAAFB', function() { + var badNcaafb, ncaafb; + ncaafb = new NCAAFB('api-key', 't'); + badNcaafb = new NCAAFB('bad-key', 't'); + return describe('#getTeamsHierarchy()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/ncaafb-t1/teams/FBS/hierarchy.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/teams-ncaafb-200.txt').get('/ncaafb-t1/teams/FBS/hierarchy.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/ncaafb-t1/teams/FBS/hierarchy.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-ncaafb-200.txt').get('/ncaafb-t1/teams/FCS/hierarchy.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-ncaafb-200-empty.txt'); + }); + it('should be a function', function() { + return ncaafb.getTeamsHierarchy.should.be.a('function'); + }); + it('should default to FBS division', function(done) { + return ncaafb.getTeamsHierarchy(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaafb.getTeamsHierarchy(function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return ncaafb.getTeamsHierarchy(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.division.should.be.a('object'); + result.division.conference.should.be.an.instanceOf(Array); + result.division.conference[8].id.should.match(/PAC-12/); + result.division.conference[8].subdivision.should.be.an.instanceOf(Array); + return done(); + }); + }); + it('should pass no error and empty teams as result on 200 and no teams', function(done) { + return ncaafb.getTeamsHierarchy('FCS', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.division.should.be.a('object'); + should.not.exist(result.division.conference); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/ncaafb-weekly-schedule_test.js b/out/test/v1/ncaafb-weekly-schedule_test.js new file mode 100644 index 0000000..61e992c --- /dev/null +++ b/out/test/v1/ncaafb-weekly-schedule_test.js @@ -0,0 +1,69 @@ +(function() { + 'use strict'; + var NCAAFB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAFB = require('../../lib/v1/ncaafb.js'); + + describe('V1 NCAAFB', function() { + var badNcaafb, ncaafb; + ncaafb = new NCAAFB('api-key', 't'); + badNcaafb = new NCAAFB('bad-key', 't'); + return describe('#getWeeklySchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaafb-t1/2013/REG/1/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/ncaafb-t1/" + (new Date().getFullYear()) + "/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-weekly-schedule-200.txt').get("/ncaafb-t1/2013/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-weekly-schedule-200.txt').get("/ncaafb-t1/2005/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaafb-weekly-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return ncaafb.getWeeklySchedule.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaafb.getWeeklySchedule({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return ncaafb.getWeeklySchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaafb.getWeeklySchedule({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.games.should.be.a('object'); + result.games.game.should.be.an.instanceOf(Array); + result.games.game.should.have.length(74); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return ncaafb.getWeeklySchedule({ + year: 2005 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.games.should.be.a('object'); + should.not.exist(result.games.game); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/nfl-extended-boxscore_test.js b/out/test/v1/nfl-extended-boxscore_test.js new file mode 100644 index 0000000..531c143 --- /dev/null +++ b/out/test/v1/nfl-extended-boxscore_test.js @@ -0,0 +1,97 @@ +(function() { + 'use strict'; + var NFL, nock, should; + + should = require('should'); + + nock = require('nock'); + + NFL = require('../../lib/v1/nfl.js'); + + describe('V1 NFL', function() { + var badNfl, nfl; + nfl = new NFL('api-key', 't'); + badNfl = new NFL('bad-key', 't'); + return describe('#getExtendedBoxscore()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/nfl-t1/2013/REG/1/CLE/PIT/extended-boxscore.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/nfl-t1/" + (new Date().getFullYear()) + "/REG/1/CLE/PIT/extended-boxscore.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-extended-boxscore-200.txt').get("/nfl-t1/2013/REG/1/DAL/NYG/extended-boxscore.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-extended-boxscore-200.txt').get("/nfl-t1/2013/REG/1/DAL/BAL/extended-boxscore.xml?api_key=api-key").reply(404); + }); + it('should be a function', function() { + return nfl.getExtendedBoxscore.should.be.a('function'); + }); + it('should pass error and no result with missing away param', function(done) { + return nfl.getExtendedBoxscore(function(err, result) { + err.should.match(/property "away" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with missing home param', function(done) { + return nfl.getExtendedBoxscore({ + away: 'CLE' + }, function(err, result) { + err.should.match(/property "home" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNfl.getExtendedBoxscore({ + year: 2013, + away: 'CLE', + home: 'PIT' + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return nfl.getExtendedBoxscore({ + away: 'CLE', + home: 'PIT' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return nfl.getExtendedBoxscore({ + year: 2013, + away: 'DAL', + home: 'NYG' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.home.should.match(/NYG/); + result.game.away.should.match(/DAL/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team.should.have.length(2); + result.game.possession.should.be.a('object'); + result.game.last_event.should.be.a('object'); + result.game.scoring_drives.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad param', function(done) { + return nfl.getExtendedBoxscore({ + year: 2013, + away: 'DAL', + home: 'BAL' + }, function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/nfl-play-by-play_test.js b/out/test/v1/nfl-play-by-play_test.js new file mode 100644 index 0000000..a5ca877 --- /dev/null +++ b/out/test/v1/nfl-play-by-play_test.js @@ -0,0 +1,95 @@ +(function() { + 'use strict'; + var NFL, nock, should; + + should = require('should'); + + nock = require('nock'); + + NFL = require('../../lib/v1/nfl.js'); + + describe('V1 NFL', function() { + var badNfl, nfl; + nfl = new NFL('api-key', 't'); + badNfl = new NFL('bad-key', 't'); + return describe('#getPlayByPlay()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/nfl-t1/2013/REG/1/CLE/PIT/pbp.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/nfl-t1/" + (new Date().getFullYear()) + "/REG/1/CLE/PIT/pbp.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-pbp-200.txt').get("/nfl-t1/2013/REG/1/DAL/NYG/pbp.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-pbp-200.txt').get("/nfl-t1/2013/REG/1/DAL/BAL/pbp.xml?api_key=api-key").reply(404); + }); + it('should be a function', function() { + return nfl.getPlayByPlay.should.be.a('function'); + }); + it('should pass error and no result with missing away param', function(done) { + return nfl.getPlayByPlay(function(err, result) { + err.should.match(/property "away" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with missing home param', function(done) { + return nfl.getPlayByPlay({ + away: 'CLE' + }, function(err, result) { + err.should.match(/property "home" does not exist/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNfl.getPlayByPlay({ + year: 2013, + away: 'CLE', + home: 'PIT' + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return nfl.getPlayByPlay({ + away: 'CLE', + home: 'PIT' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return nfl.getPlayByPlay({ + year: 2013, + away: 'DAL', + home: 'NYG' + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.home.should.match(/NYG/); + result.game.away.should.match(/DAL/); + result.game.quarter.should.be.an.instanceOf(Array); + result.game.quarter.should.have.length(4); + result.game.summary.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad param', function(done) { + return nfl.getPlayByPlay({ + year: 2013, + away: 'DAL', + home: 'BAL' + }, function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/nfl-teams-hierarchy_test.js b/out/test/v1/nfl-teams-hierarchy_test.js new file mode 100644 index 0000000..68981fb --- /dev/null +++ b/out/test/v1/nfl-teams-hierarchy_test.js @@ -0,0 +1,56 @@ +(function() { + 'use strict'; + var NFL, nock, should; + + should = require('should'); + + nock = require('nock'); + + NFL = require('../../lib/v1/nfl.js'); + + describe('V1 NFL', function() { + var badNfl, nfl; + nfl = new NFL('api-key', 't'); + badNfl = new NFL('bad-key', 't'); + return describe('#getTeamsHierarchy()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/nfl-t1/teams/hierarchy.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/nfl-t1/teams/hierarchy.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-nfl-200.txt').get('/nfl-t1/teams/hierarchy.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-nfl-200-empty.txt'); + }); + it('should be a function', function() { + return nfl.getTeamsHierarchy.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNfl.getTeamsHierarchy(function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return nfl.getTeamsHierarchy(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + result.league.conference.should.be.an.instanceOf(Array); + result.league.conference[0].division.should.be.an.instanceOf(Array); + return done(); + }); + }); + it('should pass no error and empty teams as result on 200 and no teams', function(done) { + return nfl.getTeamsHierarchy(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + should.not.exist(result.league.conference); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v1/nfl-weekly-schedule_test.js b/out/test/v1/nfl-weekly-schedule_test.js new file mode 100644 index 0000000..13d3078 --- /dev/null +++ b/out/test/v1/nfl-weekly-schedule_test.js @@ -0,0 +1,69 @@ +(function() { + 'use strict'; + var NFL, nock, should; + + should = require('should'); + + nock = require('nock'); + + NFL = require('../../lib/v1/nfl.js'); + + describe('V1 NFL', function() { + var badNfl, nfl; + nfl = new NFL('api-key', 't'); + badNfl = new NFL('bad-key', 't'); + return describe('#getWeeklySchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/nfl-t1/2013/REG/1/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/nfl-t1/" + (new Date().getFullYear()) + "/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-weekly-schedule-200.txt').get("/nfl-t1/2013/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-weekly-schedule-200.txt').get("/nfl-t1/2005/REG/1/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/nfl-weekly-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return nfl.getWeeklySchedule.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNfl.getWeeklySchedule({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year, REG, and week 1', function(done) { + return nfl.getWeeklySchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return nfl.getWeeklySchedule({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.games.should.be.a('object'); + result.games.game.should.be.an.instanceOf(Array); + result.games.game.should.have.length(16); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return nfl.getWeeklySchedule({ + year: 2005 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.games.should.be.a('object'); + should.not.exist(result.games.game); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-3day-schedule_test.js b/out/test/v3/mlb-3day-schedule_test.js new file mode 100644 index 0000000..9beb906 --- /dev/null +++ b/out/test/v3/mlb-3day-schedule_test.js @@ -0,0 +1,49 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getRollingThreeDaySchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/schedule-3day?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/schedule-3day?api_key=api-key').replyWithFile(200, __dirname + '/replies/rolling-schedule-200.txt'); + }); + it('should be a function', function() { + return mlb.getRollingThreeDaySchedule.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getRollingThreeDaySchedule(function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return mlb.getRollingThreeDaySchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.outlook.should.be.a('object'); + result.outlook.schedules.should.be.a('object'); + result.outlook.schedules.event.should.be.an.instanceOf(Array); + result.outlook.schedules.event[0].should.be.a('object'); + result.outlook.schedules.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-daily-boxscore_test.js b/out/test/v3/mlb-daily-boxscore_test.js new file mode 100644 index 0000000..e63fd49 --- /dev/null +++ b/out/test/v3/mlb-daily-boxscore_test.js @@ -0,0 +1,100 @@ +(function() { + 'use strict'; + var MLB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getDailyBoxscore()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/mlb-t3/daily/boxscore/" + (now.format('YYYY')) + "/" + (now.format('MM')) + "/" + (now.format('DD')) + ".xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get(nowUrl).replyWithFile(200, __dirname + '/replies/daily-boxscore-200.txt').get('/mlb-t3/daily/boxscore/2013/05/10.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/daily/boxscore/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-boxscore-200.txt').get('/mlb-t3/daily/boxscore/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-boxscore-200.txt').get('/mlb-t3/daily/boxscore/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-boxscore-200.txt').get('/mlb-t3/daily/boxscore/2013/07/15.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-boxscore-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getDailyBoxscore.should.be.a('function'); + }); + it('should default to current date', function(done) { + return mlb.getDailyBoxscore(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getDailyBoxscore(new Date('2013-05-10 00:00:00'), function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and boxscores as result on 200', function(done) { + return mlb.getDailyBoxscore(new Date('2013-05-10 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscores.should.be.a('object'); + result.boxscores.boxscore.should.be.an.instanceOf(Array); + result.boxscores.boxscore[0].should.be.a('object'); + result.boxscores.boxscore[0].season_type.should.match(/REG/); + result.boxscores.boxscore[0].visitor.should.be.a('object'); + result.boxscores.boxscore[0].home.should.be.a('object'); + return done(); + }); + }); + it('should support date object literal param', function(done) { + var params; + params = { + date: new Date('2013-05-10 00:00:00') + }; + return mlb.getDailyBoxscore(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscores.should.be.a('object'); + result.boxscores.boxscore.should.be.an.instanceOf(Array); + result.boxscores.boxscore[0].should.be.a('object'); + result.boxscores.boxscore[0].season_type.should.match(/REG/); + result.boxscores.boxscore[0].visitor.should.be.a('object'); + result.boxscores.boxscore[0].home.should.be.a('object'); + return done(); + }); + }); + it('should support string param', function(done) { + return mlb.getDailyBoxscore('2013-05-10 00:00:00', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscores.should.be.a('object'); + result.boxscores.boxscore.should.be.an.instanceOf(Array); + result.boxscores.boxscore[0].should.be.a('object'); + result.boxscores.boxscore[0].season_type.should.match(/REG/); + result.boxscores.boxscore[0].visitor.should.be.a('object'); + result.boxscores.boxscore[0].home.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and empty boxscores as result on 200 and no boxscores', function(done) { + return mlb.getDailyBoxscore(new Date('2013-07-15 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscores.should.be.a('object'); + should.not.exist(result.boxscores.boxscore); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-daily-events_test.js b/out/test/v3/mlb-daily-events_test.js new file mode 100644 index 0000000..3eb4b0d --- /dev/null +++ b/out/test/v3/mlb-daily-events_test.js @@ -0,0 +1,103 @@ +(function() { + 'use strict'; + var MLB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getDailyEvents()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/mlb-t3/daily/event/" + (now.format('YYYY')) + "/" + (now.format('MM')) + "/" + (now.format('DD')) + ".xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get(nowUrl).replyWithFile(200, __dirname + '/replies/daily-events-200.txt').get('/mlb-t3/daily/event/2013/05/10.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/daily/event/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-events-200.txt').get('/mlb-t3/daily/event/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-events-200.txt').get('/mlb-t3/daily/event/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-events-200.txt').get('/mlb-t3/daily/event/2013/07/15.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-events-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getDailyEvents.should.be.a('function'); + }); + it('should default to current date', function(done) { + return mlb.getDailyEvents(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getDailyEvents(new Date('2013-05-10 00:00:00'), function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and events as result on 200', function(done) { + return mlb.getDailyEvents(new Date('2013-05-10 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.events.should.be.a('object'); + result.events.event.should.be.an.instanceOf(Array); + result.events.event[0].should.be.a('object'); + result.events.event[0].season_type.should.match(/REG/); + result.events.event[0].game.should.be.a('object'); + result.events.event[0].game.visitor.should.be.a('object'); + result.events.event[0].game.home.should.be.a('object'); + return done(); + }); + }); + it('should support date object literal param', function(done) { + var params; + params = { + date: new Date('2013-05-10 00:00:00') + }; + return mlb.getDailyEvents(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.events.should.be.a('object'); + result.events.event.should.be.an.instanceOf(Array); + result.events.event[0].should.be.a('object'); + result.events.event[0].season_type.should.match(/REG/); + result.events.event[0].game.should.be.a('object'); + result.events.event[0].game.visitor.should.be.a('object'); + result.events.event[0].game.home.should.be.a('object'); + return done(); + }); + }); + it('should support string param', function(done) { + return mlb.getDailyEvents('2013-05-10 00:00:00', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.events.should.be.a('object'); + result.events.event.should.be.an.instanceOf(Array); + result.events.event[0].should.be.a('object'); + result.events.event[0].season_type.should.match(/REG/); + result.events.event[0].game.should.be.a('object'); + result.events.event[0].game.visitor.should.be.a('object'); + result.events.event[0].game.home.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and empty events as result on 200 and no events', function(done) { + return mlb.getDailyEvents(new Date('2013-07-15 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.events.should.be.a('object'); + should.not.exist(result.events.event); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-daily-schedule_test.js b/out/test/v3/mlb-daily-schedule_test.js new file mode 100644 index 0000000..b777d35 --- /dev/null +++ b/out/test/v3/mlb-daily-schedule_test.js @@ -0,0 +1,94 @@ +(function() { + 'use strict'; + var MLB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getDailySchedule()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/mlb-t3/daily/schedule/" + (now.format('YYYY')) + "/" + (now.format('MM')) + "/" + (now.format('DD')) + ".xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get(nowUrl).replyWithFile(200, __dirname + '/replies/daily-schedule-200.txt').get('/mlb-t3/daily/schedule/2013/05/10.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/daily/schedule/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-schedule-200.txt').get('/mlb-t3/daily/schedule/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-schedule-200.txt').get('/mlb-t3/daily/schedule/2013/05/10.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-schedule-200.txt').get('/mlb-t3/daily/schedule/2013/07/15.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/daily-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getDailySchedule.should.be.a('function'); + }); + it('should default to current date', function(done) { + return mlb.getDailySchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getDailySchedule(new Date('2013-05-10 00:00:00'), function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return mlb.getDailySchedule(new Date('2013-05-10 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + result.calendars.event.should.be.an.instanceOf(Array); + result.calendars.event[0].should.be.a('object'); + result.calendars.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + it('should support date object literal param', function(done) { + var params; + params = { + date: new Date('2013-05-10 00:00:00') + }; + return mlb.getDailySchedule(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + result.calendars.event.should.be.an.instanceOf(Array); + result.calendars.event[0].should.be.a('object'); + result.calendars.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + it('should support string param', function(done) { + return mlb.getDailySchedule('2013-05-10 00:00:00', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + result.calendars.event.should.be.an.instanceOf(Array); + result.calendars.event[0].should.be.a('object'); + result.calendars.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return mlb.getDailySchedule(new Date('2013-07-15 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + should.not.exist(result.calendars.event); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-event-boxscore_test.js b/out/test/v3/mlb-event-boxscore_test.js new file mode 100644 index 0000000..8b14617 --- /dev/null +++ b/out/test/v3/mlb-event-boxscore_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getEventBoxscore()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/boxscore/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/boxscore/bad-event-id.xml?api_key=api-key').replyWithFile(412, __dirname + '/replies/event-id-error.txt').get('/mlb-t3/boxscore/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-boxscore-200.txt').get('/mlb-t3/boxscore/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-boxscore-200.txt'); + }); + it('should be a function', function() { + return mlb.getEventBoxscore.should.be.a('function'); + }); + it('should should throw error without eventId', function() { + return (function() { + return mlb.getEventBoxscore(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getEventBoxscore('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad eventId', function(done) { + return mlb.getEventBoxscore('bad-event-id', function(err, result) { + err.should.match(/HTTP 412/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getEventBoxscore('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscore.should.be.a('object'); + result.boxscore.final.should.be.a('object'); + result.boxscore.visitor.should.be.a('object'); + result.boxscore.home.should.be.a('object'); + result.boxscore.pitching.should.be.a('object'); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + eventId: 'c8457f5d-d8ed-4949-8c92-b341e5b37fa4' + }; + return mlb.getEventBoxscore(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.boxscore.should.be.a('object'); + result.boxscore.final.should.be.a('object'); + result.boxscore.visitor.should.be.a('object'); + result.boxscore.home.should.be.a('object'); + result.boxscore.pitching.should.be.a('object'); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-event-pbp_test.js b/out/test/v3/mlb-event-pbp_test.js new file mode 100644 index 0000000..6b7fbe3 --- /dev/null +++ b/out/test/v3/mlb-event-pbp_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getEventPlayByPlay()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/pbp/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/pbp/bad-event-id.xml?api_key=api-key').replyWithFile(412, __dirname + '/replies/event-id-error.txt').get('/mlb-t3/pbp/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-pbp-200.txt').get('/mlb-t3/pbp/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-pbp-200.txt'); + }); + it('should be a function', function() { + return mlb.getEventPlayByPlay.should.be.a('function'); + }); + it('should should throw error without eventId', function() { + return (function() { + return mlb.getEventPlayByPlay(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getEventPlayByPlay('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad eventId', function(done) { + return mlb.getEventPlayByPlay('bad-event-id', function(err, result) { + err.should.match(/HTTP 412/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getEventPlayByPlay('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.play_by_play.should.be.a('object'); + result.play_by_play.inning.should.be.an.instanceOf(Array); + result.play_by_play.inning[0].should.be.a('object'); + result.play_by_play.inning[0].inning_half.should.be.an.instanceOf(Array); + result.play_by_play.inning[0].inning_half[0].id.should.match(/top/); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + eventId: 'c8457f5d-d8ed-4949-8c92-b341e5b37fa4' + }; + return mlb.getEventPlayByPlay(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.play_by_play.should.be.a('object'); + result.play_by_play.inning.should.be.an.instanceOf(Array); + result.play_by_play.inning[0].should.be.a('object'); + result.play_by_play.inning[0].inning_half.should.be.an.instanceOf(Array); + result.play_by_play.inning[0].inning_half[0].id.should.match(/top/); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-event-statistics_test.js b/out/test/v3/mlb-event-statistics_test.js new file mode 100644 index 0000000..c8a784a --- /dev/null +++ b/out/test/v3/mlb-event-statistics_test.js @@ -0,0 +1,81 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getEventStatistics()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/statistics/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/statistics/bad-event-id.xml?api_key=api-key').replyWithFile(412, __dirname + '/replies/event-id-error.txt').get('/mlb-t3/statistics/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-statistics-200.txt').get('/mlb-t3/statistics/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-statistics-200.txt'); + }); + it('should be a function', function() { + return mlb.getEventStatistics.should.be.a('function'); + }); + it('should should throw error without eventId', function() { + return (function() { + return mlb.getEventStatistics(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getEventStatistics('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and not result with bad eventId', function(done) { + return mlb.getEventStatistics('bad-event-id', function(err, result) { + err.should.match(/HTTP 412/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getEventStatistics('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.visitor.should.be.a('object'); + result.statistics.home.should.be.a('object'); + result.statistics.visitor.hitting.should.be.a('object'); + result.statistics.home.hitting.should.be.a('object'); + result.statistics.visitor.pitching.should.be.a('object'); + result.statistics.home.pitching.should.be.a('object'); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + eventId: 'c8457f5d-d8ed-4949-8c92-b341e5b37fa4' + }; + return mlb.getEventStatistics(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.visitor.should.be.a('object'); + result.statistics.home.should.be.a('object'); + result.statistics.visitor.hitting.should.be.a('object'); + result.statistics.home.hitting.should.be.a('object'); + result.statistics.visitor.pitching.should.be.a('object'); + result.statistics.home.pitching.should.be.a('object'); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-event_test.js b/out/test/v3/mlb-event_test.js new file mode 100644 index 0000000..145626b --- /dev/null +++ b/out/test/v3/mlb-event_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getEvent()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/event/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/event/bad-event-id.xml?api_key=api-key').replyWithFile(412, __dirname + '/replies/event-id-error.txt').get('/mlb-t3/event/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-200.txt').get('/mlb-t3/event/c8457f5d-d8ed-4949-8c92-b341e5b37fa4.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/event-200.txt'); + }); + it('should be a function', function() { + return mlb.getEvent.should.be.a('function'); + }); + it('should should throw error without eventId', function() { + return (function() { + return mlb.getEvent(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getEvent('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and not result with bad eventId', function(done) { + return mlb.getEvent('bad-event-id', function(err, result) { + err.should.match(/HTTP 412/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getEvent('c8457f5d-d8ed-4949-8c92-b341e5b37fa4', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.event.should.be.a('object'); + result.event.season_type.should.match(/REG/); + result.event.game.should.be.a('object'); + result.event.game.visitor.should.be.a('object'); + result.event.game.home.should.be.a('object'); + return done(); + }); + }); + it('should support eventId object literal param', function(done) { + var params; + params = { + eventId: 'c8457f5d-d8ed-4949-8c92-b341e5b37fa4' + }; + return mlb.getEvent(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.event.should.be.a('object'); + result.event.season_type.should.match(/REG/); + result.event.game.should.be.a('object'); + result.event.game.visitor.should.be.a('object'); + result.event.game.home.should.be.a('object'); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-glossary_test.js b/out/test/v3/mlb-glossary_test.js new file mode 100644 index 0000000..105d222 --- /dev/null +++ b/out/test/v3/mlb-glossary_test.js @@ -0,0 +1,51 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getGlossary()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/glossary/glossary.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/glossary/glossary.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/glossary-200.txt'); + }); + it('should be a function', function() { + return mlb.getGlossary.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getGlossary(function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and glossary as result on 200', function(done) { + return mlb.getGlossary(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.glossary.should.be.a('object'); + result.glossary.pitch_types.should.be.a('object'); + result.glossary.player_statuses.should.be.a('object'); + result.glossary.pitch_outcome.should.be.a('object'); + result.glossary.game_status.should.be.a('object'); + result.glossary.runner_outcomes.should.be.a('object'); + result.glossary.post_season.should.be.a('object'); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-league-schedule_test.js b/out/test/v3/mlb-league-schedule_test.js new file mode 100644 index 0000000..ab05726 --- /dev/null +++ b/out/test/v3/mlb-league-schedule_test.js @@ -0,0 +1,79 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getLeagueSchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/schedule/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/league-schedule-200.txt').get('/mlb-t3/schedule/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/schedule/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/league-schedule-200.txt').get('/mlb-t3/schedule/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/league-schedule-200.txt').get('/mlb-t3/schedule/2011.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/league-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getLeagueSchedule.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getLeagueSchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getLeagueSchedule(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return mlb.getLeagueSchedule(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + result.calendars.event.should.be.an.instanceOf(Array); + result.calendars.event[0].should.be.a('object'); + result.calendars.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getLeagueSchedule(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + result.calendars.event.should.be.an.instanceOf(Array); + result.calendars.event[0].should.be.a('object'); + result.calendars.event[0].season_type.should.match(/REG/); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return mlb.getLeagueSchedule(2011, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.calendars.should.be.a('object'); + should.not.exist(result.calendars.event); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-player-profile_test.js b/out/test/v3/mlb-player-profile_test.js new file mode 100644 index 0000000..9205f18 --- /dev/null +++ b/out/test/v3/mlb-player-profile_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getPlayerProfile()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/player/profile/898c62b6-95bf-4973-a435-c6cb42a52158.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/player/profile/bad-player-profile-id.xml?api_key=api-key').replyWithFile(412, __dirname + '/replies/player-profile-id-error.txt').get('/mlb-t3/player/profile/898c62b6-95bf-4973-a435-c6cb42a52158.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/player-profile-200.txt').get('/mlb-t3/player/profile/898c62b6-95bf-4973-a435-c6cb42a52158.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/player-profile-200.txt'); + }); + it('should be a function', function() { + return mlb.getPlayerProfile.should.be.a('function'); + }); + it('should should throw error without playerId', function() { + return (function() { + return mlb.getPlayerProfile(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getPlayerProfile('898c62b6-95bf-4973-a435-c6cb42a52158', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and not result with bad playerId', function(done) { + return mlb.getPlayerProfile('bad-player-profile-id', function(err, result) { + err.should.match(/HTTP 412/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getPlayerProfile('898c62b6-95bf-4973-a435-c6cb42a52158', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.participant.should.be.a('object'); + result.participant.profile.should.be.a('object'); + result.participant.profile.first.should.match(/Gerald/); + result.participant.profile.preferred_first.should.match(/Buster/); + result.participant.profile.last.should.match(/Posey/); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + playerId: '898c62b6-95bf-4973-a435-c6cb42a52158' + }; + return mlb.getPlayerProfile(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.participant.should.be.a('object'); + result.participant.profile.should.be.a('object'); + result.participant.profile.first.should.match(/Gerald/); + result.participant.profile.preferred_first.should.match(/Buster/); + result.participant.profile.last.should.match(/Posey/); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-player-stats_test.js b/out/test/v3/mlb-player-stats_test.js new file mode 100644 index 0000000..cde00e6 --- /dev/null +++ b/out/test/v3/mlb-player-stats_test.js @@ -0,0 +1,79 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getPlayersSeasonalStatistics()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/seasontd/players/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/players-stats-200.txt').get('/mlb-t3/seasontd/players/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/seasontd/players/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/players-stats-200.txt').get('/mlb-t3/seasontd/players/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/players-stats-200.txt').get('/mlb-t3/seasontd/players/2010.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/players-stats-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getPlayersSeasonalStatistics.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getPlayersSeasonalStatistics(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getPlayersSeasonalStatistics(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and rosters as result on 200', function(done) { + return mlb.getPlayersSeasonalStatistics(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.player.should.be.an.instanceOf(Array); + result.statistics.player[0].team.should.be.a('object'); + result.statistics.player[0].team.pitching.should.be.a('object'); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getPlayersSeasonalStatistics(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.player.should.be.an.instanceOf(Array); + result.statistics.player[0].team.should.be.a('object'); + result.statistics.player[0].team.pitching.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and empty rosters as result on 200 and no rosters', function(done) { + return mlb.getPlayersSeasonalStatistics(2010, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + should.not.exist(result.statistics.player); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-standings_test.js b/out/test/v3/mlb-standings_test.js new file mode 100644 index 0000000..0057ebd --- /dev/null +++ b/out/test/v3/mlb-standings_test.js @@ -0,0 +1,79 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getStandings()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/standings/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/standings-200.txt').get('/mlb-t3/standings/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/standings/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/standings-200.txt').get('/mlb-t3/standings/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/standings-200.txt').get('/mlb-t3/standings/2011.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/standings-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getStandings.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getStandings(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getStandings(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and standings as result on 200', function(done) { + return mlb.getStandings(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.standings.should.be.a('object'); + result.standings.league.should.be.an.instanceOf(Array); + result.standings.league[0].should.be.a('object'); + result.standings.league[0].id.should.match(/AL/); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getStandings(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.standings.should.be.a('object'); + result.standings.league.should.be.an.instanceOf(Array); + result.standings.league[0].should.be.a('object'); + result.standings.league[0].id.should.match(/AL/); + return done(); + }); + }); + it('should pass no error and empty standings as result on 200 and no standings', function(done) { + return mlb.getStandings(2011, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.standings.should.be.a('object'); + should.not.exist(result.standings.league); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-team-rosters-active_test.js b/out/test/v3/mlb-team-rosters-active_test.js new file mode 100644 index 0000000..3cd2c72 --- /dev/null +++ b/out/test/v3/mlb-team-rosters-active_test.js @@ -0,0 +1,81 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getTeamRostersActive()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/rosters/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/team-rosters-200.txt').get('/mlb-t3/rosters/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/rosters/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-200.txt').get('/mlb-t3/rosters/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-200.txt').get('/mlb-t3/rosters/2010.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getTeamRostersActive.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getTeamRostersActive(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getTeamRostersActive(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and rosters as result on 200', function(done) { + return mlb.getTeamRostersActive(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + result.rosters.team.should.be.an.instanceOf(Array); + result.rosters.team[0].should.be.a('object'); + result.rosters.team[0].players.should.be.a('object'); + result.rosters.team[0].players.profile.should.be.an.instanceOf(Array)["with"].lengthOf(25); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getTeamRostersActive(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + result.rosters.team.should.be.an.instanceOf(Array); + result.rosters.team[0].should.be.a('object'); + result.rosters.team[0].players.should.be.a('object'); + result.rosters.team[0].players.profile.should.be.an.instanceOf(Array)["with"].lengthOf(25); + return done(); + }); + }); + it('should pass no error and empty rosters as result on 200 and no rosters', function(done) { + return mlb.getTeamRostersActive(2010, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + should.not.exist(result.rosters.team); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-team-rosters-full_test.js b/out/test/v3/mlb-team-rosters-full_test.js new file mode 100644 index 0000000..11706fe --- /dev/null +++ b/out/test/v3/mlb-team-rosters-full_test.js @@ -0,0 +1,81 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getTeamRostersFull()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/rosters-full/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/team-rosters-full-200.txt').get('/mlb-t3/rosters-full/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/rosters-full/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-full-200.txt').get('/mlb-t3/rosters-full/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-full-200.txt').get('/mlb-t3/rosters-full/2010.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-rosters-full-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getTeamRostersFull.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getTeamRostersFull(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getTeamRostersFull(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and rosters as result on 200', function(done) { + return mlb.getTeamRostersFull(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + result.rosters.team.should.be.an.instanceOf(Array); + result.rosters.team[0].should.be.a('object'); + result.rosters.team[0].players.should.be.a('object'); + result.rosters.team[0].players.profile.should.be.an.instanceOf(Array)["with"].lengthOf(34); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getTeamRostersFull(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + result.rosters.team.should.be.an.instanceOf(Array); + result.rosters.team[0].should.be.a('object'); + result.rosters.team[0].players.should.be.a('object'); + result.rosters.team[0].players.profile.should.be.an.instanceOf(Array)["with"].lengthOf(34); + return done(); + }); + }); + it('should pass no error and empty rosters as result on 200 and no rosters', function(done) { + return mlb.getTeamRostersFull(2010, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.rosters.should.be.a('object'); + should.not.exist(result.rosters.team); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-team-stats_test.js b/out/test/v3/mlb-team-stats_test.js new file mode 100644 index 0000000..b439bb7 --- /dev/null +++ b/out/test/v3/mlb-team-stats_test.js @@ -0,0 +1,81 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getTeamSeasonalStatistics()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/seasontd/teams/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/team-stats-200.txt').get('/mlb-t3/seasontd/teams/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/seasontd/teams/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-stats-200.txt').get('/mlb-t3/seasontd/teams/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-stats-200.txt').get('/mlb-t3/seasontd/teams/2010.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/team-stats-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getTeamSeasonalStatistics.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getTeamSeasonalStatistics(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getTeamSeasonalStatistics(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and rosters as result on 200', function(done) { + return mlb.getTeamSeasonalStatistics(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.team.should.be.an.instanceOf(Array)["with"].lengthOf(30); + result.statistics.team[0].should.be.a('object'); + result.statistics.team[0].hitting.should.be.a('object'); + result.statistics.team[0].pitching.should.be.a('object'); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getTeamSeasonalStatistics(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + result.statistics.team.should.be.an.instanceOf(Array)["with"].lengthOf(30); + result.statistics.team[0].should.be.a('object'); + result.statistics.team[0].hitting.should.be.a('object'); + result.statistics.team[0].pitching.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and empty rosters as result on 200 and no rosters', function(done) { + return mlb.getTeamSeasonalStatistics(2010, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.statistics.should.be.a('object'); + should.not.exist(result.statistics.team); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-teams-hierarchy_test.js b/out/test/v3/mlb-teams-hierarchy_test.js new file mode 100644 index 0000000..d32bb59 --- /dev/null +++ b/out/test/v3/mlb-teams-hierarchy_test.js @@ -0,0 +1,79 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getTeamsHierarchy()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get("/mlb-t3/teams/" + (new Date().getFullYear()) + ".xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/teams-200.txt').get('/mlb-t3/teams/2013.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/teams/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-200.txt').get('/mlb-t3/teams/2013.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-200.txt').get('/mlb-t3/teams/2010.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/teams-200-empty.txt'); + }); + it('should be a function', function() { + return mlb.getTeamsHierarchy.should.be.a('function'); + }); + it('should default to current year', function(done) { + return mlb.getTeamsHierarchy(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getTeamsHierarchy(2013, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return mlb.getTeamsHierarchy(2013, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.teams.should.be.a('object'); + result.teams.team.should.be.an.instanceOf(Array); + result.teams.team[0].should.be.a('object'); + result.teams.team[0].abbr.should.match(/LA/); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + year: 2013 + }; + return mlb.getTeamsHierarchy(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.teams.should.be.a('object'); + result.teams.team.should.be.an.instanceOf(Array); + result.teams.team[0].should.be.a('object'); + result.teams.team[0].abbr.should.match(/LA/); + return done(); + }); + }); + it('should pass no error and empty teams as result on 200 and no teams', function(done) { + return mlb.getTeamsHierarchy(2010, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.teams.should.be.a('object'); + should.not.exist(result.teams.team); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/mlb-venue-info_test.js b/out/test/v3/mlb-venue-info_test.js new file mode 100644 index 0000000..ee6e483 --- /dev/null +++ b/out/test/v3/mlb-venue-info_test.js @@ -0,0 +1,48 @@ +(function() { + 'use strict'; + var MLB, nock, should; + + should = require('should'); + + nock = require('nock'); + + MLB = require('../../lib/v3/mlb.js'); + + describe('V3 MLB', function() { + var badMlb, mlb; + mlb = new MLB('api-key', 't'); + badMlb = new MLB('bad-key', 't'); + return describe('#getVenueInfo()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/mlb-t3/venues/venues.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/mlb-t3/venues/venues.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/venue-info-200.txt'); + }); + it('should be a function', function() { + return mlb.getVenueInfo.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badMlb.getVenueInfo(function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and venues as result on 200', function(done) { + return mlb.getVenueInfo(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.venues.should.be.a('object'); + result.venues.venue.should.be.an.instanceOf(Array); + result.venues.venue[0].should.be.a('object'); + result.venues.venue[0].name.should.match(/PETCO Park/); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-daily-schedule_test.js b/out/test/v3/ncaamb-daily-schedule_test.js new file mode 100644 index 0000000..7ce36a9 --- /dev/null +++ b/out/test/v3/ncaamb-daily-schedule_test.js @@ -0,0 +1,98 @@ +(function() { + 'use strict'; + var NCAAMB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getDailySchedule()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/ncaamb-t3/games/" + (now.format('YYYY')) + "/" + (now.format('MM')) + "/" + (now.format('DD')) + "/schedule.xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get(nowUrl).replyWithFile(200, __dirname + '/replies/ncaamb-daily-schedule-200.txt').get('/ncaamb-t3/games/2013/10/14/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/ncaamb-t3/games/2013/11/08/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-daily-schedule-200.txt').get('/ncaamb-t3/games/2013/11/08/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-daily-schedule-200.txt').get('/ncaamb-t3/games/2013/11/08/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-daily-schedule-200.txt').get('/ncaamb-t3/games/2013/10/15/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-daily-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return ncaamb.getDailySchedule.should.be.a('function'); + }); + it('should default to current date', function(done) { + return ncaamb.getDailySchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getDailySchedule(new Date('2013-10-14 00:00:00'), function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaamb.getDailySchedule(new Date('2013-11-08 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + result.league['daily-schedule'].should.be.a('object'); + result.league['daily-schedule'].games.should.be.a('object'); + result.league['daily-schedule'].games.game.should.be.an.instanceOf(Array); + result.league['daily-schedule'].games.game[0].should.be.a('object'); + result.league['daily-schedule'].games.game[0].status.should.match(/scheduled/); + return done(); + }); + }); + it('should support date object literal param', function(done) { + var params; + params = { + date: new Date('2013-11-08 00:00:00') + }; + return ncaamb.getDailySchedule(params, function(err, result) { + should.not.exist(err); + result.league.should.be.a('object'); + result.league['daily-schedule'].should.be.a('object'); + result.league['daily-schedule'].games.should.be.a('object'); + result.league['daily-schedule'].games.game.should.be.an.instanceOf(Array); + result.league['daily-schedule'].games.game[0].should.be.a('object'); + result.league['daily-schedule'].games.game[0].status.should.match(/scheduled/); + return done(); + }); + }); + it('should support string param', function(done) { + return ncaamb.getDailySchedule('2013-11-08 00:00:00', function(err, result) { + should.not.exist(err); + result.league.should.be.a('object'); + result.league['daily-schedule'].should.be.a('object'); + result.league['daily-schedule'].games.should.be.a('object'); + result.league['daily-schedule'].games.game.should.be.an.instanceOf(Array); + result.league['daily-schedule'].games.game[0].should.be.a('object'); + result.league['daily-schedule'].games.game[0].status.should.match(/scheduled/); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return ncaamb.getDailySchedule(new Date('2013-10-15 00:00:00'), function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league['daily-schedule'].games.should.be.a('string'); + result.league['daily-schedule'].games.should.be.empty; + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-game-boxscore_test.js b/out/test/v3/ncaamb-game-boxscore_test.js new file mode 100644 index 0000000..76a43b2 --- /dev/null +++ b/out/test/v3/ncaamb-game-boxscore_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var NCAAMB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getGameBoxscore()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/boxscore.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/ncaamb-t3/games/bad-event-id/boxscore.xml?api_key=api-key').reply(404, '').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/boxscore.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-game-boxscore-200.txt').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/boxscore.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-game-boxscore-200.txt'); + }); + it('should be a function', function() { + return ncaamb.getGameBoxscore.should.be.a('function'); + }); + it('should should throw error without gameId', function() { + return (function() { + return ncaamb.getGameBoxscore(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getGameBoxscore('2b999b4b-c01f-4aa6-9576-f2e195c6b421', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad gameId', function(done) { + return ncaamb.getGameBoxscore('bad-event-id', function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return ncaamb.getGameBoxscore('2b999b4b-c01f-4aa6-9576-f2e195c6b421', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.title.should.match(/2013 National Championship/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team[0].scoring.should.be.a('object'); + should.not.exist(result.game.team[0].statistics); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + gameId: '2b999b4b-c01f-4aa6-9576-f2e195c6b421' + }; + return ncaamb.getGameBoxscore(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.title.should.match(/2013 National Championship/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team[0].scoring.should.be.a('object'); + should.not.exist(result.game.team[0].statistics); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-game-summary_test.js b/out/test/v3/ncaamb-game-summary_test.js new file mode 100644 index 0000000..7d560c5 --- /dev/null +++ b/out/test/v3/ncaamb-game-summary_test.js @@ -0,0 +1,77 @@ +(function() { + 'use strict'; + var NCAAMB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getGameSummary()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/summary.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/ncaamb-t3/games/bad-event-id/summary.xml?api_key=api-key').reply(404, '').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/summary.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-game-summary-200.txt').get('/ncaamb-t3/games/2b999b4b-c01f-4aa6-9576-f2e195c6b421/summary.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-game-summary-200.txt'); + }); + it('should be a function', function() { + return ncaamb.getGameSummary.should.be.a('function'); + }); + it('should should throw error without gameId', function() { + return (function() { + return ncaamb.getGameSummary(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getGameSummary('2b999b4b-c01f-4aa6-9576-f2e195c6b421', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and no result with bad gameId', function(done) { + return ncaamb.getGameSummary('bad-event-id', function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return ncaamb.getGameSummary('2b999b4b-c01f-4aa6-9576-f2e195c6b421', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.title.should.match(/2013 National Championship/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team[0].scoring.should.be.a('object'); + result.game.team[0].statistics.should.be.a('object'); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + gameId: '2b999b4b-c01f-4aa6-9576-f2e195c6b421' + }; + return ncaamb.getGameSummary(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.game.should.be.a('object'); + result.game.title.should.match(/2013 National Championship/); + result.game.team.should.be.an.instanceOf(Array); + result.game.team[0].scoring.should.be.a('object'); + result.game.team[0].statistics.should.be.a('object'); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-schedule_test.js b/out/test/v3/ncaamb-schedule_test.js new file mode 100644 index 0000000..2eb3cdd --- /dev/null +++ b/out/test/v3/ncaamb-schedule_test.js @@ -0,0 +1,71 @@ +(function() { + 'use strict'; + var NCAAMB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getSchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/games/2013/REG/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/ncaamb-t3/games/" + (new Date().getFullYear()) + "/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-schedule-200.txt').get("/ncaamb-t3/games/2013/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-schedule-200.txt').get("/ncaamb-t3/games/2012/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-schedule-200-empty.txt'); + }); + it('should be a function', function() { + return ncaamb.getSchedule.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getSchedule({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year and REG', function(done) { + return ncaamb.getSchedule(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaamb.getSchedule({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + result.league['season-schedule'].should.be.a('object'); + result.league['season-schedule'].games.should.be.a('object'); + result.league['season-schedule'].games.game.should.be.an.instanceOf(Array); + result.league['season-schedule'].games.game.should.have.length(37); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return ncaamb.getSchedule({ + year: 2012 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league['season-schedule'].games.should.be.a('string'); + result.league['season-schedule'].games.should.be.empty; + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-standings_test.js b/out/test/v3/ncaamb-standings_test.js new file mode 100644 index 0000000..683eef7 --- /dev/null +++ b/out/test/v3/ncaamb-standings_test.js @@ -0,0 +1,81 @@ +(function() { + 'use strict'; + var NCAAMB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getStandings()', function() { + var now, nowUrl, scope; + scope = void 0; + now = moment(); + nowUrl = "/ncaamb-t3/seasontd/" + (now.format('YYYY')) + "/REG/standings.xml?api_key=api-key"; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/seasontd/2013/REG/standings.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get(nowUrl).replyWithFile(200, __dirname + '/replies/ncaamb-standings-200.txt').get('/ncaamb-t3/seasontd/2013/REG/standings.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-standings-200.txt').get('/ncaamb-t3/seasontd/2012/REG/standings.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-standings-200-empty.txt'); + }); + it('should be a function', function() { + return ncaamb.getStandings.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getStandings({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year and REG', function(done) { + return ncaamb.getStandings(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and standings as result on 200', function(done) { + return ncaamb.getStandings({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + result.league.season.should.be.a('object'); + result.league.season.year.should.match(/2013/); + result.league.season.type.should.match(/REG/); + result.league.season.conference.should.be.an.instanceOf(Array); + result.league.season.conference.should.have.length(2); + result.league.season.conference[1].alias.should.match(/PAC12/); + result.league.season.conference[1].team.should.be.an.instanceOf(Array); + result.league.season.conference[1].team.should.have.length(12); + return done(); + }); + }); + it('should pass no error and empty standings as result on 200 and no standings', function(done) { + return ncaamb.getStandings({ + year: 2012 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.season.should.be.a('object'); + result.league.season.year.should.match(/2012/); + result.league.season.type.should.match(/REG/); + should.not.exist(result.league.season.conference); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-tournament-list_test.js b/out/test/v3/ncaamb-tournament-list_test.js new file mode 100644 index 0000000..5d19ef6 --- /dev/null +++ b/out/test/v3/ncaamb-tournament-list_test.js @@ -0,0 +1,72 @@ +(function() { + 'use strict'; + var NCAAMB, moment, nock, should; + + should = require('should'); + + nock = require('nock'); + + moment = require('moment'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getTournamentList()', function() { + var now, scope; + scope = void 0; + now = moment(); + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/tournaments/2013/REG/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get("/ncaamb-t3/tournaments/" + (new Date().getFullYear()) + "/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-tournament-list-200.txt').get("/ncaamb-t3/tournaments/2013/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-tournament-list-200.txt').get("/ncaamb-t3/tournaments/2012/REG/schedule.xml?api_key=api-key").replyWithFile(200, __dirname + '/replies/ncaamb-tournament-list-200-empty.txt'); + }); + it('should be a function', function() { + return ncaamb.getTournamentList.should.be.a('function'); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getTournamentList({ + year: 2013 + }, function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should default to current year and REG', function(done) { + return ncaamb.getTournamentList(function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + return done(); + }); + }); + it('should pass no error and schedule as result on 200', function(done) { + return ncaamb.getTournamentList({ + year: 2013 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league.should.be.a('object'); + result.league['season-schedule'].should.be.a('object'); + result.league['season-schedule'].tournament.should.be.an.instanceOf(Array); + result.league['season-schedule'].tournament.should.have.length(21); + return done(); + }); + }); + it('should pass no error and empty schedule as result on 200 and no schedule', function(done) { + return ncaamb.getTournamentList({ + year: 2012 + }, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + should.not.exist(result.league['season-schedule'].tournament); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this); diff --git a/out/test/v3/ncaamb-tournament-schedule_test.js b/out/test/v3/ncaamb-tournament-schedule_test.js new file mode 100644 index 0000000..43a7841 --- /dev/null +++ b/out/test/v3/ncaamb-tournament-schedule_test.js @@ -0,0 +1,73 @@ +(function() { + 'use strict'; + var NCAAMB, nock, should; + + should = require('should'); + + nock = require('nock'); + + NCAAMB = require('../../lib/v3/ncaamb.js'); + + describe('V3 NCAAMB', function() { + var badNcaamb, ncaamb; + ncaamb = new NCAAMB('api-key', 't'); + badNcaamb = new NCAAMB('bad-key', 't'); + return describe('#getTournamentSchedule()', function() { + var scope; + scope = void 0; + before(function() { + return scope = nock('http://api.sportsdatallc.org').get('/ncaamb-t3/tournaments/ab0754a7-2a19-4e22-987a-c45ce217ea60/schedule.xml?api_key=bad-key').replyWithFile(403, __dirname + '/replies/api-key-error.txt').get('/ncaamb-t3/tournaments/bad-tournament-id/schedule.xml?api_key=api-key').reply(404, '').get('/ncaamb-t3/tournaments/ab0754a7-2a19-4e22-987a-c45ce217ea60/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-tournament-schedule-200.txt').get('/ncaamb-t3/tournaments/ab0754a7-2a19-4e22-987a-c45ce217ea60/schedule.xml?api_key=api-key').replyWithFile(200, __dirname + '/replies/ncaamb-tournament-schedule-200.txt'); + }); + it('should be a function', function() { + return ncaamb.getTournamentSchedule.should.be.a('function'); + }); + it('should should throw error without tournamentId', function() { + return (function() { + return ncaamb.getTournamentSchedule(); + }).should.throwError(/required/); + }); + it('should pass error and no result with bad api key', function(done) { + return badNcaamb.getTournamentSchedule('ab0754a7-2a19-4e22-987a-c45ce217ea60', function(err, result) { + err.should.match(/HTTP 403/); + should.not.exist(result); + return done(); + }); + }); + it('should pass error and not result with bad tournament id', function(done) { + return ncaamb.getTournamentSchedule('bad-tournament-id', function(err, result) { + err.should.match(/HTTP 404/); + should.not.exist(result); + return done(); + }); + }); + it('should pass no error and teams as result on 200', function(done) { + return ncaamb.getTournamentSchedule('ab0754a7-2a19-4e22-987a-c45ce217ea60', function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league['tournament-schedule'].should.be.a('object'); + result.league['tournament-schedule'].name.should.match(/Las Vegas Invitational/); + result.league['tournament-schedule'].round.should.be.an.instanceOf(Array); + return done(); + }); + }); + it('should support object literal as param', function(done) { + var params; + params = { + tournamentId: 'ab0754a7-2a19-4e22-987a-c45ce217ea60' + }; + return ncaamb.getTournamentSchedule(params, function(err, result) { + should.not.exist(err); + result.should.be.a('object'); + result.league['tournament-schedule'].should.be.a('object'); + result.league['tournament-schedule'].name.should.match(/Las Vegas Invitational/); + result.league['tournament-schedule'].round.should.be.an.instanceOf(Array); + return done(); + }); + }); + return after(function() { + return scope.done(); + }); + }); + }); + +}).call(this);