Files
minecraft-account-manager/packages/contracts/test/contracts.test.ts
T

52 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
cloudEventSchema,
velocityAccessRequestSchema,
velocityAccessResponseSchema,
} from "../src/index";
describe("shared service contracts", () => {
it("accepts a game login event in CloudEvents format", () => {
const event = cloudEventSchema.parse({
id: "8cf5b035-4368-4fa8-b9bb-2835da752f20",
specversion: "1.0",
source: "/velocity/main",
type: "games.minecraft.account-manager.game.login.allowed",
subject: "minecraft-account/8667ba71b85a4004af54457a9734eed7",
time: "2026-03-06T12:00:00.000Z",
datacontenttype: "application/json",
data: { username: "Notch" },
});
expect(event.specversion).toBe("1.0");
});
it("requires Velocity to send a Java UUID, username, and IP address", () => {
const request = velocityAccessRequestSchema.parse({
requestId: "6f1fd065-5298-42fa-b1ad-87a8916c6a8a",
serverId: "velocity-main",
minecraftUuid: "069a79f444e94726a5befca90e38aaf5",
username: "Notch",
ipAddress: "203.0.113.10",
occurredAt: "2026-03-06T12:00:00.000Z",
});
expect(request.username).toBe("Notch");
expect(() =>
velocityAccessRequestSchema.parse({ ...request, minecraftUuid: "not-a-uuid" }),
).toThrow();
});
it("only returns explicit allow or deny decisions to Velocity", () => {
expect(
velocityAccessResponseSchema.parse({
allowed: false,
message: "Please register your Minecraft account before joining.",
}),
).toEqual({
allowed: false,
message: "Please register your Minecraft account before joining.",
});
});
});