Skip to content

Commit

Permalink
Add hyphen to valid rsn regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxswa committed May 1, 2021
1 parent 163f4dd commit a406502
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
95 changes: 58 additions & 37 deletions __tests__/hiscores.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getStats,
getStatsByGamemode,
getRSNFormat,
Stats,
Stats
} from '../src/index';

test('Parse CSV to json', () => {
Expand Down Expand Up @@ -115,12 +115,12 @@ test('Parse CSV to json', () => {
farming: { rank: 821, level: 99, xp: 62123353 },
runecraft: { rank: 169, level: 99, xp: 43127930 },
hunter: { rank: 810, level: 99, xp: 37688883 },
construction: { rank: 92, level: 99, xp: 32005622 },
construction: { rank: 92, level: 99, xp: 32005622 }
},
leaguePoints: { rank: 23423, score: 478 },
bountyHunter: {
hunter: { rank: 99831, score: 23 },
rogue: { rank: 89912, score: 37 },
rogue: { rank: 89912, score: 37 }
},
lastManStanding: { rank: 4814, score: 898 },
soulWarsZeal: { rank: 37, score: 225 },
Expand All @@ -131,7 +131,7 @@ test('Parse CSV to json', () => {
medium: { rank: 127, score: 4259 },
hard: { rank: 361, score: 915 },
elite: { rank: 392, score: 250 },
master: { rank: 1, score: 6143 },
master: { rank: 1, score: 6143 }
},
bosses: {
abyssalSire: { rank: 382, score: 2780 },
Expand Down Expand Up @@ -178,17 +178,38 @@ test('Parse CSV to json', () => {
vorkath: { rank: 8623, score: 1340 },
wintertodt: { rank: 605, score: 1694 },
zalcano: { rank: -1, score: -1 },
zulrah: { rank: 3867, score: 4583 },
},
zulrah: { rank: 3867, score: 4583 }
}
};

expect(parseStats(csv)).toStrictEqual(expectedOutput);
});

test('Get name format', async () => {
jest.setTimeout(30000);
const data = await getRSNFormat('lYnX tiTaN');
expect(data).toBe('Lynx Titan');
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');
});
it('gets a name with an underscore', async () => {
jest.setTimeout(30000);
const data = await getRSNFormat('lYnX_tiTaN');
expect(data).toBe('Lynx Titan');
});
it('gets a name with a hyphen', async () => {
jest.setTimeout(30000);
const data = await getRSNFormat('lYnX-tiTaN');
expect(data).toBe('Lynx Titan');
});
it('gets a name with a number', async () => {
jest.setTimeout(30000);
const data = await getRSNFormat('B0ATY');
expect(data).toBe('B0aty');
});
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 () => {
Expand All @@ -200,176 +221,176 @@ test('Get attack top page', async () => {
rank: 1,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 2,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{ name: 'Drakon', rank: 3, level: 99, xp: 200000000, dead: false },
{
name: expect.any(String),
rank: 4,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 5,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 6,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 7,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 8,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 9,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 10,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 11,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 12,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 13,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 14,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 15,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 16,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 17,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 18,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 19,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 20,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 21,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 22,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 23,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 24,
level: 99,
xp: 200000000,
dead: false,
dead: false
},
{
name: expect.any(String),
rank: 25,
level: 99,
xp: 200000000,
dead: false,
},
dead: false
}
]);
});

test('Get non-existant player', async () => {
jest.setTimeout(30000);
getStats('fishy').catch(err => {
getStats('fishy').catch((err) => {
if (err.response) {
expect(err.response.status).toBe(404);
}
Expand Down Expand Up @@ -403,6 +424,6 @@ test('Get stats by gamemode', async () => {
farming: { rank: expect.any(Number), level: 99, xp: 200000000 },
runecraft: { 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 }
});
});
2 changes: 1 addition & 1 deletion src/hiscores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
export async function getRSNFormat(rsn: string): Promise<string> {
if (typeof rsn !== 'string') {
throw Error('RSN must be a string');
} else if (!/^[a-zA-Z0-9 _]+$/.test(rsn)) {
} else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
throw Error('RSN contains invalid character');
} else if (rsn.length > 12 || rsn.length < 1) {
throw Error('RSN must be between 1 and 12 characters');
Expand Down

0 comments on commit a406502

Please sign in to comment.