Full configuration export/import system for Homarr with excellent DX: - Export/import boards, apps, integrations (with re-encrypted secrets), users (with bcrypt hashes), groups (with permissions and memberships), search engines, and server settings - Homepage services.yaml import with widget-type mapping - Generic resolveEntities() utility eliminates per-entity boilerplate - Declarative entity-fields.ts: adding a new user preference requires only one line change (no export/import/schema edits needed) - User schema uses .catchall(z.unknown()) for forward-compatible prefs - groupByKey() utility replaces manual Map-building - CONFIG_ENTITY_KEYS as single source of truth for entity metadata - Reuse existing entities (apps by name+icon+href, integrations by kind+name+url, users by email, groups by name, boards by name) - Skip duplicates with warnings rather than failing - Onboarding flow skips user creation step when config includes users - Reuse existing admin group during onboarding after config import
112 lines
3.1 KiB
TypeScript
112 lines
3.1 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
|
|
import { parseServicesYaml } from "./parse-services-yaml";
|
|
|
|
const sampleYaml = `
|
|
- Media:
|
|
- Sonarr:
|
|
icon: sonarr.png
|
|
href: http://sonarr.host/
|
|
description: Series management
|
|
ping: sonarr.host
|
|
widget:
|
|
type: sonarr
|
|
url: http://sonarr.host
|
|
key: apikeyhere
|
|
- Radarr:
|
|
icon: radarr.png
|
|
href: http://radarr.host/
|
|
widgets:
|
|
- type: radarr
|
|
url: http://radarr.host
|
|
key: radarrkey
|
|
- Downloads:
|
|
- qBittorrent:
|
|
icon: qbittorrent.png
|
|
href: http://qbit.host/
|
|
widget:
|
|
type: qbittorrent
|
|
url: http://qbit.host
|
|
username: admin
|
|
password: pass123
|
|
`;
|
|
|
|
describe("parseServicesYaml", () => {
|
|
test("parses groups, services, singular widget, and plural widgets", () => {
|
|
const result = parseServicesYaml(sampleYaml);
|
|
expect(result.success).toBe(true);
|
|
if (!result.success) {
|
|
return;
|
|
}
|
|
|
|
expect(result.services).toHaveLength(3);
|
|
|
|
const sonarr = result.services.find((service) => service.name === "Sonarr");
|
|
expect(sonarr).toMatchObject({
|
|
group: "Media",
|
|
href: "http://sonarr.host/",
|
|
ping: "sonarr.host",
|
|
});
|
|
expect(sonarr?.widgets).toHaveLength(1);
|
|
expect(sonarr?.widgets[0]).toMatchObject({ type: "sonarr", key: "apikeyhere" });
|
|
|
|
const radarr = result.services.find((service) => service.name === "Radarr");
|
|
expect(radarr?.widgets).toHaveLength(1);
|
|
expect(radarr?.widgets[0]?.type).toBe("radarr");
|
|
|
|
const qbit = result.services.find((service) => service.name === "qBittorrent");
|
|
expect(qbit?.group).toBe("Downloads");
|
|
expect(qbit?.widgets[0]).toMatchObject({ type: "qbittorrent", fields: { username: "admin" } });
|
|
});
|
|
|
|
test("flattens nested groups with separator", () => {
|
|
const yaml = `
|
|
- Parent:
|
|
- Child:
|
|
- Service:
|
|
href: http://service.local
|
|
`;
|
|
const result = parseServicesYaml(yaml);
|
|
expect(result.success).toBe(true);
|
|
if (!result.success) {
|
|
return;
|
|
}
|
|
|
|
expect(result.services[0]?.group).toBe("Parent / Child");
|
|
expect(result.services[0]?.name).toBe("Service");
|
|
});
|
|
|
|
test("parses services without widgets", () => {
|
|
const yaml = `
|
|
- Tools:
|
|
- Homepage:
|
|
href: http://homepage.local
|
|
`;
|
|
const result = parseServicesYaml(yaml);
|
|
expect(result.success).toBe(true);
|
|
if (!result.success) {
|
|
return;
|
|
}
|
|
|
|
expect(result.services[0]?.widgets).toEqual([]);
|
|
});
|
|
|
|
test("returns empty services for empty content", () => {
|
|
expect(parseServicesYaml(" ")).toEqual({ success: true, services: [] });
|
|
});
|
|
|
|
test("handles malformed yaml gracefully", () => {
|
|
const result = parseServicesYaml("invalid: yaml: [");
|
|
expect(result.success).toBe(false);
|
|
if (result.success) {
|
|
return;
|
|
}
|
|
expect(result.error).toBe("Invalid YAML");
|
|
});
|
|
|
|
test("rejects non-array root documents", () => {
|
|
const result = parseServicesYaml("name: not-an-array");
|
|
expect(result).toEqual({ success: false, error: "Homepage services.yaml must be a YAML array" });
|
|
});
|
|
});
|