Merge pull request #35 from Not-Jayden/fix-seasonal-bosses-results

[Bug fix] Add conditional bosses filter if gamemode is seasonal
This commit is contained in:
Max Swartwout
2021-06-08 17:08:44 -04:00
committed by GitHub
5 changed files with 128 additions and 9 deletions

View File

@@ -0,0 +1,82 @@
1,2277,4600000000
15,99,200000000
28,99,200000000
18,99,200000000
7,99,200000000
8,99,200000000
11,99,200000000
32,99,200000000
159,99,200000000
15,99,200000000
12,99,200000000
9,99,200000000
48,99,200000000
4,99,200000000
3,99,200000000
25,99,200000000
5,99,200000000
23,99,200000000
12,99,200000000
2,99,200000000
19,99,200000000
7,99,200000000
4,99,200000000
4,99,200000000
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
347584,22
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
Can't render this file because it has a wrong number of fields in line 25.

View File

@@ -10,7 +10,9 @@ import {
Stats, Stats,
getPlayerTableURL, getPlayerTableURL,
getSkillPageURL, getSkillPageURL,
getStatsURL getStatsURL,
BOSSES,
Boss
} from '../src/index'; } from '../src/index';
const B0ATY_NAME = 'B0ATY'; const B0ATY_NAME = 'B0ATY';
@@ -19,6 +21,7 @@ const LYNX_TITAN_SPACE_NAME = 'lYnX tiTaN';
const LYNX_TITAN_UNDERSCORE_NAME = 'lYnX_tiTaN'; const LYNX_TITAN_UNDERSCORE_NAME = 'lYnX_tiTaN';
const LYNX_TITAN_HYPHEN_NAME = 'lYnX-tiTaN'; const LYNX_TITAN_HYPHEN_NAME = 'lYnX-tiTaN';
const LYNX_TITAN_FORMATTED_NAME = 'Lynx Titan'; const LYNX_TITAN_FORMATTED_NAME = 'Lynx Titan';
const FYSAD_FORMATTED_NAME = 'Fysad';
const attackTopPage = readFileSync(`${__dirname}/attackTopPage.html`, 'utf8'); const attackTopPage = readFileSync(`${__dirname}/attackTopPage.html`, 'utf8');
const b0atyNamePage = readFileSync(`${__dirname}/b0atyNamePage.html`, 'utf8'); const b0atyNamePage = readFileSync(`${__dirname}/b0atyNamePage.html`, 'utf8');
@@ -27,6 +30,7 @@ const lynxTitanNamePage = readFileSync(
`${__dirname}/lynxTitanNamePage.html`, `${__dirname}/lynxTitanNamePage.html`,
'utf8' 'utf8'
); );
const fysadStatsSeasonal = readFileSync(`${__dirname}/fysadStatsSeasonal.csv`, 'utf8');
jest.spyOn(axios, 'get').mockImplementation((url) => { jest.spyOn(axios, 'get').mockImplementation((url) => {
const lynxUrls = [ const lynxUrls = [
@@ -46,6 +50,9 @@ jest.spyOn(axios, 'get').mockImplementation((url) => {
if (getStatsURL('main', LYNX_TITAN_FORMATTED_NAME) === url) { if (getStatsURL('main', LYNX_TITAN_FORMATTED_NAME) === url) {
return Promise.resolve({ status: 200, data: lynxTitanStats }); return Promise.resolve({ status: 200, data: lynxTitanStats });
} }
if (getStatsURL('seasonal', FYSAD_FORMATTED_NAME) === url) {
return Promise.resolve({ status: 200, data: fysadStatsSeasonal });
}
throw new Error(`No mock response for URL: ${url}`); throw new Error(`No mock response for URL: ${url}`);
}); });
@@ -441,7 +448,8 @@ test('Get non-existent player', async () => {
}); });
test('Get stats by gamemode', async () => { test('Get stats by gamemode', async () => {
const { skills } = await getStatsByGamemode(LYNX_TITAN_FORMATTED_NAME); const { skills, bosses } = await getStatsByGamemode(LYNX_TITAN_FORMATTED_NAME);
expect(skills).toMatchObject({ expect(skills).toMatchObject({
overall: { rank: expect.any(Number), level: 2277, xp: 4600000000 }, overall: { rank: expect.any(Number), level: 2277, xp: 4600000000 },
attack: { rank: expect.any(Number), level: 99, xp: 200000000 }, attack: { rank: expect.any(Number), level: 99, xp: 200000000 },
@@ -468,4 +476,21 @@ test('Get stats by gamemode', async () => {
hunter: { rank: expect.any(Number), level: 99, xp: 200000000 }, hunter: { rank: expect.any(Number), level: 99, xp: 200000000 },
construction: { rank: expect.any(Number), level: 99, xp: 200000000 } construction: { rank: expect.any(Number), level: 99, xp: 200000000 }
}); });
const bossKeys = Object.keys(bosses);
expect(bossKeys).toStrictEqual(BOSSES);
expect.assertions(2);
});
test('Get stats by game mode seasonal (omit TOB: Hard Mode from bosses)', async () => {
const {bosses} = await getStatsByGamemode(FYSAD_FORMATTED_NAME, 'seasonal');
const bossKeys = Object.keys(bosses);
const filteredBosses = BOSSES.filter(boss => boss !== 'theatreOfBloodHardMode');
expect(bossKeys).toStrictEqual(filteredBosses);
expect(bossKeys).not.toContain<Boss>('theatreOfBloodHardMode');
expect.assertions(2);
}); });

View File

@@ -15,7 +15,7 @@
3,99,200000000 3,99,200000000
25,99,200000000 25,99,200000000
5,99,200000000 5,99,200000000
24,99,200000000 23,99,200000000
12,99,200000000 12,99,200000000
2,99,200000000 2,99,200000000
19,99,200000000 19,99,200000000
@@ -29,7 +29,8 @@
-1,-1 -1,-1
-1,-1 -1,-1
-1,-1 -1,-1
344430,22 347584,22
-1,-1
-1,-1 -1,-1
-1,-1 -1,-1
-1,-1 -1,-1
Can't render this file because it has a wrong number of fields in line 25.

View File

@@ -68,7 +68,7 @@ export async function getRSNFormat(rsn: string): Promise<string> {
* @param csv Raw CSV from the official OSRS API. * @param csv Raw CSV from the official OSRS API.
* @returns Parsed stats object. * @returns Parsed stats object.
*/ */
export function parseStats(csv: string): Stats { export function parseStats(csv: string, mode: Gamemode = 'main'): Stats {
const splitCSV = csv const splitCSV = csv
.split('\n') .split('\n')
.filter((entry) => !!entry) .filter((entry) => !!entry)
@@ -97,11 +97,17 @@ export function parseStats(csv: string): Stats {
return activity; return activity;
}); });
/** `seasonal` API results don't currently include TOB: Hard Mode, so it needs to be filtered out in that case. */
const filteredBosses =
mode === 'seasonal'
? BOSSES.filter((boss) => boss !== 'theatreOfBloodHardMode')
: BOSSES;
const [leaguePoints] = activityObjects.splice(0, 1); const [leaguePoints] = activityObjects.splice(0, 1);
const bhObjects = activityObjects.splice(0, BH_MODES.length); const bhObjects = activityObjects.splice(0, BH_MODES.length);
const clueObjects = activityObjects.splice(0, CLUES.length); const clueObjects = activityObjects.splice(0, CLUES.length);
const [lastManStanding, soulWarsZeal] = activityObjects.splice(0, 2); const [lastManStanding, soulWarsZeal] = activityObjects.splice(0, 2);
const bossObjects = activityObjects.splice(0, BOSSES.length); const bossObjects = activityObjects.splice(0, filteredBosses.length);
const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => { const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => {
const newSkills = { ...prev }; const newSkills = { ...prev };
@@ -123,7 +129,7 @@ export function parseStats(csv: string): Stats {
const bosses: Bosses = bossObjects.reduce<Bosses>((prev, curr, index) => { const bosses: Bosses = bossObjects.reduce<Bosses>((prev, curr, index) => {
const newBosses = { ...prev }; const newBosses = { ...prev };
newBosses[BOSSES[index]] = curr; newBosses[filteredBosses[index]] = curr;
return newBosses; return newBosses;
}, {} as Bosses); }, {} as Bosses);
@@ -250,7 +256,7 @@ export async function getStatsByGamemode(
if (response.status !== 200) { if (response.status !== 200) {
throw Error('Player not found'); throw Error('Player not found');
} }
const stats = parseStats(response.data); const stats = parseStats(response.data, mode);
return stats; return stats;
} }

View File

@@ -4,7 +4,12 @@
"module": "commonjs", "module": "commonjs",
"declaration": true, "declaration": true,
"outDir": "./lib", "outDir": "./lib",
"strict": true "strict": true,
"lib": ["ES2015", "DOM", "DOM.Iterable"],
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
}, },
"include": ["src"], "include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"] "exclude": ["node_modules", "**/__tests__/*"]