mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
Add functions to support JSON endpoint.
This commit is contained in:
@@ -13,7 +13,9 @@ import {
|
||||
getStatsURL,
|
||||
BOSSES,
|
||||
INVALID_FORMAT_ERROR,
|
||||
BH_MODES
|
||||
BH_MODES,
|
||||
parseJsonStats,
|
||||
HiscoresResponse
|
||||
} from '../src/index';
|
||||
|
||||
const B0ATY_NAME = 'B0ATY';
|
||||
@@ -25,6 +27,10 @@ const LYNX_TITAN_FORMATTED_NAME = 'Lynx Titan';
|
||||
|
||||
const attackTopPage = readFileSync(`${__dirname}/attackTopPage.html`, 'utf8');
|
||||
const b0atyNamePage = readFileSync(`${__dirname}/b0atyNamePage.html`, 'utf8');
|
||||
const b0atyStatsCsv = readFileSync(`${__dirname}/b0atyStats.csv`, 'utf8');
|
||||
const b0atyStatsJson: HiscoresResponse = JSON.parse(
|
||||
readFileSync(`${__dirname}/b0atyStats.json`, 'utf8')
|
||||
);
|
||||
const lynxTitanStats = readFileSync(`${__dirname}/lynxTitanStats.csv`, 'utf8');
|
||||
const lynxTitanNamePage = readFileSync(
|
||||
`${__dirname}/lynxTitanNamePage.html`,
|
||||
@@ -184,7 +190,7 @@ test('Parse CSV to json', () => {
|
||||
hunterV2: { rank: 89914, score: 35 },
|
||||
rogueV2: { rank: 99834, score: 25 },
|
||||
hunter: { rank: 99831, score: 23 },
|
||||
rogue: { rank: 89912, score: 37 },
|
||||
rogue: { rank: 89912, score: 37 }
|
||||
},
|
||||
lastManStanding: { rank: 4814, score: 898 },
|
||||
pvpArena: { rank: 13, score: 4057 },
|
||||
@@ -533,13 +539,13 @@ describe('Get stats options', () => {
|
||||
beforeEach(() => {
|
||||
axios.get = jest.fn(
|
||||
(url) =>
|
||||
new Promise<any>((resolve) =>
|
||||
new Promise<any>((resolve) => {
|
||||
resolve(
|
||||
url === getPlayerTableURL('main', rsn)
|
||||
? { data: lynxTitanNamePage }
|
||||
: { status: 200, data: lynxTitanStats }
|
||||
)
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
axiosMock = axios.get as any;
|
||||
axiosMock.mockClear();
|
||||
@@ -573,3 +579,9 @@ describe('Get stats options', () => {
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
test('CSV and JSON parsing outputs identical object', async () => {
|
||||
const csvOutput = parseStats(b0atyStatsCsv);
|
||||
const jsonOutput = parseJsonStats(b0atyStatsJson);
|
||||
expect(csvOutput).toEqual(jsonOutput);
|
||||
});
|
||||
|
Reference in New Issue
Block a user