From b90a1e277e7041f58e39fdc542bcebda78069b9d Mon Sep 17 00:00:00 2001 From: Zachary Jaser <76439587+Zickles@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:04:46 -0500 Subject: [PATCH] fix getSkyblockProfiles bug (qol :man_shrugging: ) (#439) * fix getSkyblockProfiles bug * remove my key again >:) * Better Error Throwing * Added Missing info & Fix uuid --------- Co-authored-by: Kath <55346310+Kathund@users.noreply.github.com> --- src/API/skyblock/getSkyblockMember.js | 4 +-- src/API/skyblock/getSkyblockProfiles.js | 6 +--- src/Errors.js | 3 +- tests/test.js | 44 ++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/API/skyblock/getSkyblockMember.js b/src/API/skyblock/getSkyblockMember.js index 6d3473eb..c3ae77de 100644 --- a/src/API/skyblock/getSkyblockMember.js +++ b/src/API/skyblock/getSkyblockMember.js @@ -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) { diff --git a/src/API/skyblock/getSkyblockProfiles.js b/src/API/skyblock/getSkyblockProfiles.js index 0eca0632..066f12f1 100644 --- a/src/API/skyblock/getSkyblockProfiles.js +++ b/src/API/skyblock/getSkyblockProfiles.js @@ -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())]; diff --git a/src/Errors.js b/src/Errors.js index f1a6ece0..df287dec 100644 --- a/src/Errors.js +++ b/src/Errors.js @@ -40,5 +40,6 @@ module.exports = { UNEXPECTED_ERROR: "[hypixel-api-reborn] The data provided to hypixel API is malformed and thus not recognized by hypixel, but this shouldn't be your fault. Please report this error in our Discord Server https://discord.gg/NSEBNMM or GitHub. ", RATE_LIMIT_EXCEEDED: - "[hypixel-api-reborn] The rate limitations on your API Key has been exceeded. There might be an outage (Check Hypixel's status page), or you simply did too many requests in a short time. Hint: Enable rate limit options! They can help you avoid this error! For help join our Discord Server https://discord.gg/NSEBNMM" + "[hypixel-api-reborn] The rate limitations on your API Key has been exceeded. There might be an outage (Check Hypixel's status page), or you simply did too many requests in a short time. Hint: Enable rate limit options! They can help you avoid this error! For help join our Discord Server https://discord.gg/NSEBNMM", + NO_SKYBLOCK_PROFILES: '[hypixel-api-reborn] The player has no skyblock profiles.' }; diff --git a/tests/test.js b/tests/test.js index 210a5420..32c3561f 100644 --- a/tests/test.js +++ b/tests/test.js @@ -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'); @@ -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 () => {