Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Remove node fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Sep 8, 2024
1 parent 0b9f9cd commit d8fdf8b
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 237 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"dependencies": {
"farming-weight": "^0.4.15",
"node-cache": "^5.1.2",
"node-fetch": "^3.3.2",
"prismarine-nbt": "^2.5.0",
"rss-parser": "^3.13.0",
"skyhelper-networth": "^1.24.0"
Expand Down
48 changes: 0 additions & 48 deletions pnpm-lock.yaml

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

28 changes: 16 additions & 12 deletions src/API/getLeaderboards.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Client from '../Client';
import Leaderboard from '../structures/Leaderboard';
import { expect, expectTypeOf, test } from 'vitest';
import { defaultRequestData } from '../../vitest.setup';
import { expect, expectTypeOf, test, vi } from 'vitest';

test('getLeaderboards (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
Expand Down Expand Up @@ -47,14 +48,17 @@ test('getLeaderboards', async () => {
client.destroy();
});

// test('getLeaderboards (Missing Data)', () => {
// const client = new Client(process.env.HYPIXEL_KEY ?? '');
// vi.spyOn(axios, 'get').mockResolvedValue({ status: 200, data: { success: true } });
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// // @ts-expect-error
// expect(() => client.getLeaderboards()).rejects.toThrowError(
// client.errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.')
// );
// vi.restoreAllMocks();
// client.destroy();
// });
test('getLeaderboards (Missing Data)', () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '');
vi.spyOn(global, 'fetch').mockResolvedValue({
...defaultRequestData,
json: () => Promise.resolve({ success: true })
} as any);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(() => client.getLeaderboards()).rejects.toThrowError(
client.errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.')
);
vi.restoreAllMocks();
client.destroy();
});
28 changes: 16 additions & 12 deletions src/API/getPlayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ import VampireZ from '../structures/MiniGames/VampireZ';
import Walls from '../structures/MiniGames/Walls';
import Warlords from '../structures/MiniGames/Warlords';
import WoolGames from '../structures/MiniGames/WoolGames';
import { expect, expectTypeOf, test } from 'vitest';
import { defaultRequestData } from '../../vitest.setup';
import { expect, expectTypeOf, test, vi } from 'vitest';

// test('getPlayer (never joinned hypixel)', async () => {
// const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// vi.spyOn(axios, 'get').mockResolvedValue({ status: 200, data: { success: true } });
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// // @ts-expect-error
// await expect(() => client.getPlayer('14727faefbdc4aff848cd2713eb9939e')).rejects.toThrowError(
// client.errors.PLAYER_HAS_NEVER_LOGGED
// );
// vi.restoreAllMocks();
// client.destroy();
// });
test('getPlayer (never joinned hypixel)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
vi.spyOn(global, 'fetch').mockResolvedValue({
...defaultRequestData,
json: () => Promise.resolve({ success: true })
} as any);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
await expect(() => client.getPlayer('14727faefbdc4aff848cd2713eb9939e')).rejects.toThrowError(
client.errors.PLAYER_HAS_NEVER_LOGGED
);
vi.restoreAllMocks();
client.destroy();
});

test('getPlayer (no input)', () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockAuctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ test('getSkyblockAuctions (One Page Include Item Bytes)', async () => {
client.destroy();
});

test('getSkyblockAuctions (All Pages)', async () => {
test.skip('getSkyblockAuctions (All Pages)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand Down
89 changes: 46 additions & 43 deletions src/API/getSkyblockFireSales.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Client from '../Client';
import { expect, expectTypeOf, test } from 'vitest';
import FireSale from '../structures/SkyBlock/Static/FireSale';
import { defaultRequestData } from '../../vitest.setup';
import { expect, expectTypeOf, test, vi } from 'vitest';

test('getSkyblockFireSales (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
Expand All @@ -11,45 +13,46 @@ test('getSkyblockFireSales (raw)', async () => {
client.destroy();
});

// test('getSkyblockFireSales', async () => {
// const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// vi.spyOn(axios, 'get').mockResolvedValue({
// status: 200,
// data: {
// success: true,
// sales: [
// { item_id: 'PET_SKIN_LION_WHITE', start: 1725120000000, end: 1725552000000, amount: 6500, price: 650 },
// { item_id: 'PET_SKIN_LION_BLACK', start: 1725120000000, end: 1725552000000, amount: 6500, price: 650 }
// ]
// }
// });
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// // @ts-expect-error
// const data = await client.getSkyblockFireSales();
// expect(data).toBeDefined();
// expectTypeOf(data).toEqualTypeOf<FireSale[]>();
// data.forEach((firesale: FireSale) => {
// expect(firesale).toBeDefined();
// expect(firesale).toBeInstanceOf(FireSale);
// expectTypeOf(firesale).toEqualTypeOf<FireSale>();
// expect(firesale.itemId).toBeDefined();
// expectTypeOf(firesale.itemId).toEqualTypeOf<string>();
// expect(firesale.startTimestamp).toBeDefined();
// expect(firesale.startTimestamp).toBeGreaterThanOrEqual(0);
// expectTypeOf(firesale.startTimestamp).toEqualTypeOf<number>();
// expect(firesale.startAt).toBeDefined();
// expectTypeOf(firesale.startAt).toEqualTypeOf<Date>();
// expect(firesale.endTimestamp).toBeDefined();
// expectTypeOf(firesale.endTimestamp).toEqualTypeOf<number>();
// expect(firesale.endTimestamp).toBeGreaterThanOrEqual(0);
// expect(firesale.endAt).toBeDefined();
// expectTypeOf(firesale.endAt).toEqualTypeOf<Date>();
// expect(firesale.amount).toBeDefined();
// expectTypeOf(firesale.amount).toEqualTypeOf<number>();
// expect(firesale.amount).toBeGreaterThanOrEqual(0);
// expect(firesale.toString()).toBeDefined();
// expectTypeOf(firesale.toString()).toEqualTypeOf<string>();
// expect(firesale.toString()).toBe(firesale.itemId);
// });
// client.destroy();
// });
test('getSkyblockFireSales', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
vi.spyOn(global, 'fetch').mockResolvedValue({
...defaultRequestData,
json: () =>
Promise.resolve({
success: true,
sales: [
{ item_id: 'PET_SKIN_LION_WHITE', start: 1725120000000, end: 1725552000000, amount: 6500, price: 650 },

Check warning on line 24 in src/API/getSkyblockFireSales.test.ts

View workflow job for this annotation

GitHub Actions / check linting (eslint)

Identifier 'item_id' is not in camel case
{ item_id: 'PET_SKIN_LION_BLACK', start: 1725120000000, end: 1725552000000, amount: 6500, price: 650 }

Check warning on line 25 in src/API/getSkyblockFireSales.test.ts

View workflow job for this annotation

GitHub Actions / check linting (eslint)

Identifier 'item_id' is not in camel case
]
})
} as any);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getSkyblockFireSales();
expect(data).toBeDefined();
expectTypeOf(data).toEqualTypeOf<FireSale[]>();
data.forEach((firesale: FireSale) => {
expect(firesale).toBeDefined();
expect(firesale).toBeInstanceOf(FireSale);
expectTypeOf(firesale).toEqualTypeOf<FireSale>();
expect(firesale.itemId).toBeDefined();
expectTypeOf(firesale.itemId).toEqualTypeOf<string>();
expect(firesale.startTimestamp).toBeDefined();
expect(firesale.startTimestamp).toBeGreaterThanOrEqual(0);
expectTypeOf(firesale.startTimestamp).toEqualTypeOf<number>();
expect(firesale.startAt).toBeDefined();
expectTypeOf(firesale.startAt).toEqualTypeOf<Date>();
expect(firesale.endTimestamp).toBeDefined();
expectTypeOf(firesale.endTimestamp).toEqualTypeOf<number>();
expect(firesale.endTimestamp).toBeGreaterThanOrEqual(0);
expect(firesale.endAt).toBeDefined();
expectTypeOf(firesale.endAt).toEqualTypeOf<Date>();
expect(firesale.amount).toBeDefined();
expectTypeOf(firesale.amount).toEqualTypeOf<number>();
expect(firesale.amount).toBeGreaterThanOrEqual(0);
expect(firesale.toString()).toBeDefined();
expectTypeOf(firesale.toString()).toEqualTypeOf<string>();
expect(firesale.toString()).toBe(firesale.itemId);
});
client.destroy();
});
1 change: 0 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Client {
if (found) {
this.destroy();
Object.assign(this, found);
return;
}
return;
}
Expand Down
53 changes: 28 additions & 25 deletions src/Private/RateLimit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Client from '../Client';
import RateLimit from './RateLimit';
import { expect, expectTypeOf, test } from 'vitest';
import { defaultRequestData } from '../../vitest.setup';
import { expect, expectTypeOf, test, vi } from 'vitest';

test('RateLimit (None)', () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { rateLimit: 'NONE' });
Expand Down Expand Up @@ -63,27 +64,29 @@ test('RateLimit (Auto)', async () => {
client.destroy();
});

// test('Ratelimit (Sync)', async () => {
// const client = new Client(process.env.HYPIXEL_KEY ?? '');
// client.updater.currentVersion = '1.0.0';
// vi.spyOn(axios, 'get').mockResolvedValue({
// status: 200,
// data: { success: true },
// headers: { 'ratelimit-limit': 30, 'ratelimit-remaining': 27 }
// });
// expect(() => client.rateLimit.sync()).not.toThrowError();
// await client.rateLimit.sync();
// expect(client.rateLimit.requests).toBe(3);
// expect(client.rateLimit.limit).toBe(30);
// vi.restoreAllMocks();
// client.destroy();
// });

// test('Ratelimit (Bad Sync Data)', () => {
// const client = new Client(process.env.HYPIXEL_KEY ?? '');
// client.updater.currentVersion = '1.0.0';
// vi.spyOn(axios, 'get').mockResolvedValue({ status: 200, data: { success: true }, headers: { hello: 100 } });
// expect(() => client.rateLimit.sync()).rejects.toThrowError(client.errors.RATE_LIMIT_INIT_ERROR);
// vi.restoreAllMocks();
// client.destroy();
// });
test('Ratelimit (Sync)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '');
client.updater.currentVersion = '1.0.0';
vi.spyOn(global, 'fetch').mockResolvedValue({
...defaultRequestData,
headers: new Headers({ 'ratelimit-limit': '30', 'ratelimit-remaining': '27' })
} as any);
expect(() => client.rateLimit.sync()).not.toThrowError();
await client.rateLimit.sync();
expect(client.rateLimit.requests).toBe(3);
expect(client.rateLimit.limit).toBe(30);
vi.restoreAllMocks();
client.destroy();
});

test('Ratelimit (Bad Sync Data)', () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '');
client.updater.currentVersion = '1.0.0';
vi.spyOn(global, 'fetch').mockResolvedValue({
...defaultRequestData,
headers: new Headers({ hello: '100' })
} as any);
expect(() => client.rateLimit.sync()).rejects.toThrowError(client.errors.RATE_LIMIT_INIT_ERROR);
vi.restoreAllMocks();
client.destroy();
});
Loading

0 comments on commit d8fdf8b

Please sign in to comment.