Skip to content

Commit

Permalink
BREAKING: Refactor BoxscorePlayer to be a subclass of Player
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreiser committed Nov 12, 2023
1 parent 4632121 commit 4dd7b57
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
38 changes: 19 additions & 19 deletions src/boxscore-player/boxscore-player.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
30 changes: 18 additions & 12 deletions src/boxscore-player/boxscore-player.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import _ from 'lodash';

import BaseObject from '../base-classes/base-object/base-object.js';

import PlayerStats from '../player-stats/player-stats';

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);

Expand Down Expand Up @@ -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)
);
});
});
});
Expand Down

0 comments on commit 4dd7b57

Please sign in to comment.