Compare commits
2 Commits
fbbb4e1483
...
74a3305ddd
Author | SHA1 | Date | |
---|---|---|---|
74a3305ddd | |||
3171346d4b |
@ -61,7 +61,9 @@ export const getMinecraftServer = (
|
||||
* @returns the promised blocked status
|
||||
*/
|
||||
export const isMojangBlocked = (hostname: string): Promise<boolean> =>
|
||||
new WebRequest(`/server/blocked/${hostname}`).execute<boolean>();
|
||||
new WebRequest(`/server/blocked/${hostname}`).execute<{
|
||||
blocked: boolean;
|
||||
}>().then((res) => res.blocked);
|
||||
|
||||
/**
|
||||
* Get the icon of the Java Minecraft
|
||||
|
13
JS-SDK/test/mojang.test.ts
Normal file
13
JS-SDK/test/mojang.test.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { getMojangServerStatus } from "@/index";
|
||||
import { MojangServerStatus } from "@/types/mojang";
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
/**
|
||||
* Run a test to ensure retrieving
|
||||
* the status of Mojang servers is
|
||||
* successful.
|
||||
*/
|
||||
test("ensureServerStatusCheckSuccess", async () => {
|
||||
const status: MojangServerStatus = await getMojangServerStatus(); // Get Mojang service status
|
||||
expect(status).toBeDefined();
|
||||
});
|
76
JS-SDK/test/server.test.ts
Normal file
76
JS-SDK/test/server.test.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import {
|
||||
getJavaServerFavicon,
|
||||
getMinecraftServer,
|
||||
isMojangBlocked,
|
||||
} from "@/index";
|
||||
import { ErrorResponse } from "@/types/generic";
|
||||
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
||||
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
||||
import { ServerPlatform } from "@/types/server/server";
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
/**
|
||||
* Run a test to ensure retrieving a
|
||||
* Java server's status is successful.
|
||||
*/
|
||||
test("ensureJavaServerLookupSuccess", async () => {
|
||||
const server: CachedJavaMinecraftServer = (await getMinecraftServer(
|
||||
ServerPlatform.JAVA,
|
||||
"hypixel.net"
|
||||
)) as CachedJavaMinecraftServer; // Fetch the Java server
|
||||
expect(server.hostname).toBe("mc.hypixel.net");
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a test to ensure retrieving a
|
||||
* Bedrock server's status is successful.
|
||||
*/
|
||||
test("ensureBedrockServerLookupSuccess", async () => {
|
||||
const server: CachedBedrockMinecraftServer = (await getMinecraftServer(
|
||||
ServerPlatform.BEDROCK,
|
||||
"wildprison.bedrock.minehut.gg"
|
||||
)) as CachedBedrockMinecraftServer; // Fetch the Bedrock server
|
||||
expect(server.hostname).toBe("wildprison.bedrock.minehut.gg");
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a test to ensure looking up an
|
||||
* invalid hostname results in a 400.
|
||||
*/
|
||||
test("ensureUnknownHostname", async () => {
|
||||
try {
|
||||
await getMinecraftServer(ServerPlatform.JAVA, "invalid"); // Fetch the unknown server
|
||||
} catch (err) {
|
||||
expect((err as ErrorResponse).code).toBe(400);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a test to ensure looking up an
|
||||
* invalid port results in a 400.
|
||||
*/
|
||||
test("ensureUnknownPort", async () => {
|
||||
try {
|
||||
await getMinecraftServer(ServerPlatform.JAVA, "hypixel.net:A"); // Fetch the invalid server
|
||||
} catch (err) {
|
||||
expect((err as ErrorResponse).code).toBe(400);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a test to ensure checking if
|
||||
* a server is blocked is successful.
|
||||
*/
|
||||
test("ensureServerBanCheckSuccess", async () => {
|
||||
const blocked: boolean = await isMojangBlocked("arkhamnetwork.org"); // Check if the server is blocked
|
||||
expect(blocked).toBe(true);
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a test to ensure retrieving a
|
||||
* Java server's favicon is successful.
|
||||
*/
|
||||
test("ensureServerFaviconSuccess", async () => {
|
||||
const faviconTexture: ArrayBuffer = await getJavaServerFavicon("hypixel.net"); // Get the Java server's favicon
|
||||
expect(faviconTexture.byteLength).toBeGreaterThan(0);
|
||||
});
|
Reference in New Issue
Block a user