CI / ci (push) Canceled after 0s
Added a cron job processor so emails and notifications can get processed. Added super admin settings with a gui to edit.
79 lines
3.3 KiB
TypeScript
79 lines
3.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { generateBusinessEnv, type BusinessEnvValues } from "../compose-template";
|
|
|
|
const baseValues: BusinessEnvValues = {
|
|
name: "Acme Barbers",
|
|
domain: "acme.example.com",
|
|
databaseName: "acme",
|
|
databaseUser: "acme",
|
|
databasePassword: "db-password",
|
|
authSecret: "auth-secret",
|
|
installationToken: "the-installation-token-value",
|
|
cronSecret: "cron-secret",
|
|
};
|
|
|
|
describe("generateBusinessEnv — INSTALLATION_TOKEN", () => {
|
|
it("writes the given installation token into the generated .env", () => {
|
|
const env = generateBusinessEnv(baseValues);
|
|
expect(env).toContain('INSTALLATION_TOKEN="the-installation-token-value"');
|
|
});
|
|
|
|
it("never writes the token in a NEXT_PUBLIC_* (build-time-inlined) variable", () => {
|
|
const env = generateBusinessEnv(baseValues);
|
|
const publicLines = env.split("\n").filter((line) => line.startsWith("NEXT_PUBLIC_"));
|
|
for (const line of publicLines) {
|
|
expect(line).not.toContain("the-installation-token-value");
|
|
}
|
|
});
|
|
|
|
it("is the only place a business's INSTALLATION_TOKEN gets written — every business gets a distinct token if given one", () => {
|
|
const envA = generateBusinessEnv({ ...baseValues, installationToken: "token-a" });
|
|
const envB = generateBusinessEnv({ ...baseValues, domain: "other.example.com", installationToken: "token-b" });
|
|
expect(envA).toContain('INSTALLATION_TOKEN="token-a"');
|
|
expect(envB).toContain('INSTALLATION_TOKEN="token-b"');
|
|
expect(envA).not.toContain("token-b");
|
|
expect(envB).not.toContain("token-a");
|
|
});
|
|
});
|
|
|
|
describe("generateBusinessEnv — AUTH_URL", () => {
|
|
it("sets AUTH_URL explicitly to the business's own https domain — not left to header-based detection", () => {
|
|
const env = generateBusinessEnv(baseValues);
|
|
expect(env).toContain('AUTH_URL="https://acme.example.com"');
|
|
});
|
|
|
|
it("AUTH_URL always matches DOMAIN/NEXT_PUBLIC_APP_URL for a given business", () => {
|
|
const env = generateBusinessEnv({ ...baseValues, domain: "other-business.example.com" });
|
|
expect(env).toContain('DOMAIN="other-business.example.com"');
|
|
expect(env).toContain('AUTH_URL="https://other-business.example.com"');
|
|
expect(env).toContain('NEXT_PUBLIC_APP_URL="https://other-business.example.com"');
|
|
});
|
|
});
|
|
|
|
describe("generateBusinessEnv — SUPER_ADMIN_*", () => {
|
|
it("leaves SUPER_ADMIN_EMAIL blank when no global default is configured", () => {
|
|
const env = generateBusinessEnv(baseValues);
|
|
expect(env).toContain('SUPER_ADMIN_EMAIL=""');
|
|
expect(env).toContain('SUPER_ADMIN_FIRST_NAME=""');
|
|
expect(env).toContain('SUPER_ADMIN_LAST_NAME=""');
|
|
});
|
|
|
|
it("bakes in the global default Super Administrator when given one", () => {
|
|
const env = generateBusinessEnv({
|
|
...baseValues,
|
|
superAdmin: { email: "lazis002@gmail.com", firstName: "Stefan", lastName: "Lazic" },
|
|
});
|
|
expect(env).toContain('SUPER_ADMIN_EMAIL="lazis002@gmail.com"');
|
|
expect(env).toContain('SUPER_ADMIN_FIRST_NAME="Stefan"');
|
|
expect(env).toContain('SUPER_ADMIN_LAST_NAME="Lazic"');
|
|
});
|
|
|
|
it("never writes a SUPER_ADMIN_PASSWORD line — sign-in is OTP-only", () => {
|
|
const env = generateBusinessEnv({
|
|
...baseValues,
|
|
superAdmin: { email: "lazis002@gmail.com", firstName: "Stefan", lastName: "Lazic" },
|
|
});
|
|
expect(env).not.toContain("SUPER_ADMIN_PASSWORD");
|
|
});
|
|
});
|