From 4dd7b57f17df2ef344197d6515ddc17183c5a890 Mon Sep 17 00:00:00 2001 From: Mike Kreiser Date: Sun, 5 Nov 2023 12:58:00 -0500 Subject: [PATCH] BREAKING: Refactor BoxscorePlayer to be a subclass of Player --- src/boxscore-player/boxscore-player.js | 38 ++++++++++----------- src/boxscore-player/boxscore-player.test.js | 30 +++++++++------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/boxscore-player/boxscore-player.js b/src/boxscore-player/boxscore-player.js index ccc0940..8f73f9f 100644 --- a/src/boxscore-player/boxscore-player.js +++ b/src/boxscore-player/boxscore-player.js @@ -1,7 +1,5 @@ import _ from 'lodash'; -import BaseObject from '../base-classes/base-object/base-object'; - import Player from '../player/player'; import { parsePlayerStats } from '../player-stats/player-stats'; @@ -12,39 +10,41 @@ import { slotCategoryIdToPositionMap } from '../constants'; /** * Represents a player and their stats on a boxscore. * - * @augments {BaseObject} + * @augments {Player} */ -class BoxscorePlayer extends BaseObject { +class BoxscorePlayer extends Player { static displayName = 'BoxscorePlayer'; + /* eslint-disable jsdoc/no-undefined-types */ /** - * @typedef {object} BoxscorePlayerMap + * @typedef {PlayerMap} BoxscorePlayerMap * * @property {Player} player The player model representing the NFL player. - * @property {string} position The position the player is slotted at in the fantasy lineup. + * @property {string} rosteredPosition The position the player is slotted at in the fantasy lineup * @property {number} totalPoints The total points scored by the player. * @property {PlayerStats} pointBreakdown The PlayerStats model with the points scored by the * player. * @property {PlayerStats} rawStats The PlayerStats model with the raw statistics registered by * the player. */ + /* eslint-enable jsdoc/no-undefined-types */ /** * @type {BoxscorePlayerMap} */ static responseMap = { - player: { - key: 'playerPoolEntry', - BaseObject: Player + availabilityStatus: { + key: 'status', + manualParse: (responseData, data, rawData) => rawData.playerPoolEntry.status }, - position: { + rosteredPosition: { key: 'lineupSlotId', manualParse: (responseData) => _.get(slotCategoryIdToPositionMap, responseData) }, - totalPoints: 'playerPoolEntry.appliedStatTotal', + totalPoints: 'appliedStatTotal', pointBreakdown: { - key: 'playerPoolEntry', - manualParse: (responseData, data, constructorParams) => parsePlayerStats({ + key: 'stats', + manualParse: (responseData, data, rawData, constructorParams) => parsePlayerStats({ responseData, constructorParams, usesPoints: true, @@ -54,8 +54,8 @@ class BoxscorePlayer extends BaseObject { }) }, projectedPointBreakdown: { - key: 'playerPoolEntry', - manualParse: (responseData, data, constructorParams) => parsePlayerStats({ + key: 'stats', + manualParse: (responseData, data, rawData, constructorParams) => parsePlayerStats({ responseData, constructorParams, usesPoints: true, @@ -65,8 +65,8 @@ class BoxscorePlayer extends BaseObject { }) }, rawStats: { - key: 'playerPoolEntry', - manualParse: (responseData, data, constructorParams) => parsePlayerStats({ + key: 'stats', + manualParse: (responseData, data, rawData, constructorParams) => parsePlayerStats({ responseData, constructorParams, usesPoints: false, @@ -76,8 +76,8 @@ class BoxscorePlayer extends BaseObject { }) }, projectedRawStats: { - key: 'playerPoolEntry', - manualParse: (responseData, data, constructorParams) => parsePlayerStats({ + key: 'stats', + manualParse: (responseData, data, rawData, constructorParams) => parsePlayerStats({ responseData, constructorParams, usesPoints: false, diff --git a/src/boxscore-player/boxscore-player.test.js b/src/boxscore-player/boxscore-player.test.js index ae81438..c32aa2f 100644 --- a/src/boxscore-player/boxscore-player.test.js +++ b/src/boxscore-player/boxscore-player.test.js @@ -1,7 +1,5 @@ import _ from 'lodash'; -import BaseObject from '../base-classes/base-object/base-object.js'; - import PlayerStats from '../player-stats/player-stats'; import { slotCategoryIdToPositionMap } from '../constants'; @@ -9,11 +7,6 @@ import { slotCategoryIdToPositionMap } from '../constants'; import BoxscorePlayer from './boxscore-player.js'; describe('BoxscorePlayer', () => { - test('extends BaseObject', () => { - const instance = new BoxscorePlayer(); - expect(instance).toBeInstanceOf(BaseObject); - }); - describe('responseMap', () => { const buildBoxscorePlayer = (data, options) => BoxscorePlayer.buildFromServer(data, options); @@ -52,16 +45,29 @@ describe('BoxscorePlayer', () => { playerPoolEntry: { player: { stats: [projectedStats, pointStats] - } - } + }, + status: 'ONTEAM' + }, + status: 'NORMAL' }; }); - describe('position', () => { + describe('availabilityStatus', () => { describe('manualParse', () => { - test('maps id to human readable position', () => { + test('maps from rawData to override collision with other status', () => { const player = buildBoxscorePlayer(data); - expect(player.position).toBe(_.get(slotCategoryIdToPositionMap, data.lineupSlotId)); + expect(player.availabilityStatus).toBe(data.playerPoolEntry.status); + }); + }); + }); + + describe('rosteredPosition', () => { + describe('manualParse', () => { + test('maps id to human readable rosteredPosition', () => { + const player = buildBoxscorePlayer(data); + expect(player.rosteredPosition).toBe( + _.get(slotCategoryIdToPositionMap, data.lineupSlotId) + ); }); }); });