diff --git a/__tests__/attackTopPage.html b/__tests__/attackTopPage.html new file mode 100644 index 0000000..5feee3a --- /dev/null +++ b/__tests__/attackTopPage.html @@ -0,0 +1,953 @@ + + + + + + +Old School Hiscores + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+Log in +
+
+
+
+ +Old School Hiscores
+Home +
+
+
+
+ + +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +  + +Attack +Hiscores +
RankNameLevelXP
+1 + +Heur + +99 + +200,000,000 +
+2 + +Unohdettu2 + +99 + +200,000,000 +
+3 + +Drakon + +99 + +200,000,000 +
+4 + +Ame Umehara + +99 + +200,000,000 +
+5 + +Jakee + +99 + +200,000,000 +
+6 + +L00OO00OO00l + +99 + +200,000,000 +
+7 + +Howson + +99 + +200,000,000 +
+8 + +Dr PFAFF + +99 + +200,000,000 +
+9 + +Malt Lickeys + +99 + +200,000,000 +
+10 + +Burned + +99 + +200,000,000 +
+11 + +Blue Limes + +99 + +200,000,000 +
+12 + +Mini Finbarr + +99 + +200,000,000 +
+13 + +Unohdettu3 + +99 + +200,000,000 +
+14 + +Eslihero + +99 + +200,000,000 +
+15 + +Lynx Titan + +99 + +200,000,000 +
+16 + +AndrewWigins + +99 + +200,000,000 +
+17 + +iMelee + +99 + +200,000,000 +
+18 + +Portuguese + +99 + +200,000,000 +
+19 + +MarkoOSRS + +99 + +200,000,000 +
+20 + +Cairo + +99 + +200,000,000 +
+21 + +Hey Jase + +99 + +200,000,000 +
+22 + +H D M P + +99 + +200,000,000 +
+23 + +Yumemi + +99 + +200,000,000 +
+24 + +Fiiggy + +99 + +200,000,000 +
+25 + +Edgecrusher + +99 + +200,000,000 +
+ +
+
+
+
+
+
+ + +
+
+

+Search by name + + +

+
+
+
+
+

+Search by rank + + + +

+
+
+
+
+

+Compare Users + + + +

+
+
+
+
+Friends Hiscores +To view personal
+hiscores and compare
+yourself to your friends
+
+Click here +
+ +
+
+
+
+Jagex Software +

This website and its contents are copyright © 1999 - 2021 Jagex Ltd, 220 Science Park, Cambridge, CB4 0WA, United Kingdom.
Use of this website is subject to our Terms & Conditions and Privacy Policy.
Rules of Old School RuneScape | Change Cookie Settings

+OSRS RSS Feed +
+ + + + + + + + + +
+ + \ No newline at end of file diff --git a/__tests__/b0atyNamePage.html b/__tests__/b0atyNamePage.html new file mode 100644 index 0000000..bc17ad8 --- /dev/null +++ b/__tests__/b0atyNamePage.html @@ -0,0 +1,955 @@ + + + + + + +Old School Hiscores + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+Log in +
+
+
+
+ +Old School Hiscores
+Home +
+
+
+
+ + +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +  +Overall +Hiscores +
RankNameLevelXP
+8,576 + +Skreecher + +2,277 + +456,007,859 +
+8,577 + +Headlines v2 + +2,277 + +456,004,101 +
+8,578 + +Bald Male + +2,277 + +455,954,019 +
+8,579 + +Pennywise + +2,277 + +455,939,160 +
+8,580 + +zwolle 0038 + +2,277 + +455,931,261 +
+8,581 + +Adios luega + +2,277 + +455,916,692 +
+8,582 + +Will man + +2,277 + +455,916,362 +
+8,583 + +My Coxy Rekt + +2,277 + +455,885,198 +
+8,584 + +Facehuntter + +2,277 + +455,852,905 +
+8,585 + +Wtf Need Yak + +2,277 + +455,818,042 +
+8,586 + +Hakala + +2,277 + +455,817,635 +
+8,587 + +Mike TheGuy + +2,277 + +455,798,477 +
+8,588 + +microwave62 + +2,277 + +455,716,336 +
+8,589 + +PCCZ + +2,277 + +455,706,491 +
+8,590 + +CK9 + +2,277 + +455,704,723 +
+8,591 + +Flavaaaaa + +2,277 + +455,685,632 +
+8,592 + +LoliElie + +2,277 + +455,659,464 +
+8,593 + +Give Advice + +2,277 + +455,653,828 +
+8,594 + +danzing + +2,277 + +455,651,024 +
+8,595 + +EVScape + +2,277 + +455,634,426 +
+8,596 + +rakete + +2,277 + +455,623,918 +
+8,597 + +Bear MaxYmum + +2,277 + +455,618,823 +
+8,598 + +B0aty + +2,277 + +455,618,480 +
+8,599 + +Alt Huss + +2,277 + +455,613,721 +
+8,600 + +Blak Mk + +2,277 + +455,609,237 +
+ +
+
+
+
+
+
+ + +
+
+

+Search by name + + +

+
+
+
+
+

+Search by rank + + + +

+
+
+
+
+

+Compare Users + + + +

+
+
+
+
+Friends Hiscores +To view personal
+hiscores and compare
+yourself to your friends
+
+Click here +
+ +
+
+
+
+Jagex Software +

This website and its contents are copyright © 1999 - 2021 Jagex Ltd, 220 Science Park, Cambridge, CB4 0WA, United Kingdom.
Use of this website is subject to our Terms & Conditions and Privacy Policy.
Rules of Old School RuneScape | Change Cookie Settings

+OSRS RSS Feed +
+ + + + + + + + + +
+ + \ No newline at end of file diff --git a/__tests__/hiscores.test.ts b/__tests__/hiscores.test.ts index 6834963..b6068a9 100644 --- a/__tests__/hiscores.test.ts +++ b/__tests__/hiscores.test.ts @@ -1,12 +1,54 @@ +import axios from 'axios'; +import { readFileSync } from 'fs'; + import { parseStats, getSkillPage, getStats, getStatsByGamemode, getRSNFormat, - Stats + Stats, + getPlayerTableURL, + getSkillPageURL, + getStatsURL } from '../src/index'; +const B0ATY_NAME = 'B0ATY'; +const B0ATY_FORMATTED_NAME = 'B0aty'; +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 attackTopPage = readFileSync(`${__dirname}/attackTopPage.html`, 'utf8'); +const b0atyNamePage = readFileSync(`${__dirname}/b0atyNamePage.html`, 'utf8'); +const lynxTitanStats = readFileSync(`${__dirname}/lynxTitanStats.csv`, 'utf8'); +const lynxTitanNamePage = readFileSync( + `${__dirname}/lynxTitanNamePage.html`, + 'utf8' +); + +jest.spyOn(axios, 'get').mockImplementation((url) => { + const lynxUrls = [ + getPlayerTableURL('main', LYNX_TITAN_SPACE_NAME), + getPlayerTableURL('main', LYNX_TITAN_UNDERSCORE_NAME), + getPlayerTableURL('main', LYNX_TITAN_HYPHEN_NAME) + ]; + if (lynxUrls.includes(url)) { + return Promise.resolve({ data: lynxTitanNamePage }); + } + if (getPlayerTableURL('main', B0ATY_NAME) === url) { + return Promise.resolve({ data: b0atyNamePage }); + } + if (getSkillPageURL('main', 'attack', 1) === url) { + return Promise.resolve({ data: attackTopPage }); + } + if (getStatsURL('main', LYNX_TITAN_FORMATTED_NAME) === url) { + return Promise.resolve({ status: 200, data: lynxTitanStats }); + } + throw new Error(`No mock response for URL: ${url}`); +}); + test('Parse CSV to json', () => { const csv = `246,2277,1338203419 615,99,77438259 @@ -187,33 +229,27 @@ test('Parse CSV to json', () => { describe('Get name format', () => { it('gets a name with a space', async () => { - jest.setTimeout(30000); - const data = await getRSNFormat('lYnX tiTaN'); - expect(data).toBe('Lynx Titan'); + const data = await getRSNFormat(LYNX_TITAN_SPACE_NAME); + expect(data).toBe(LYNX_TITAN_FORMATTED_NAME); }); it('gets a name with an underscore', async () => { - jest.setTimeout(30000); - const data = await getRSNFormat('lYnX_tiTaN'); - expect(data).toBe('Lynx Titan'); + const data = await getRSNFormat(LYNX_TITAN_UNDERSCORE_NAME); + expect(data).toBe(LYNX_TITAN_FORMATTED_NAME); }); it('gets a name with a hyphen', async () => { - jest.setTimeout(30000); - const data = await getRSNFormat('lYnX-tiTaN'); - expect(data).toBe('Lynx Titan'); + const data = await getRSNFormat(LYNX_TITAN_HYPHEN_NAME); + expect(data).toBe(LYNX_TITAN_FORMATTED_NAME); }); it('gets a name with a number', async () => { - jest.setTimeout(30000); - const data = await getRSNFormat('B0ATY'); - expect(data).toBe('B0aty'); + const data = await getRSNFormat(B0ATY_NAME); + expect(data).toBe(B0ATY_FORMATTED_NAME); }); it('throws an error for a name with invalid characters', async () => { - jest.setTimeout(30000); await expect(getRSNFormat('b&aty')).rejects.toBeTruthy(); }); }); test('Get attack top page', async () => { - jest.setTimeout(30000); const data = await getSkillPage('attack'); expect(data).toMatchObject([ { @@ -395,7 +431,6 @@ test('Get attack top page', async () => { }); test('Get non-existent player', async () => { - jest.setTimeout(30000); getStats('fishy').catch((err) => { if (err.response) { expect(err.response.status).toBe(404); @@ -404,8 +439,7 @@ test('Get non-existent player', async () => { }); test('Get stats by gamemode', async () => { - jest.setTimeout(30000); - const { skills } = await getStatsByGamemode('Lynx Titan'); + const { skills } = 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 }, diff --git a/__tests__/lynxTitanNamePage.html b/__tests__/lynxTitanNamePage.html new file mode 100644 index 0000000..83ed3ef --- /dev/null +++ b/__tests__/lynxTitanNamePage.html @@ -0,0 +1,952 @@ + + + + + + +Old School Hiscores + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+Log in +
+
+
+
+ +Old School Hiscores
+Home +
+
+
+
+ + +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +  +Overall +Hiscores +
RankNameLevelXP
+1 + +Lynx Titan + +2,277 + +4,600,000,000 +
+2 + +Hey Jase + +2,277 + +4,600,000,000 +
+3 + +ShawnBay + +2,277 + +4,600,000,000 +
+4 + +senZe + +2,277 + +4,600,000,000 +
+5 + +Tomdabom + +2,277 + +4,600,000,000 +
+6 + +Karma + +2,277 + +4,600,000,000 +
+7 + +Harmony + +2,277 + +4,600,000,000 +
+8 + +DedWilson + +2,277 + +4,600,000,000 +
+9 + +GodTormentor + +2,277 + +4,600,000,000 +
+10 + +Vinny + +2,277 + +4,600,000,000 +
+11 + +borsi + +2,277 + +4,600,000,000 +
+12 + +Brundeen + +2,277 + +4,600,000,000 +
+13 + +Aziz + +2,277 + +4,600,000,000 +
+14 + +Eeli + +2,277 + +4,600,000,000 +
+15 + +baile y + +2,277 + +4,600,000,000 +
+16 + +Dumbfounded + +2,277 + +4,578,922,635 +
+17 + +Dan Gleesac + +2,277 + +4,533,050,279 +
+18 + +blind idiot + +2,277 + +4,522,080,162 +
+19 + +he box jonge + +2,277 + +4,511,571,769 +
+20 + +Oskar + +2,277 + +4,488,710,108 +
+21 + +Randalicious + +2,277 + +4,431,024,107 +
+22 + +Gustav + +2,277 + +4,414,384,551 +
+23 + +Capt King + +2,277 + +4,366,733,065 +
+24 + +Joonas + +2,277 + +4,318,668,761 +
+25 + +Killzone + +2,277 + +4,289,590,389 +
+ +
+
+
+
+
+
+ + +
+
+

+Search by name + + +

+
+
+
+
+

+Search by rank + + + +

+
+
+
+
+

+Compare Users + + + +

+
+
+
+
+Friends Hiscores +To view personal
+hiscores and compare
+yourself to your friends
+
+Click here +
+ +
+
+
+
+Jagex Software +

This website and its contents are copyright � 1999 - 2021 Jagex Ltd, 220 Science Park, Cambridge, CB4 0WA, United Kingdom.
Use of this website is subject to our Terms & Conditions and Privacy Policy.
Rules of Old School RuneScape | Change Cookie Settings

+OSRS RSS Feed +
+ + + + + + + + + +
+ + \ No newline at end of file diff --git a/__tests__/lynxTitanStats.csv b/__tests__/lynxTitanStats.csv new file mode 100644 index 0000000..eeb1321 --- /dev/null +++ b/__tests__/lynxTitanStats.csv @@ -0,0 +1,81 @@ +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 +24,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 +344430,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 \ No newline at end of file diff --git a/package.json b/package.json index 3e572d7..cada6f6 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "root": true, "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "./tsconfig.json" + "project": "./tsconfig.eslint.json" }, "plugins": [ "@typescript-eslint" diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..f3d3958 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": true, + "outDir": "./lib", + "strict": true + }, + "include": ["src", "**/__tests__/*"], + "exclude": ["node_modules"] +}