49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import { describe, expect, it } from "vitest";
|
|
import type { Asset } from "@/lib/types";
|
|
|
|
type AssetsContract = {
|
|
version: number;
|
|
asset: Asset;
|
|
defaults: {
|
|
platformExternalName: string;
|
|
publicExternalName: string;
|
|
platformExternalTags: string[];
|
|
publicRequiredTags: string[];
|
|
platformRegisteredFrom: string;
|
|
publicRegisteredFrom: string;
|
|
};
|
|
publicVisibility: { jobLookupLimit: number; clientTagPrefix: string };
|
|
};
|
|
|
|
describe("assets v1 compatibility contract", () => {
|
|
it("freezes the TypeScript wire shape, defaults, and public visibility rule", async () => {
|
|
const contract = JSON.parse(await readFile(new URL("../contracts/assets/assets-v1.json", import.meta.url), "utf8")) as AssetsContract;
|
|
const asset: Asset = contract.asset;
|
|
|
|
expect(contract.version).toBe(1);
|
|
expect(asset).toEqual({
|
|
id: "asset-contract-1",
|
|
ownerId: "owner-1",
|
|
kind: "image",
|
|
name: "poster.png",
|
|
url: "https://cdn.example.test/uploads/poster.png",
|
|
storagePath: "uploads/2026-08-13/poster.png",
|
|
source: "upload",
|
|
tags: ["upload"],
|
|
metadata: { contentType: "image/png", size: 4 },
|
|
createdAt: "2026-08-13T08:00:00.000Z",
|
|
updatedAt: "2026-08-13T08:00:00.000Z"
|
|
});
|
|
expect(contract.defaults).toEqual({
|
|
platformExternalName: "外部图片",
|
|
publicExternalName: "外部素材",
|
|
platformExternalTags: ["external"],
|
|
publicRequiredTags: ["external", "public-api", "api-client:agent-a"],
|
|
platformRegisteredFrom: "api",
|
|
publicRegisteredFrom: "public-api"
|
|
});
|
|
expect(contract.publicVisibility).toEqual({ jobLookupLimit: 200, clientTagPrefix: "api-client:" });
|
|
});
|
|
});
|