@tailgatefantasysports/seasonservice 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SeasonService.js +23 -0
- package/__tests__/SeasonService.test.js +61 -0
- package/app.config.js +14 -0
- package/package.json +1 -1
package/SeasonService.js
CHANGED
|
@@ -70,6 +70,29 @@ module.exports = class SeasonService {
|
|
|
70
70
|
return this._getSeasonDirection(date, -1);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Get the previous complete season, including all types.
|
|
75
|
+
* @summary Starting from `date`, walk backwards by one week to the nearest season.
|
|
76
|
+
* Using that seasons `season` property continue to walk backwards to find all types of previous season.
|
|
77
|
+
* @param {object} date - date to begin search
|
|
78
|
+
* @returns {object}
|
|
79
|
+
*/
|
|
80
|
+
getPreviousFullSeason(date) {
|
|
81
|
+
let frame = this.getPreviousSeason(date);
|
|
82
|
+
if (!frame)
|
|
83
|
+
return null
|
|
84
|
+
|
|
85
|
+
const full = { };
|
|
86
|
+
let season = frame.season,
|
|
87
|
+
newFrame = frame;
|
|
88
|
+
while (newFrame && newFrame.season === season) {
|
|
89
|
+
full[newFrame.type] = newFrame;
|
|
90
|
+
newFrame = this.getPreviousSeason(newFrame.start - 1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return full;
|
|
94
|
+
}
|
|
95
|
+
|
|
73
96
|
/**
|
|
74
97
|
* Walks to a nearby season from date in direction
|
|
75
98
|
* @param {number} direction - direction to get season (1 for next, -1 for previous)
|
|
@@ -19,6 +19,20 @@ beforeEach(() => {
|
|
|
19
19
|
start: new Date('2021-03-01'),
|
|
20
20
|
end: new Date('2021-04-01')
|
|
21
21
|
}
|
|
22
|
+
},
|
|
23
|
+
3: {
|
|
24
|
+
[types.preseason]: {
|
|
25
|
+
start: new Date('2022-01-01'),
|
|
26
|
+
end: new Date('2022-02-01')
|
|
27
|
+
},
|
|
28
|
+
[types.regular]: {
|
|
29
|
+
start: new Date('2022-02-01'),
|
|
30
|
+
end: new Date('2022-03-01')
|
|
31
|
+
},
|
|
32
|
+
[types.postseason]: {
|
|
33
|
+
start: new Date('2022-03-01'),
|
|
34
|
+
end: new Date('2022-04-01')
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
}
|
|
24
38
|
});
|
|
@@ -90,3 +104,50 @@ describe('Get Next/Previous Season', () => {
|
|
|
90
104
|
expect(season).toBeUndefined();
|
|
91
105
|
});
|
|
92
106
|
})
|
|
107
|
+
|
|
108
|
+
describe('GetPreviousFullSeason', () => {
|
|
109
|
+
test.each([
|
|
110
|
+
['Exists - start outside frame', new Date('2022-5-30'), {
|
|
111
|
+
[types.preseason]: {
|
|
112
|
+
season: "3",
|
|
113
|
+
type: types.preseason,
|
|
114
|
+
start: new Date('2022-01-01'),
|
|
115
|
+
end: new Date('2022-02-01')
|
|
116
|
+
},
|
|
117
|
+
[types.regular]: {
|
|
118
|
+
season: "3",
|
|
119
|
+
type: types.regular,
|
|
120
|
+
start: new Date('2022-02-01'),
|
|
121
|
+
end: new Date('2022-03-01')
|
|
122
|
+
},
|
|
123
|
+
[types.postseason]: {
|
|
124
|
+
season: "3",
|
|
125
|
+
type: types.postseason,
|
|
126
|
+
start: new Date('2022-03-01'),
|
|
127
|
+
end: new Date('2022-04-01')
|
|
128
|
+
}
|
|
129
|
+
}],
|
|
130
|
+
['Exists - start inside frame', new Date('2022-02-02'), {
|
|
131
|
+
[types.preseason]: {
|
|
132
|
+
season: "3",
|
|
133
|
+
type: types.preseason,
|
|
134
|
+
start: new Date('2022-01-01'),
|
|
135
|
+
end: new Date('2022-02-01')
|
|
136
|
+
},
|
|
137
|
+
[types.regular]: {
|
|
138
|
+
season: "3",
|
|
139
|
+
type: types.regular,
|
|
140
|
+
start: new Date('2022-02-01'),
|
|
141
|
+
end: new Date('2022-03-01')
|
|
142
|
+
},
|
|
143
|
+
}],
|
|
144
|
+
['Doesn\'t exist', new Date('2019-01-01'), null]
|
|
145
|
+
])('%s', (_tName, inp, expected) => {
|
|
146
|
+
// setup
|
|
147
|
+
// execute
|
|
148
|
+
let season = this.service.getPreviousFullSeason(inp);
|
|
149
|
+
|
|
150
|
+
// assert
|
|
151
|
+
expect(season).toStrictEqual(expected);
|
|
152
|
+
});
|
|
153
|
+
})
|
package/app.config.js
CHANGED
|
@@ -45,6 +45,20 @@ module.exports = {
|
|
|
45
45
|
start: new Date('2023-01-11T00:00:00Z'),
|
|
46
46
|
end: new Date('2023-02-15T00:00:00Z'),
|
|
47
47
|
}
|
|
48
|
+
},
|
|
49
|
+
2023: {
|
|
50
|
+
[types.preseason]: {
|
|
51
|
+
start: new Date('2023-08-02T00:00:00Z'),
|
|
52
|
+
end: new Date('2023-08-30T00:00:00Z')
|
|
53
|
+
},
|
|
54
|
+
[types.regular]: {
|
|
55
|
+
start: new Date('2023-09-06T00:00:00Z'),
|
|
56
|
+
end: new Date('2023-01-10T00:00:00Z'),
|
|
57
|
+
},
|
|
58
|
+
[types.postseason]: {
|
|
59
|
+
start: new Date('2023-01-10T00:00:00Z'),
|
|
60
|
+
end: new Date('2023-02-14T00:00:00Z'),
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
64
|
}
|