import assert from "node:assert/strict" import test from "node:test" import { collaborationConfig } from "../src/modules/collaboration/config" const deployment = { API_BASE_URL: "https://fedeo.example/backend", ENCRYPTION_KEY: "a".repeat(64) } test("existing HTTPS deployment enables federation without additional environment values", () => { const config = collaborationConfig(deployment) assert.equal(config.enabled, true) assert.equal(config.apiUrl, deployment.API_BASE_URL) assert.equal(config.publicUrl, "https://fedeo.example") assert.equal(config.disabledReason, undefined) assert.equal(collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "auto", FEDEO_FEDERATION_URL: "", FEDEO_PUBLIC_URL: "" }).enabled, true) }) test("custom API paths are retained and instance addresses are canonicalized", () => { const config = collaborationConfig({ ...deployment, API_BASE_URL: "https://FEDEO.example:443/application/api/" }) assert.equal(config.apiUrl, "https://fedeo.example/application/api") assert.equal(config.publicUrl, "https://fedeo.example") assert.equal(config.enabled, true) }) test("explicit opt-out stays disabled even on a correctly configured deployment", () => { const config = collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "false" }) assert.equal(config.enabled, false) assert.match(config.disabledReason!, /Betreiber deaktiviert/) }) test("optional gateway override does not move guest links away from the web application", () => { const config = collaborationConfig({ ...deployment, FEDEO_FEDERATION_URL: "https://gateway.example/federation-api/" }) assert.equal(config.apiUrl, "https://gateway.example/federation-api") assert.equal(config.publicUrl, "https://fedeo.example") assert.equal(collaborationConfig({ ...deployment, FEDEO_PUBLIC_URL: "https://portal.example/app/" }).publicUrl, "https://portal.example/app") }) test("local and incomplete deployments keep local collaboration available without federation", () => { for (const API_BASE_URL of [undefined, "", "invalid", "http://localhost:3100", "https://fedeo.example:8443/backend", "https://user:password@fedeo.example/backend"]) { const config = collaborationConfig({ ...deployment, API_BASE_URL }) assert.equal(config.enabled, false, API_BASE_URL) assert.match(config.disabledReason!, /HTTPS-API_BASE_URL/) } for (const ENCRYPTION_KEY of [undefined, "", "invalid", "x".repeat(64)]) { const config = collaborationConfig({ ...deployment, ENCRYPTION_KEY }) assert.equal(config.enabled, false) assert.match(config.disabledReason!, /ENCRYPTION_KEY/) } }) test("forced activation reports invalid configuration instead of silently ignoring it", () => { assert.throws(() => collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "true", API_BASE_URL: "http://localhost" }), /HTTPS/) assert.throws(() => collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "true", ENCRYPTION_KEY: "invalid" }), /ENCRYPTION_KEY/) assert.throws(() => collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "typo" }), /auto, true oder false/) assert.equal(collaborationConfig({ ...deployment, FEDEO_FEDERATION_ENABLED: "true" }).enabled, true) })