import { describe, expect, it } from "vitest"; import { ColineApp, colineAppManifestSchema } from "./index"; describe("ColineApp", () => { it("validates manifest configuration", () => { const manifest = colineAppManifestSchema.parse({ key: "com.coline.notes", name: "Notes", permissions: ["app.home.read", "files.write", "index.write"], hosting: { mode: "external", baseUrl: "https://notes.example.com", }, }); expect(manifest.hosting.baseUrl).toBe("https://notes.example.com"); }); it("registers file types and handlers in the app definition", () => { const app = new ColineApp({ key: "com.coline.notes", name: "Notes", permissions: ["app.home.read", "files.read", "files.write"], hosting: { mode: "external", baseUrl: "https://notes.example.com", }, }) .defineFileType({ typeKey: "com.coline.notes.note", name: "Note", storage: "coline_document", }) .onHomeRender(async () => ({ type: "Text", props: { value: "Notes" } })) .onIndexSync(() => []); const definition = app.getDefinition(); expect(definition.fileTypes).toHaveLength(1); expect(definition.fileTypes[0]?.typeKey).toBe("com.coline.notes.note"); expect(typeof definition.handlers.homeRender).toBe("function"); expect(typeof definition.handlers.indexSync).toBe("function"); }); it("builds a typed registration payload for API submission", () => { const app = new ColineApp({ key: "com.coline.notes", name: "Notes", permissions: ["app.home.read"], hosting: { mode: "external", baseUrl: "https://notes.example.com", }, }).defineFileType({ typeKey: "com.coline.notes.note", name: "Note", storage: "coline_document", }); const payload = app.getRegistrationPayload("0.1.0"); expect(payload.version).toBe("0.1.0"); expect(payload.manifest.key).toBe("com.coline.notes"); expect(payload.fileTypes[0]?.homeRenderMode).toBe("cached"); }); it("rejects invalid external hosting urls", () => { expect(() => { new ColineApp({ key: "com.coline.invalid", name: "Invalid", permissions: [], hosting: { mode: "external", baseUrl: "not-a-url", }, }); }).toThrow(); }); });