From 67614f8d477c9471c1a9965d841ddde3ea8d5e75 Mon Sep 17 00:00:00 2001 From: Mike Kreiser Date: Sun, 22 Oct 2023 20:53:30 -0400 Subject: [PATCH 1/3] Include newer classes in index export --- src/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.js b/src/index.js index 60ee655..537bcde 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,10 @@ import Boxscore from './boxscore/boxscore'; import BoxscorePlayer from './boxscore-player/boxscore-player'; import Client from './client/client'; +import DraftPlayer from './draft-player/draft-player'; import FreeAgentPlayer from './free-agent-player/free-agent-player'; +import League from './league/league'; +import NFLGame from './nfl-game/nfl-game'; import Player from './player/player'; import PlayerStats from './player-stats/player-stats'; import Team from './team/team'; @@ -10,7 +13,10 @@ export { Boxscore, BoxscorePlayer, Client, + DraftPlayer, FreeAgentPlayer, + League, + NFLGame, Player, PlayerStats, Team From 95885d0be8f1c930af8993efca002a9bab463b53 Mon Sep 17 00:00:00 2001 From: Mike Kreiser Date: Sun, 22 Oct 2023 21:42:56 -0400 Subject: [PATCH 2/3] Throw errors when invalid season IDs are passed to Client methods --- .../__snapshots__/integration.test.js.snap | 57 + .../2016-season/integration.test.js | 84 +- src/client/client.js | 39 + src/client/client.test.js | 1104 ++++++++++------- 4 files changed, 816 insertions(+), 468 deletions(-) diff --git a/integration-tests/2016-season/__snapshots__/integration.test.js.snap b/integration-tests/2016-season/__snapshots__/integration.test.js.snap index e145451..9f12530 100644 --- a/integration-tests/2016-season/__snapshots__/integration.test.js.snap +++ b/integration-tests/2016-season/__snapshots__/integration.test.js.snap @@ -1,5 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`2016 season integration tests getBoxscoreForWeek throws an error 1`] = `[Error: Cannot call getBoxscoreForWeek with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).Call Client#getHistoricalScoreboardForWeek for historical data instead.]`; + +exports[`2016 season integration tests getDraftInfo throws an error 1`] = `[Error: Cannot call getDraftInfo with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).]`; + +exports[`2016 season integration tests getFreeAgents throws an error 1`] = `[Error: Cannot call getFreeAgents with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).]`; + exports[`2016 season integration tests getHistoricalScoreboardForWeek returns a populated array of Boxscores 1`] = ` [ Boxscore { @@ -3531,3 +3537,54 @@ exports[`2016 season integration tests getHistoricalTeamsAtWeek returns a popula }, ] `; + +exports[`2016 season integration tests getLeagueInfo throws an error 1`] = `[Error: Cannot call getLeagueInfo with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).]`; + +exports[`2016 season integration tests getNFLGamesForPeriod returns a populated array of NFLGames 1`] = ` +[ + NFLGame { + "awayTeam": { + "id": 19, + "record": "2-2", + "score": 10, + "team": "New York Giants", + "teamAbbrev": "NYG", + }, + "broadcaster": "ESPN", + "clock": "0:00", + "gameStatus": "Final", + "homeTeam": { + "id": 16, + "record": "4-0", + "score": 24, + "team": "Minnesota Vikings", + "teamAbbrev": "MIN", + }, + "quarter": 4, + "startTime": 2016-10-04T00:30:00.000Z, + }, + NFLGame { + "awayTeam": { + "id": 22, + "record": "2-3", + "score": 33, + "team": "Arizona Cardinals", + "teamAbbrev": "ARI", + }, + "broadcaster": "CBS", + "clock": "0:00", + "gameStatus": "Final", + "homeTeam": { + "id": 25, + "record": "1-4", + "score": 21, + "team": "San Francisco 49ers", + "teamAbbrev": "SF", + }, + "quarter": 4, + "startTime": 2016-10-07T00:25:00.000Z, + }, +] +`; + +exports[`2016 season integration tests getTeamsAtWeek throws an error 1`] = `[Error: Cannot call getTeamsAtWeek with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).Call Client#getHistoricalTeamsAtWeek for historical data instead.]`; diff --git a/integration-tests/2016-season/integration.test.js b/integration-tests/2016-season/integration.test.js index cb334ad..2d9b1f1 100644 --- a/integration-tests/2016-season/integration.test.js +++ b/integration-tests/2016-season/integration.test.js @@ -22,10 +22,92 @@ describe('2016 season integration tests', () => { }); }); + describe('getBoxscoreForWeek', () => { + test('throws an error', async () => { + expect.assertions(1); + + try { + await client.getBoxscoreForWeek({ + seasonId, + matchupPeriodId: scoringPeriodId, + scoringPeriodId + }); + } catch (ex) { + // eslint-disable-next-line jest/no-conditional-expect + expect(ex).toMatchSnapshot(); + } + }); + }); + + describe('getDraftInfo', () => { + test('throws an error', async () => { + expect.assertions(1); + + try { + await client.getDraftInfo({ seasonId }); + } catch (ex) { + // eslint-disable-next-line jest/no-conditional-expect + expect(ex).toMatchSnapshot(); + } + }); + }); + + describe('getFreeAgents', () => { + test('throws an error', async () => { + expect.assertions(1); + + try { + await client.getFreeAgents({ seasonId, scoringPeriodId }); + } catch (ex) { + // eslint-disable-next-line jest/no-conditional-expect + expect(ex).toMatchSnapshot(); + } + }); + }); + + describe('getTeamsAtWeek', () => { + test('throws an error', async () => { + expect.assertions(1); + + try { + await client.getTeamsAtWeek({ seasonId, scoringPeriodId }); + } catch (ex) { + // eslint-disable-next-line jest/no-conditional-expect + expect(ex).toMatchSnapshot(); + } + }); + }); + + describe('getLeagueInfo', () => { + test('throws an error', async () => { + expect.assertions(1); + + try { + await client.getLeagueInfo({ seasonId }); + } catch (ex) { + // eslint-disable-next-line jest/no-conditional-expect + expect(ex).toMatchSnapshot(); + } + }); + }); + + describe('getNFLGamesForPeriod', () => { + test('returns a populated array of NFLGames', async () => { + const nflGames = await client.getNFLGamesForPeriod({ + startDate: '20161003', + endDate: '20161008' + }); + + expect(nflGames).toMatchSnapshot(); + }); + }); + describe('getHistoricalScoreboardForWeek', () => { test('returns a populated array of Boxscores', async () => { const scoreboards = await client.getHistoricalScoreboardForWeek({ - seasonId, matchupPeriodId: scoringPeriodId, scoringPeriodId + seasonId, + matchupPeriodId: scoringPeriodId, + scoringPeriodId }); expect(scoreboards).toMatchSnapshot(); diff --git a/src/client/client.js b/src/client/client.js index 731c26a..714f0dd 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -17,6 +17,19 @@ axios.defaults.baseURL = 'https://fantasy.espn.com/apis/v3/games/ffl/seasons/'; * @class */ class Client { + static _validateV3Params(seasonId, route, alternateRoute = '') { + if (seasonId < 2018) { + throw new Error(`Cannot call ${route} with a season ID prior to 2018 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more).${alternateRoute ? `Call Client#${alternateRoute} for historical data instead.` : ''}`); + } + } + + static _validateHistoricalParams(seasonId, route, alternateRoute) { + if (seasonId >= 2018) { + // Historical routes should always have a modern endpoint, so alternateRoute is required. + throw new Error(`Cannot call ${route} with a season ID after 2017 due to ESPN limitations (see README.md#espn-databases-and-data-storage for more). Call Client#${alternateRoute} for new data instead.`); + } + } + constructor(options = {}) { this.leagueId = options.leagueId; @@ -51,6 +64,12 @@ class Client { * @returns {Boxscore[]} All boxscores for the week */ getBoxscoreForWeek({ seasonId, matchupPeriodId, scoringPeriodId }) { + this.constructor._validateV3Params( + seasonId, + 'getBoxscoreForWeek', + 'getHistoricalScoreboardForWeek' + ); + const route = this.constructor._buildRoute({ base: `${seasonId}/segments/0/leagues/${this.leagueId}`, params: `?view=mMatchup&view=mMatchupScore&scoringPeriodId=${scoringPeriodId}` @@ -76,6 +95,8 @@ class Client { * @returns {DraftPlayer[]} All drafted players sorted in draft order */ getDraftInfo({ seasonId, scoringPeriodId = 0 }) { + this.constructor._validateV3Params(seasonId, 'getDraftInfo'); + const draftRoute = this.constructor._buildRoute({ base: `${seasonId}/segments/0/leagues/${this.leagueId}`, params: @@ -134,6 +155,12 @@ class Client { * @returns {Boxscore[]} All boxscores for the week */ getHistoricalScoreboardForWeek({ seasonId, matchupPeriodId, scoringPeriodId }) { + this.constructor._validateHistoricalParams( + seasonId, + 'getHistoricalScoreboardForWeek', + 'getBoxscoreForWeek' + ); + const route = this.constructor._buildRoute({ base: `${this.leagueId}`, params: `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}` + @@ -164,6 +191,8 @@ class Client { * @returns {FreeAgentPlayer[]} The list of free agents. */ getFreeAgents({ seasonId, scoringPeriodId }) { + this.constructor._validateV3Params(seasonId, 'getFreeAgents'); + const route = this.constructor._buildRoute({ base: `${seasonId}/segments/0/leagues/${this.leagueId}`, params: `?scoringPeriodId=${scoringPeriodId}&view=kona_player_info` @@ -203,6 +232,8 @@ class Client { * @returns {Team[]} The list of teams. */ getTeamsAtWeek({ seasonId, scoringPeriodId }) { + this.constructor._validateV3Params(seasonId, 'getTeamsAtWeek', 'getHistoricalTeamsAtWeek'); + const route = this.constructor._buildRoute({ base: `${seasonId}/segments/0/leagues/${this.leagueId}`, params: `?scoringPeriodId=${scoringPeriodId}&view=mRoster&view=mTeam` @@ -226,6 +257,12 @@ class Client { * @returns {Team[]} The list of teams. */ getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }) { + this.constructor._validateHistoricalParams( + seasonId, + 'getHistoricalTeamsAtWeek', + 'getTeamsAtWeek' + ); + const route = this.constructor._buildRoute({ base: `${this.leagueId}`, params: `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}` + @@ -287,6 +324,8 @@ class Client { * @returns {League} The league info. */ getLeagueInfo({ seasonId }) { + this.constructor._validateV3Params(seasonId, 'getLeagueInfo'); + const route = this.constructor._buildRoute({ base: `${seasonId}/segments/0/leagues/${this.leagueId}`, params: '?view=mSettings' diff --git a/src/client/client.test.js b/src/client/client.test.js index 0b591d1..051555d 100644 --- a/src/client/client.test.js +++ b/src/client/client.test.js @@ -218,62 +218,84 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const routeParams = `?view=mMatchup&view=mMatchupScore&scoringPeriodId=${scoringPeriodId}`; - const route = `${routeBase}${routeParams}`; + describe('when the seasonId is prior to 2018', () => { + test('throws an error', () => { + expect(() => client.getBoxscoreForWeek({ + seasonId: 2017, + matchupPeriodId, + scoringPeriodId + })).toThrow(); + }); + }); - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); - client.getBoxscoreForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(route, config); - }); + expect(() => client.getBoxscoreForWeek({ + seasonId: 2018, + matchupPeriodId, + scoringPeriodId + })).not.toThrow(); + }); - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(Boxscore, 'buildFromServer').mockImplementation(); + test('calls axios.get with the correct params', () => { + const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; + const routeParams = `?view=mMatchup&view=mMatchupScore&scoringPeriodId=${scoringPeriodId}`; + const route = `${routeBase}${routeParams}`; + + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getBoxscoreForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); - expect(Boxscore.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Boxscores', async () => { - const response = { - data: { - schedule: [{ - matchupPeriodId, - home: { teamId: 2 }, - away: { teamId: 3 } - }, { - matchupPeriodId, - home: { teamId: 5 }, - away: { teamId: 6 } - }, { - matchupPeriodId: matchupPeriodId + 1, - home: { teamId: 6 }, - away: { teamId: 2 } - }] - } - }; - - const promise = q(response); - axios.get.mockReturnValue(promise); + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(Boxscore, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); - const boxscores = await client.getBoxscoreForWeek({ - seasonId, matchupPeriodId, scoringPeriodId + client.getBoxscoreForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); + expect(Boxscore.buildFromServer).not.toBeCalled(); }); + }); - expect.hasAssertions(); - expect(boxscores.length).toBe(2); - _.forEach(boxscores, (boxscore, index) => { - expect(boxscore).toBeInstanceOf(Boxscore); - expect(boxscore.homeTeamId).toBe(response.data.schedule[index].home.teamId); - expect(boxscore.awayTeamId).toBe(response.data.schedule[index].away.teamId); + describe('after the promise resolves', () => { + test('maps response data into Boxscores', async () => { + const response = { + data: { + schedule: [{ + matchupPeriodId, + home: { teamId: 2 }, + away: { teamId: 3 } + }, { + matchupPeriodId, + home: { teamId: 5 }, + away: { teamId: 6 } + }, { + matchupPeriodId: matchupPeriodId + 1, + home: { teamId: 6 }, + away: { teamId: 2 } + }] + } + }; + + const promise = q(response); + axios.get.mockReturnValue(promise); + + const boxscores = await client.getBoxscoreForWeek({ + seasonId, matchupPeriodId, scoringPeriodId + }); + + expect.hasAssertions(); + expect(boxscores.length).toBe(2); + _.forEach(boxscores, (boxscore, index) => { + expect(boxscore).toBeInstanceOf(Boxscore); + expect(boxscore.homeTeamId).toBe(response.data.schedule[index].home.teamId); + expect(boxscore.awayTeamId).toBe(response.data.schedule[index].away.teamId); + }); }); }); }); @@ -295,39 +317,39 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const draftRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const draftRouteParams = `?view=mDraftDetail&view=mMatchup&view=mMatchupScore&scoringPeriodId=${scoringPeriodId}`; - const draftRoute = `${draftRouteBase}${draftRouteParams}`; - - const playerRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const playerRouteParams = `?scoringPeriodId=${scoringPeriodId}&view=players_wl`; - const playerRoute = `${playerRouteBase}${playerRouteParams}`; + describe('when the seasonId is prior to 2018', () => { + test('throws an error', () => { + expect(() => client.getDraftInfo({ + seasonId: 2017, + scoringPeriodId + })).toThrow(); + }); + }); - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q({ - data: { - draftDetail: { - picks: [] - }, - players: [] - } - })); + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q({ + data: { + draftDetail: { + picks: [] + }, + players: [] + } + })); - client.getDraftInfo({ seasonId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(draftRoute, config); - expect(axios.get).toBeCalledWith(playerRoute, config); - }); + expect(() => client.getDraftInfo({ + seasonId: 2018, + scoringPeriodId + })).not.toThrow(); + }); - describe('when scoringPeriodId is not passed', () => { test('calls axios.get with the correct params', () => { const draftRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const draftRouteParams = '?view=mDraftDetail&view=mMatchup&view=mMatchupScore&scoringPeriodId=0'; + const draftRouteParams = `?view=mDraftDetail&view=mMatchup&view=mMatchupScore&scoringPeriodId=${scoringPeriodId}`; const draftRoute = `${draftRouteBase}${draftRouteParams}`; const playerRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const playerRouteParams = '?scoringPeriodId=0&view=players_wl'; + const playerRouteParams = `?scoringPeriodId=${scoringPeriodId}&view=players_wl`; const playerRoute = `${playerRouteBase}${playerRouteParams}`; const config = {}; @@ -341,46 +363,73 @@ describe('Client', () => { } })); - client.getDraftInfo({ seasonId }); + client.getDraftInfo({ seasonId, scoringPeriodId }); expect(axios.get).toBeCalledWith(draftRoute, config); expect(axios.get).toBeCalledWith(playerRoute, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Boxscores', async () => { - const response = { - data: { - draftDetail: { - picks: [{ - overallPickNumber: 1, - playerId: 2 + describe('when scoringPeriodId is not passed', () => { + test('calls axios.get with the correct params', () => { + const draftRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; + const draftRouteParams = '?view=mDraftDetail&view=mMatchup&view=mMatchupScore&scoringPeriodId=0'; + const draftRoute = `${draftRouteBase}${draftRouteParams}`; + + const playerRouteBase = `${seasonId}/segments/0/leagues/${leagueId}`; + const playerRouteParams = '?scoringPeriodId=0&view=players_wl'; + const playerRoute = `${playerRouteBase}${playerRouteParams}`; + + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); + axios.get.mockReturnValue(q({ + data: { + draftDetail: { + picks: [] + }, + players: [] + } + })); + + client.getDraftInfo({ seasonId }); + expect(axios.get).toBeCalledWith(draftRoute, config); + expect(axios.get).toBeCalledWith(playerRoute, config); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into Boxscores', async () => { + const response = { + data: { + draftDetail: { + picks: [{ + overallPickNumber: 1, + playerId: 2 + }, { + overallPickNumber: 2, + playerId: 3 + }] + }, + players: [{ + player: { + id: 2 + } }, { - overallPickNumber: 2, - playerId: 3 + player: { + id: 3 + } }] - }, - players: [{ - player: { - id: 2 - } - }, { - player: { - id: 3 - } - }] - } - }; + } + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const draftPlayers = await client.getDraftInfo({ seasonId, scoringPeriodId }); + const draftPlayers = await client.getDraftInfo({ seasonId, scoringPeriodId }); - expect.hasAssertions(); - expect(draftPlayers.length).toBe(2); - _.forEach(draftPlayers, (draftPlayer) => { - expect(draftPlayer).toBeInstanceOf(DraftPlayer); + expect.hasAssertions(); + expect(draftPlayers.length).toBe(2); + _.forEach(draftPlayers, (draftPlayer) => { + expect(draftPlayer).toBeInstanceOf(DraftPlayer); + }); }); }); }); @@ -397,73 +446,95 @@ describe('Client', () => { leagueId = 213213; matchupPeriodId = 2; scoringPeriodId = 3; - seasonId = 2018; + seasonId = 2017; client = new Client({ leagueId }); jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${leagueId}`; - const routeParams = `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}` + - '&view=mMatchupScore&view=mScoreboard&view=mSettings&view=mTopPerformers&view=mTeam'; - const route = `${routeBase}${routeParams}`; - - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + describe('when the seasonId is prior to 2018', () => { + test('does not throw an error', () => { + expect(() => client.getHistoricalScoreboardForWeek({ + seasonId, + matchupPeriodId, + scoringPeriodId + })).toThrow(); + }); - client.getHistoricalScoreboardForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(route, config); - }); + test('calls axios.get with the correct params', () => { + const routeBase = `${leagueId}`; + const routeParams = `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}` + + '&view=mMatchupScore&view=mScoreboard&view=mSettings&view=mTopPerformers&view=mTeam'; + const route = `${routeBase}${routeParams}`; - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(Boxscore, 'buildFromServer').mockImplementation(); + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getHistoricalScoreboardForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); - expect(Boxscore.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Boxscores', async () => { - const response = { - data: [{ - schedule: [{ - matchupPeriodId, - home: { teamId: 2 }, - away: { teamId: 3 } - }, { - matchupPeriodId, - home: { teamId: 5 }, - away: { teamId: 6 } - }, { - matchupPeriodId: matchupPeriodId + 1, - home: { teamId: 6 }, - away: { teamId: 2 } + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(Boxscore, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); + + client.getHistoricalScoreboardForWeek({ seasonId, matchupPeriodId, scoringPeriodId }); + expect(Boxscore.buildFromServer).not.toBeCalled(); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into Boxscores', async () => { + const response = { + data: [{ + schedule: [{ + matchupPeriodId, + home: { teamId: 2 }, + away: { teamId: 3 } + }, { + matchupPeriodId, + home: { teamId: 5 }, + away: { teamId: 6 } + }, { + matchupPeriodId: matchupPeriodId + 1, + home: { teamId: 6 }, + away: { teamId: 2 } + }] }] - }] - }; + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const boxscores = await client.getHistoricalScoreboardForWeek({ - seasonId, matchupPeriodId, scoringPeriodId - }); + const boxscores = await client.getHistoricalScoreboardForWeek({ + seasonId, matchupPeriodId, scoringPeriodId + }); - expect.hasAssertions(); - expect(boxscores.length).toBe(2); - _.forEach(boxscores, (boxscore, index) => { - expect(boxscore).toBeInstanceOf(Boxscore); - expect(boxscore.homeTeamId).toBe(response.data[0].schedule[index].home.teamId); - expect(boxscore.awayTeamId).toBe(response.data[0].schedule[index].away.teamId); + expect.hasAssertions(); + expect(boxscores.length).toBe(2); + _.forEach(boxscores, (boxscore, index) => { + expect(boxscore).toBeInstanceOf(Boxscore); + expect(boxscore.homeTeamId).toBe(response.data[0].schedule[index].home.teamId); + expect(boxscore.awayTeamId).toBe(response.data[0].schedule[index].away.teamId); + }); }); }); }); + + describe('when the seasonId is 2018 or after', () => { + test('throws an error', () => { + axios.get.mockReturnValue(q()); + + expect(() => client.getHistoricalScoreboardForWeek({ + seasonId: 2018, + matchupPeriodId, + scoringPeriodId + })).toThrow(); + }); + }); }); describe('getFreeAgents', () => { @@ -482,101 +553,123 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls _buildAxiosConfig with additional headers', () => { - jest.spyOn(client, '_buildAxiosConfig').mockImplementation(); - axios.get.mockReturnValue(q()); - - client.getFreeAgents({ seasonId, scoringPeriodId }); - expect(client._buildAxiosConfig).toBeCalledWith({ - headers: { - 'x-fantasy-filter': JSON.stringify({ - players: { - filterStatus: { - value: ['FREEAGENT', 'WAIVERS'] - }, - limit: 2000, - sortPercOwned: { - sortAsc: false, - sortPriority: 1 - } - } - }) - } + describe('when the seasonId is prior to 2018', () => { + test('throws an error', () => { + expect(() => client.getFreeAgents({ + seasonId: 2017, + scoringPeriodId + })).toThrow(); }); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const routeParams = `?scoringPeriodId=${scoringPeriodId}&view=kona_player_info`; - const route = `${routeBase}${routeParams}`; + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + expect(() => client.getFreeAgents({ + seasonId: 2018, + scoringPeriodId + })).not.toThrow(); + }); - client.getFreeAgents({ seasonId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(route, config); - }); + test('calls _buildAxiosConfig with additional headers', () => { + jest.spyOn(client, '_buildAxiosConfig').mockImplementation(); + axios.get.mockReturnValue(q()); - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(FreeAgentPlayer, 'buildFromServer').mockImplementation(); + client.getFreeAgents({ seasonId, scoringPeriodId }); + expect(client._buildAxiosConfig).toBeCalledWith({ + headers: { + 'x-fantasy-filter': JSON.stringify({ + players: { + filterStatus: { + value: ['FREEAGENT', 'WAIVERS'] + }, + limit: 2000, + sortPercOwned: { + sortAsc: false, + sortPriority: 1 + } + } + }) + } + }); + }); + + test('calls axios.get with the correct params', () => { + const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; + const routeParams = `?scoringPeriodId=${scoringPeriodId}&view=kona_player_info`; + const route = `${routeBase}${routeParams}`; + + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getFreeAgents({ seasonId, scoringPeriodId }); - expect(FreeAgentPlayer.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into FreeAgentPlayers', async () => { - const response = { - data: { - players: [{ - player: { - firstName: 'Test', - lastName: 'McTestFace', - stats: [{ - seasonId, - statSourceId: 1, - statSplitTypeId: 0, + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(FreeAgentPlayer, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); + + client.getFreeAgents({ seasonId, scoringPeriodId }); + expect(FreeAgentPlayer.buildFromServer).not.toBeCalled(); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into FreeAgentPlayers', async () => { + const response = { + data: { + players: [{ + player: { + firstName: 'Test', + lastName: 'McTestFace', stats: [{ - 23: 2341, - 24: 234, - 25: 123 + seasonId, + statSourceId: 1, + statSplitTypeId: 0, + stats: [{ + 23: 2341, + 24: 234, + 25: 123 + }] }] - }] - } - }, { - player: { - firstName: 'Stable', - lastName: 'Genius', - stats: [{ - seasonId, - statSourceId: 1, - statSplitTypeId: 0, + } + }, { + player: { + firstName: 'Stable', + lastName: 'Genius', stats: [{ - 23: 32, - 24: 23124, - 25: 0 + seasonId, + statSourceId: 1, + statSplitTypeId: 0, + stats: [{ + 23: 32, + 24: 23124, + 25: 0 + }] }] - }] - } - }] - } - }; + } + }] + } + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const freeAgents = await client.getFreeAgents({ seasonId, scoringPeriodId }); + const freeAgents = await client.getFreeAgents({ seasonId, scoringPeriodId }); - expect.hasAssertions(); - expect(freeAgents.length).toBe(2); - _.forEach(freeAgents, (freeAgent, index) => { - expect(freeAgent).toBeInstanceOf(FreeAgentPlayer); - expect(freeAgent.player.firstName).toBe(response.data.players[index].player.firstName); - expect(freeAgent.player.lastName).toBe(response.data.players[index].player.lastName); + expect.hasAssertions(); + expect(freeAgents.length).toBe(2); + _.forEach(freeAgents, (freeAgent, index) => { + expect(freeAgent).toBeInstanceOf(FreeAgentPlayer); + expect(freeAgent.player.firstName).toBe( + response.data.players[index].player.firstName + ); + expect(freeAgent.player.lastName).toBe(response.data.players[index].player.lastName); + }); }); }); }); @@ -598,127 +691,149 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; - const routeParams = `?scoringPeriodId=${scoringPeriodId}&view=mRoster&view=mTeam`; - const route = `${routeBase}${routeParams}`; - - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + describe('when the seasonId is prior to 2018', () => { + test('throws an error', () => { + axios.get.mockReturnValue(q()); - client.getTeamsAtWeek({ seasonId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(route, config); + expect(() => client.getTeamsAtWeek({ + seasonId: 2017, + scoringPeriodId + })).toThrow(); + }); }); - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(Team, 'buildFromServer').mockImplementation(); + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); + + expect(() => client.getTeamsAtWeek({ + seasonId: 2018, + scoringPeriodId + })).not.toThrow(); + }); + + test('calls axios.get with the correct params', () => { + const routeBase = `${seasonId}/segments/0/leagues/${leagueId}`; + const routeParams = `?scoringPeriodId=${scoringPeriodId}&view=mRoster&view=mTeam`; + const route = `${routeBase}${routeParams}`; + + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getTeamsAtWeek({ seasonId, scoringPeriodId }); - expect(Team.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Teams', async () => { - const response = { - data: { - members: [{ - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', - lastName: 'Dude' - }, { - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', - lastName: 'Dude' - }, { - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', - lastName: 'Dude' - }], - teams: [{ - abbrev: 'SWAG', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', - record: { - overall: { - wins: 3, - losses: 11 - } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Montana' + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(Team, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); + + client.getTeamsAtWeek({ seasonId, scoringPeriodId }); + expect(Team.buildFromServer).not.toBeCalled(); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into Teams', async () => { + const response = { + data: { + members: [{ + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', + lastName: 'Dude' + }, { + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', + lastName: 'Dude' + }, { + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', + lastName: 'Dude' + }], + teams: [{ + abbrev: 'SWAG', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', + record: { + overall: { + wins: 3, + losses: 11 } - }] - } - }, { - abbrev: 'JS', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', - record: { - overall: { - wins: 5, - losses: 11 + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Montana' + } + }] } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Smith' + }, { + abbrev: 'JS', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', + record: { + overall: { + wins: 5, + losses: 11 } - }] - } - }, { - abbrev: 'SWAG', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', - record: { - overall: { - wins: 11, - losses: 8 + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Smith' + } + }] } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Brown' + }, { + abbrev: 'SWAG', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', + record: { + overall: { + wins: 11, + losses: 8 } - }] - } - }] - } - }; + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Brown' + } + }] + } + }] + } + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const teams = await client.getTeamsAtWeek({ seasonId, scoringPeriodId }); + const teams = await client.getTeamsAtWeek({ seasonId, scoringPeriodId }); - expect.hasAssertions(); - expect(teams.length).toBe(3); - _.forEach(teams, (team, index) => { - expect(team).toBeInstanceOf(Team); - expect(team.abbreviation).toBe(response.data.teams[index].abbrev); - expect(team.ownerName).toBe('Owner Dude'); - - expect(team.wins).toBe(response.data.teams[index].record.overall.wins); - expect(team.losses).toBe(response.data.teams[index].record.overall.losses); - - expect(team.roster).toEqual(expect.any(Array)); - expect(team.roster[0]).toBeInstanceOf(Player); - expect(team.roster[0].firstName).toBe( - response.data.teams[index].roster.entries[0].playerPoolEntry.firstName - ); + expect.hasAssertions(); + expect(teams.length).toBe(3); + _.forEach(teams, (team, index) => { + expect(team).toBeInstanceOf(Team); + expect(team.abbreviation).toBe(response.data.teams[index].abbrev); + expect(team.ownerName).toBe('Owner Dude'); + + expect(team.wins).toBe(response.data.teams[index].record.overall.wins); + expect(team.losses).toBe(response.data.teams[index].record.overall.losses); + + expect(team.roster).toEqual(expect.any(Array)); + expect(team.roster[0]).toBeInstanceOf(Player); + expect(team.roster[0].firstName).toBe( + response.data.teams[index].roster.entries[0].playerPoolEntry.firstName + ); + }); }); }); }); @@ -740,128 +855,148 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${leagueId}`; - const routeParams = `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}&view=mMatchupScore&view=mScoreboard&view=mSettings&view=mTopPerformers&view=mTeam&view=mRoster`; - const route = `${routeBase}${routeParams}`; - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + describe('when the seasonId is prior to 2018', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); - client.getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }); - expect(axios.get).toBeCalledWith(route, config); - }); + expect(() => client.getHistoricalTeamsAtWeek({ + seasonId, + scoringPeriodId + })).not.toThrow(); + }); - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(Team, 'buildFromServer').mockImplementation(); + test('calls axios.get with the correct params', () => { + const routeBase = `${leagueId}`; + const routeParams = `?scoringPeriodId=${scoringPeriodId}&seasonId=${seasonId}&view=mMatchupScore&view=mScoreboard&view=mSettings&view=mTopPerformers&view=mTeam&view=mRoster`; + const route = `${routeBase}${routeParams}`; + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }); - expect(Team.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Teams', async () => { - const response = { - data: [{ - members: [{ - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', - lastName: 'Dude' - }, { - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', - lastName: 'Dude' - }, { - firstName: 'Owner', - id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', - lastName: 'Dude' - }], - teams: [{ - abbrev: 'SWAG', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', - record: { - overall: { - wins: 3, - losses: 11 - } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Montana' + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(Team, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); + + client.getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }); + expect(Team.buildFromServer).not.toBeCalled(); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into Teams', async () => { + const response = { + data: [{ + members: [{ + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', + lastName: 'Dude' + }, { + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', + lastName: 'Dude' + }, { + firstName: 'Owner', + id: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', + lastName: 'Dude' + }], + teams: [{ + abbrev: 'SWAG', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4058}', + record: { + overall: { + wins: 3, + losses: 11 } - }] - } - }, { - abbrev: 'JS', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', - record: { - overall: { - wins: 5, - losses: 11 + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Montana' + } + }] } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Smith' + }, { + abbrev: 'JS', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4059}', + record: { + overall: { + wins: 5, + losses: 11 } - }] - } - }, { - abbrev: 'SWAG', - location: 'First ', - nickname: 'Last', - primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', - record: { - overall: { - wins: 11, - losses: 8 + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Smith' + } + }] } - }, - roster: { - entries: [{ - playerPoolEntry: { - firstName: 'Joe', - lastName: 'Brown' + }, { + abbrev: 'SWAG', + location: 'First ', + nickname: 'Last', + primaryOwner: '{BAD5167F-96F5-40FF-AFF0-4D2CC92F4057}', + record: { + overall: { + wins: 11, + losses: 8 } - }] - } + }, + roster: { + entries: [{ + playerPoolEntry: { + firstName: 'Joe', + lastName: 'Brown' + } + }] + } + }] }] - }] - }; + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const teams = await client.getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }); + const teams = await client.getHistoricalTeamsAtWeek({ seasonId, scoringPeriodId }); - expect.hasAssertions(); - expect(teams.length).toBe(3); - _.forEach(teams, (team, index) => { - expect(team).toBeInstanceOf(Team); - expect(team.abbreviation).toBe(response.data[0].teams[index].abbrev); - - expect(team.wins).toBe(response.data[0].teams[index].record.overall.wins); - expect(team.losses).toBe(response.data[0].teams[index].record.overall.losses); - - expect(team.roster).toEqual(expect.any(Array)); - expect(team.roster[0]).toBeInstanceOf(Player); - expect(team.roster[0].firstName).toBe( - response.data[0].teams[index].roster.entries[0].playerPoolEntry.firstName - ); + expect.hasAssertions(); + expect(teams.length).toBe(3); + _.forEach(teams, (team, index) => { + expect(team).toBeInstanceOf(Team); + expect(team.abbreviation).toBe(response.data[0].teams[index].abbrev); + + expect(team.wins).toBe(response.data[0].teams[index].record.overall.wins); + expect(team.losses).toBe(response.data[0].teams[index].record.overall.losses); + + expect(team.roster).toEqual(expect.any(Array)); + expect(team.roster[0]).toBeInstanceOf(Player); + expect(team.roster[0].firstName).toBe( + response.data[0].teams[index].roster.entries[0].playerPoolEntry.firstName + ); + }); }); }); }); + + describe('when the seasonId is 2018 or after', () => { + test('throws an error', () => { + expect(() => client.getHistoricalTeamsAtWeek({ + seasonId: 2018, + scoringPeriodId + })).toThrow(); + }); + }); }); describe('getNFLGamesForPeriod', () => { @@ -878,6 +1013,25 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); + describe('when the seasonId is prior to 2018', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); + + expect(() => client.getNFLGamesForPeriod({ + startDate: '20171010' + })).not.toThrow(); + }); + }); + + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); + expect(() => client.getNFLGamesForPeriod({ + startDate: '20181010' + })).not.toThrow(); + }); + }); + test('calls axios.get with the correct params', () => { const routeBase = 'apis/fantasy/v2/games/ffl/games'; const routeParams = `?dates=${startDate}-${endDate}&pbpOnly=true`; @@ -935,51 +1089,67 @@ describe('Client', () => { jest.spyOn(axios, 'get').mockImplementation(); }); - test('calls axios.get with the correct params', () => { - const routeBase = `${seasonId}/segments/0/leagues/${client.leagueId}`; - const routeParams = '?view=mSettings'; - const route = `${routeBase}${routeParams}`; - - const config = {}; - jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); - axios.get.mockReturnValue(q()); + describe('when the seasonId is prior to 2018', () => { + test('throws an error', () => { + axios.get.mockReturnValue(q()); - client.getLeagueInfo({ seasonId }); - expect(axios.get).toBeCalledWith(route, config); + expect(() => client.getLeagueInfo({ seasonId: 2017 })).toThrow(); + }); }); - describe('before the promise resolves', () => { - test('does not invoke callback', () => { - jest.spyOn(League, 'buildFromServer').mockImplementation(); + describe('when the seasonId is 2018 or after', () => { + test('does not throw an error', () => { + axios.get.mockReturnValue(q()); + + expect(() => client.getLeagueInfo({ seasonId: 2018 })).not.toThrow(); + }); + + test('calls axios.get with the correct params', () => { + const routeBase = `${seasonId}/segments/0/leagues/${client.leagueId}`; + const routeParams = '?view=mSettings'; + const route = `${routeBase}${routeParams}`; + + const config = {}; + jest.spyOn(client, '_buildAxiosConfig').mockReturnValue(config); axios.get.mockReturnValue(q()); client.getLeagueInfo({ seasonId }); - expect(League.buildFromServer).not.toBeCalled(); + expect(axios.get).toBeCalledWith(route, config); }); - }); - describe('after the promise resolves', () => { - test('maps response data into Teams', async () => { - const response = { - data: { - settings: { - name: 'some league', - draftSettings: {}, - rosterSettings: {}, - scheduleSettings: {} - }, - status: { - currentMatchupPeriod: 7, - latestScoringPeriod: 7 + describe('before the promise resolves', () => { + test('does not invoke callback', () => { + jest.spyOn(League, 'buildFromServer').mockImplementation(); + axios.get.mockReturnValue(q()); + + client.getLeagueInfo({ seasonId }); + expect(League.buildFromServer).not.toBeCalled(); + }); + }); + + describe('after the promise resolves', () => { + test('maps response data into Teams', async () => { + const response = { + data: { + settings: { + name: 'some league', + draftSettings: {}, + rosterSettings: {}, + scheduleSettings: {} + }, + status: { + currentMatchupPeriod: 7, + latestScoringPeriod: 7 + } } - } - }; + }; - const promise = q(response); - axios.get.mockReturnValue(promise); + const promise = q(response); + axios.get.mockReturnValue(promise); - const league = await client.getLeagueInfo({ seasonId }); - expect(league).toBeInstanceOf(League); + const league = await client.getLeagueInfo({ seasonId }); + expect(league).toBeInstanceOf(League); + }); }); }); }); From b5f2fee13b73e6e92d548ce4c9e32f0f457260ce Mon Sep 17 00:00:00 2001 From: Mike Kreiser Date: Sun, 22 Oct 2023 21:59:46 -0400 Subject: [PATCH 3/3] 1.6.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3107a85..7555f4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "espn-fantasy-football-api", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "espn-fantasy-football-api", - "version": "1.6.0", + "version": "1.6.1", "license": "LGPL-3.0-only", "dependencies": { "axios": "^1.5.0", diff --git a/package.json b/package.json index c1be1e5..e6ee5d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "espn-fantasy-football-api", - "version": "1.6.0", + "version": "1.6.1", "description": "A Javascript API to connect to ESPN's fantasy football API", "main": "web.js", "files": [