Files
huskies/frontend/src/api/rpcContract.test.ts
T
2026-05-13 07:14:50 +00:00

30 lines
1.1 KiB
TypeScript

/**
* Snapshot test: the frontend `CONTRACT_FIXTURES` table must match the
* Rust-side snapshot. When the Rust contract changes, the snapshot file
* regenerates (via `UPDATE_RPC_CONTRACT_SNAPSHOT=1 cargo test`) and this
* test catches any TS shapes that have drifted.
*/
import { describe, expect, it } from "vitest";
import { CONTRACT_FIXTURES } from "./rpcContract";
import snapshot from "./rpcContract.snapshot.json";
describe("rpcContract", () => {
it("CONTRACT_FIXTURES matches the Rust-generated snapshot", () => {
// Convert TS fixtures into the same shape the Rust snapshot serialises
// to: a method-keyed object of `{ params, result }`.
const fromTs = Object.fromEntries(
Object.entries(CONTRACT_FIXTURES).map(([method, payloads]) => [
method,
{ params: payloads.params, result: payloads.result },
]),
);
expect(fromTs).toEqual(snapshot);
});
it("declares the same method names as the snapshot", () => {
const tsMethods = Object.keys(CONTRACT_FIXTURES).sort();
const rustMethods = Object.keys(snapshot).sort();
expect(tsMethods).toEqual(rustMethods);
});
});