100 lines
3.2 KiB
TypeScript
100 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { loadBrandFromEnv } from "./env.js";
|
|
import { createBrandTokens, defaultBrandTokens } from "./index.js";
|
|
|
|
describe("loadBrandFromEnv", () => {
|
|
it("returns no overrides when env is empty", () => {
|
|
expect(loadBrandFromEnv({})).toEqual({});
|
|
});
|
|
|
|
it("treats whitespace-only env values as absent", () => {
|
|
expect(
|
|
loadBrandFromEnv({
|
|
BRAND_PRODUCT_NAME: " ",
|
|
BRAND_SITE_URL: "",
|
|
BRAND_SUPPORT_EMAIL: "\n",
|
|
BRAND_LEGAL_PRIVACY_URL: "\t",
|
|
BRAND_LOGO_URL: " ",
|
|
BRAND_MAIL_PRIMARY: " ",
|
|
})
|
|
).toEqual({});
|
|
});
|
|
|
|
it("extracts product name and site URL when provided", () => {
|
|
expect(
|
|
loadBrandFromEnv({
|
|
BRAND_PRODUCT_NAME: "Acme Ops",
|
|
BRAND_SITE_URL: "https://acme.test",
|
|
})
|
|
).toEqual({
|
|
productName: "Acme Ops",
|
|
siteUrl: "https://acme.test",
|
|
});
|
|
});
|
|
|
|
it("groups support, legal, assets and mail color overrides", () => {
|
|
expect(
|
|
loadBrandFromEnv({
|
|
BRAND_SUPPORT_EMAIL: "help@acme.test",
|
|
BRAND_SUPPORT_FROM_NAME: "Acme Help",
|
|
BRAND_LEGAL_IMPRINT_URL: "https://acme.test/imprint",
|
|
BRAND_LEGAL_PRIVACY_URL: "https://acme.test/privacy",
|
|
BRAND_LEGAL_TERMS_URL: "https://acme.test/terms",
|
|
BRAND_LOGO_URL: "https://cdn.acme.test/logo.svg",
|
|
BRAND_FAVICON_URL: "https://cdn.acme.test/favicon.ico",
|
|
BRAND_MAIL_PRIMARY: "#0f766e",
|
|
BRAND_MAIL_PRIMARY_TEXT: "#ffffff",
|
|
BRAND_MAIL_BACKGROUND: "#f5f5f5",
|
|
BRAND_MAIL_LINK: "#0e7490",
|
|
})
|
|
).toEqual({
|
|
support: { email: "help@acme.test", fromName: "Acme Help" },
|
|
legal: {
|
|
imprintUrl: "https://acme.test/imprint",
|
|
privacyUrl: "https://acme.test/privacy",
|
|
termsUrl: "https://acme.test/terms",
|
|
},
|
|
assets: {
|
|
logoUrl: "https://cdn.acme.test/logo.svg",
|
|
faviconUrl: "https://cdn.acme.test/favicon.ico",
|
|
},
|
|
mail: {
|
|
colors: {
|
|
primary: "#0f766e",
|
|
primaryText: "#ffffff",
|
|
background: "#f5f5f5",
|
|
link: "#0e7490",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it("composes with createBrandTokens, preserving defaults for unset env keys", () => {
|
|
const tokens = createBrandTokens(
|
|
loadBrandFromEnv({
|
|
BRAND_PRODUCT_NAME: "Acme Ops",
|
|
BRAND_MAIL_PRIMARY: "#123456",
|
|
})
|
|
);
|
|
|
|
expect(tokens.productName).toBe("Acme Ops");
|
|
expect(tokens.siteUrl).toBe(defaultBrandTokens.siteUrl);
|
|
expect(tokens.support).toEqual(defaultBrandTokens.support);
|
|
expect(tokens.mail.colors.primary).toBe("#123456");
|
|
expect(tokens.mail.colors.primaryText).toBe(defaultBrandTokens.mail.colors.primaryText);
|
|
});
|
|
|
|
it("emits only partial sub-objects when only some sub-keys are present", () => {
|
|
expect(loadBrandFromEnv({ BRAND_SUPPORT_EMAIL: "help@acme.test" })).toEqual({
|
|
support: { email: "help@acme.test" },
|
|
});
|
|
expect(loadBrandFromEnv({ BRAND_LEGAL_TERMS_URL: "https://acme.test/terms" })).toEqual({
|
|
legal: { termsUrl: "https://acme.test/terms" },
|
|
});
|
|
expect(loadBrandFromEnv({ BRAND_LOGO_URL: "https://cdn.acme.test/logo.svg" })).toEqual({
|
|
assets: { logoUrl: "https://cdn.acme.test/logo.svg" },
|
|
});
|
|
});
|
|
});
|