fix(public): distinguish unavailable data from empty results and missing pages
CI / check (push) Successful in 56s
CI / deploy (push) Successful in 1m30s
CI / publish-container (push) Successful in 44s

This commit is contained in:
Simo committed 2026-09-11 00:39:53 +02:00
1 parent db4acbb46e
commit 445ef13846
16 files changed
+608 -169

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import { beforeEach, expect, it, vi } from "vitest";
const state = vi.hoisted(() => ({ fail: false }));
vi.mock("@/lib/logger", () => ({ logger: { error: vi.fn() } }));
vi.mock("@/lib/services/news-cache", () => ({
cacheNews: async () => {
if (state.fail) throw Error("unavailable");
return [];
},
}));
vi.mock("@/lib/db", async () => ({ ...(await import("@/db/schema")), db: {} }));
import { getNewsList } from "./news-list";
beforeEach(() => {
state.fail = false;
});
it("preserves an empty successful list in strict mode", async () => {
expect(await getNewsList(4, { throwOnError: true })).toEqual([]);
});
it("lets the homepage distinguish a failed news section", async () => {
state.fail = true;
await expect(getNewsList(4, { throwOnError: true })).rejects.toThrow(
"unavailable",
);
});
it("preserves the legacy fallback for other callers", async () => {
state.fail = true;
expect(await getNewsList(4)).toEqual([]);
});