From fbbb4e14833bd9c1fd0b2f17d879eeb300db84a3 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 15 Apr 2024 09:29:39 -0400 Subject: [PATCH] Do proper tests --- JS-SDK/package.json | 2 +- JS-SDK/test/index.test.ts | 35 ----------------------------- JS-SDK/test/player.test.ts | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 36 deletions(-) delete mode 100644 JS-SDK/test/index.test.ts create mode 100644 JS-SDK/test/player.test.ts diff --git a/JS-SDK/package.json b/JS-SDK/package.json index 8453b4b..d2b5061 100644 --- a/JS-SDK/package.json +++ b/JS-SDK/package.json @@ -1,6 +1,6 @@ { "name": "restfulmc-lib", - "version": "1.0.1", + "version": "1.0.2", "author": "Braydon (Rainnny) ", "description": "A simple, yet useful RESTful API for Minecraft utilizing Springboot.", "keywords": [ diff --git a/JS-SDK/test/index.test.ts b/JS-SDK/test/index.test.ts deleted file mode 100644 index f446d23..0000000 --- a/JS-SDK/test/index.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, it } from "bun:test"; -import { getMinecraftServer, getMojangServerStatus, getPlayer } from "../src"; -import { ErrorResponse } from "../src/types/generic"; -import { MojangServerStatus } from "../src/types/mojang"; -import { CachedPlayer } from "../src/types/player"; -import { CachedBedrockMinecraftServer } from "../src/types/server/bedrock-server"; -import { CachedJavaMinecraftServer } from "../src/types/server/java-server"; - -describe("player", () => { - it("Rainnny", async () => { - try { - const player: CachedPlayer = await getPlayer("Rainnny"); - console.log(`Hello ${player.username}, your UUID is ${player.uniqueId}!`); - } catch (err) { - if ((err as ErrorResponse).code == 404) { - console.error("Player with UUID or username not found."); - } - } - }); -}); - -describe("server", () => { - it("java", async () => { - const server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer = - await getMinecraftServer("java", "play.wildnetwork.net"); - console.log(server.ip); - }); -}); - -describe("mojang", () => { - it("status", async () => { - const status: MojangServerStatus = await getMojangServerStatus(); - console.log(status["https://sessionserver.mojang.com"]); - }); -}); diff --git a/JS-SDK/test/player.test.ts b/JS-SDK/test/player.test.ts new file mode 100644 index 0000000..1624b43 --- /dev/null +++ b/JS-SDK/test/player.test.ts @@ -0,0 +1,46 @@ +import { getPlayer, getSkinPart } from "@/index"; +import { ErrorResponse } from "@/types/generic"; +import { CachedPlayer, SkinPart } from "@/types/player"; +import { expect, test } from "bun:test"; + +/** + * Run a test to ensure retrieving + * a player's data is successful. + */ +test("ensurePlayerLookupSuccess", async () => { + const player: CachedPlayer = await getPlayer("Rainnny"); // Fetch the player + expect(player.username).toBe("Rainnny"); +}); + +/** + * Run a test to ensure retrieving an + * invalid player results in a 404. + */ +test("ensurePlayerNotFound", async () => { + try { + await getPlayer("SDFSDFSDFSDFDDDG"); // Fetch the unknown player + } catch (err) { + expect((err as ErrorResponse).code).toBe(404); + } +}); + +/** + * Run a test to ensure retrieving a player + * with an invalid username results in a 400. + */ +test("ensureUsernameIsInvalid", async () => { + try { + await getPlayer("A"); // Fetch the invalid player + } catch (err) { + expect((err as ErrorResponse).code).toBe(400); + } +}); + +/** + * Run a test to ensure retrieving a + * player's skin part texture is successful. + */ +test("ensureSkinPartTextureSuccess", async () => { + const partTexture: ArrayBuffer = await getSkinPart(SkinPart.HEAD, "Rainnny"); // Fetch the skin part + expect(partTexture.byteLength).toBeGreaterThan(0); +});