RESTfulMC/JS-SDK/test/index.test.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-04-15 04:16:06 -07:00
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";
2024-04-15 04:16:06 -07:00
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.");
}
}
});
});
2024-04-15 04:16:06 -07:00
describe("server", () => {
it("java", async () => {
const server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer =
await getMinecraftServer("java", "play.wildnetwork.net");
console.log(server.ip);
});
});
2024-04-15 04:16:06 -07:00
describe("mojang", () => {
it("status", async () => {
const status: MojangServerStatus = await getMojangServerStatus();
console.log(status["https://sessionserver.mojang.com"]);
});
});