Skip to content

Commit

Permalink
fix getSkyblockProfiles bug (qol 🤷‍♂️ ) (#439)
Browse files Browse the repository at this point in the history
* fix getSkyblockProfiles bug

* remove my key again >:)

* Better Error Throwing

* Added Missing info & Fix uuid

---------

Co-authored-by: Kath <[email protected]>
  • Loading branch information
Zickles and Kathund authored Feb 18, 2024
1 parent 71e70d3 commit b90a1e2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/API/skyblock/getSkyblockMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module.exports = async function (query, options = { fetchPlayer: false }) {
query = await toUuid(query);
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
if (res.raw) return res;
if (!res.profiles || !res.profiles.length) {
return new Map();
}
if (!res.profiles || !res.profiles.length) throw new Error(Errors.NO_SKYBLOCK_PROFILES);
const player = options.fetchPlayer ? await getPlayer.call(this, query, options) : null;
const memberByProfileName = new Map();
for (const profile of res.profiles) {
Expand Down
6 changes: 1 addition & 5 deletions src/API/skyblock/getSkyblockProfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ module.exports = async function (query, options = { fetchPlayer: false }) {
query = await toUuid(query);
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
if (res.raw) return res;

if (!res.profiles || !res.profiles.length) {
return [];
}

if (!res.profiles || !res.profiles.length) throw new Error(Errors.NO_SKYBLOCK_PROFILES);
const players = new Map();
if (options.fetchPlayer) {
const uniqueUuids = [...new Set(res.profiles.map((profile) => Object.keys(profile.members)).flat())];
Expand Down
3 changes: 2 additions & 1 deletion src/Errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const {
Pets,
Pet,
Color,
WoolWars
WoolWars,
SkyblockMember
} = require('../src');
const client = new Client(process.env.HYPIXEL_KEY, { cache: true });
const { expect } = require('chai');
Expand Down Expand Up @@ -294,6 +295,47 @@ describe('Client#getSkyblockNews', async () => {
}
});
});
describe('Client#getSkyblockProfiles', async () => {
let profiles;
it('expect not to throw', async () => {
profiles = await client.getSkyblockProfiles('f025c1c7f55a4ea0b8d93f47d17dfe0f');
});
it('should be an array', () => {
expect(profiles).to.be.an('array');
});
it('required keys should exist', () => {
profiles.forEach((profile) => {
expect(profile.profileId).to.be.a('string');
expect(profile.profileName).to.be.oneOf([
'Apple',
'Banana',
'Blueberry',
'Coconut',
'Cucumber',
'Grapes',
'Kiwi',
'Lemon',
'Lime',
'Mango',
'Orange',
'Papaya',
'Pear',
'Peach',
'Pineapple',
'Pomegranate',
'Raspberry',
'Strawberry',
'Tomato',
'Watermelon',
'Zucchini'
]);
profile.members.forEach((profile) => {
expect(profile).instanceOf(SkyblockMember);
});
expect(profile.me).instanceOf(SkyblockMember);
});
});
});
describe('Client#getServerInfo', async () => {
let server;
it('expect not to throw', async () => {
Expand Down

0 comments on commit b90a1e2

Please sign in to comment.