test: add widget config tests (batch 1)

This commit is contained in:
shamoon
2026-02-04 09:39:43 -08:00
parent 4c3d39709b
commit d29854f710
11 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { expect } from "vitest";
export function expectWidgetConfigShape(widget) {
expect(widget).toBeTruthy();
expect(widget).toBeTypeOf("object");
if ("api" in widget) {
expect(widget.api).toBeTypeOf("string");
// Widget APIs are template strings that expand to a configured service URL.
expect(widget.api).toContain("{url}");
}
if ("proxyHandler" in widget) {
expect(widget.proxyHandler).toBeTypeOf("function");
}
if ("allowedEndpoints" in widget) {
expect(widget.allowedEndpoints).toBeInstanceOf(RegExp);
}
if ("mappings" in widget) {
expect(widget.mappings).toBeTruthy();
expect(widget.mappings).toBeTypeOf("object");
for (const [name, mapping] of Object.entries(widget.mappings)) {
expect(name).toBeTruthy();
expect(mapping).toBeTruthy();
expect(mapping).toBeTypeOf("object");
if ("endpoint" in mapping) {
expect(mapping.endpoint).toBeTypeOf("string");
expect(mapping.endpoint.length).toBeGreaterThan(0);
}
if ("map" in mapping) {
expect(mapping.map).toBeTypeOf("function");
}
}
}
}