2 Commits

Author SHA1 Message Date
74a3305ddd Add server and Mojang tests
Some checks failed
Publish JS SDK / docker (push) Failing after 19s
2024-04-15 09:43:40 -04:00
3171346d4b Fix #isMojangBlocked not working 2024-04-15 09:40:19 -04:00
3 changed files with 92 additions and 1 deletions

View File

@ -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

View 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();
});

View 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);
});