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
1 1 2277 4600000000
2 15 99 200000000
3 28 99 200000000
4 18 99 200000000
5 7 99 200000000
6 8 99 200000000
7 11 99 200000000
8 32 99 200000000
9 159 99 200000000
10 15 99 200000000
11 12 99 200000000
12 9 99 200000000
13 48 99 200000000
14 4 99 200000000
15 3 99 200000000
16 25 99 200000000
17 5 99 200000000
18 23 99 200000000
19 12 99 200000000
20 2 99 200000000
21 19 99 200000000
22 7 99 200000000
23 4 99 200000000
24 4 99 200000000
25 -1 -1
26 -1 -1
27 -1 -1
28 -1 -1
29 -1 -1
30 -1 -1
31 -1 -1
32 347584 22
33 -1 -1
34 -1 -1
35 -1 -1
36 -1 -1
37 -1 -1
38 -1 -1
39 -1 -1
40 -1 -1
41 -1 -1
42 -1 -1
43 -1 -1
44 -1 -1
45 -1 -1
46 -1 -1
47 -1 -1
48 -1 -1
49 -1 -1
50 -1 -1
51 -1 -1
52 -1 -1
53 -1 -1
54 -1 -1
55 -1 -1
56 -1 -1
57 -1 -1
58 -1 -1
59 -1 -1
60 -1 -1
61 -1 -1
62 -1 -1
63 -1 -1
64 -1 -1
65 -1 -1
66 -1 -1
67 -1 -1
68 -1 -1
69 -1 -1
70 -1 -1
71 -1 -1
72 -1 -1
73 -1 -1
74 -1 -1
75 -1 -1
76 -1 -1
77 -1 -1
78 -1 -1
79 -1 -1
80 -1 -1
81 -1 -1
82 -1 -1

View File

@@ -10,7 +10,9 @@ import {
Stats,
getPlayerTableURL,
getSkillPageURL,
getStatsURL
getStatsURL,
BOSSES,
Boss
} from '../src/index';
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_HYPHEN_NAME = 'lYnX-tiTaN';
const LYNX_TITAN_FORMATTED_NAME = 'Lynx Titan';
const FYSAD_FORMATTED_NAME = 'Fysad';
const attackTopPage = readFileSync(`${__dirname}/attackTopPage.html`, 'utf8');
const b0atyNamePage = readFileSync(`${__dirname}/b0atyNamePage.html`, 'utf8');
@@ -27,6 +30,7 @@ const lynxTitanNamePage = readFileSync(
`${__dirname}/lynxTitanNamePage.html`,
'utf8'
);
const fysadStatsSeasonal = readFileSync(`${__dirname}/fysadStatsSeasonal.csv`, 'utf8');
jest.spyOn(axios, 'get').mockImplementation((url) => {
const lynxUrls = [
@@ -46,6 +50,9 @@ jest.spyOn(axios, 'get').mockImplementation((url) => {
if (getStatsURL('main', LYNX_TITAN_FORMATTED_NAME) === url) {
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}`);
});
@@ -441,7 +448,8 @@ test('Get non-existent player', 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({
overall: { rank: expect.any(Number), level: 2277, xp: 4600000000 },
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 },
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
25,99,200000000
5,99,200000000
24,99,200000000
23,99,200000000
12,99,200000000
2,99,200000000
19,99,200000000
@@ -29,7 +29,8 @@
-1,-1
-1,-1
-1,-1
344430,22
347584,22
-1,-1
-1,-1
-1,-1
-1,-1
1 1 2277 4600000000
15 3 99 200000000
16 25 99 200000000
17 5 99 200000000
18 24 23 99 200000000
19 12 99 200000000
20 2 99 200000000
21 19 99 200000000
29 -1 -1
30 -1 -1
31 -1 -1
32 344430 347584 22
33 -1 -1
34 -1 -1
35 -1 -1
36 -1 -1

View File

@@ -68,7 +68,7 @@ export async function getRSNFormat(rsn: string): Promise<string> {
* @param csv Raw CSV from the official OSRS API.
* @returns Parsed stats object.
*/
export function parseStats(csv: string): Stats {
export function parseStats(csv: string, mode: Gamemode = 'main'): Stats {
const splitCSV = csv
.split('\n')
.filter((entry) => !!entry)
@@ -97,11 +97,17 @@ export function parseStats(csv: string): Stats {
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 bhObjects = activityObjects.splice(0, BH_MODES.length);
const clueObjects = activityObjects.splice(0, CLUES.length);
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 newSkills = { ...prev };
@@ -123,7 +129,7 @@ export function parseStats(csv: string): Stats {
const bosses: Bosses = bossObjects.reduce<Bosses>((prev, curr, index) => {
const newBosses = { ...prev };
newBosses[BOSSES[index]] = curr;
newBosses[filteredBosses[index]] = curr;
return newBosses;
}, {} as Bosses);
@@ -250,7 +256,7 @@ export async function getStatsByGamemode(
if (response.status !== 200) {
throw Error('Player not found');
}
const stats = parseStats(response.data);
const stats = parseStats(response.data, mode);
return stats;
}

View File

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