fix: wire editorial approval, harden registration, set production auth URL

- Wire admin approval UI to editorialService.approveEditorial so editorial
  accounts can move pending_approval -> active and log in. The approve button
  was permanently disabled and the service unreachable, so editorial users
  could never sign in.
- Surface non-validation errors (e.g. SMTP failures) on the registration
  form instead of silently redirecting to the confirmation page.
- Set BETTER_AUTH_URL default to the production domain in .env.example and
  compose.yaml so verification/reset links and the login origin check
  resolve against the live origin.
- Add scripts/check-smtp.ts to verify SMTP connectivity against the
  configured transport.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-10 23:06:13 +02:00
1 parent 907beb6e42
commit 268ea7544e
8 files changed
+228 -12

No files matched your search

@@ -0,0 +1,82 @@
import { beforeEach, expect, test, vi } from "vitest";
beforeEach(() => {
vi.clearAllMocks();
});
const mocks = vi.hoisted(() => ({
approveEditorial: vi.fn(),
headers: vi.fn(),
requireAdmin: vi.fn(),
revalidatePath: vi.fn(),
}));
vi.mock("next/headers", () => ({ headers: mocks.headers }));
vi.mock("next/cache", () => ({ revalidatePath: mocks.revalidatePath }));
vi.mock("@/modules/auth/principal", () => ({ requireAdmin: mocks.requireAdmin }));
vi.mock("@/modules/editorials/service", () => ({
editorialService: { approveEditorial: mocks.approveEditorial },
EditorialServiceError: class EditorialServiceError extends Error {
constructor(readonly code: string) {
super(code);
}
},
}));
import { approveEditorialAction } from "./actions";
test("the approve action rejects unauthenticated callers before touching the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockRejectedValue(new Error("ADMIN_REQUIRED"));
const formData = new FormData();
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("ADMIN_REQUIRED");
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
test("the approve action forwards the authenticated principal and cents price to the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
mocks.approveEditorial.mockResolvedValue(undefined);
const formData = new FormData();
formData.set("priceEuros", "12,50");
await approveEditorialAction("00000000-0000-4000-8000-000000000001", formData);
expect(mocks.approveEditorial).toHaveBeenCalledWith({
editorialId: "00000000-0000-4000-8000-000000000001",
priceCents: 1250,
adminUserId: "admin-1",
});
expect(mocks.revalidatePath).toHaveBeenCalledWith(
"/admin/redaktionen/00000000-0000-4000-8000-000000000001",
);
});
test("the approve action rejects a non-positive price before calling the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
const formData = new FormData();
formData.set("priceEuros", "0");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte geben Sie einen gültigen Nettopreis an.");
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
test("the approve action translates a service error into a German message", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
const { EditorialServiceError } = await import("@/modules/editorials/service");
mocks.approveEditorial.mockRejectedValue(new EditorialServiceError("ALBUM_GRANT_REQUIRED"));
const formData = new FormData();
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte weisen Sie zuerst mindestens ein Album zu.");
});