mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-07 16:30:52 +08:00
Chore: homepage tests (#6278)
This commit is contained in:
41
src/__tests__/pages/api/theme.test.js
Normal file
41
src/__tests__/pages/api/theme.test.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import createMockRes from "test-utils/create-mock-res";
|
||||
|
||||
const { checkAndCopyConfig, getSettings } = vi.hoisted(() => ({
|
||||
checkAndCopyConfig: vi.fn(),
|
||||
getSettings: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("utils/config/config", () => ({
|
||||
default: checkAndCopyConfig,
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import handler from "pages/api/theme";
|
||||
|
||||
describe("pages/api/theme", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns defaults when settings are missing", () => {
|
||||
getSettings.mockReturnValueOnce({});
|
||||
|
||||
const res = createMockRes();
|
||||
handler({ res });
|
||||
|
||||
expect(checkAndCopyConfig).toHaveBeenCalledWith("settings.yaml");
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toEqual({ color: "slate", theme: "dark" });
|
||||
});
|
||||
|
||||
it("returns configured color + theme when present", () => {
|
||||
getSettings.mockReturnValueOnce({ color: "red", theme: "light" });
|
||||
|
||||
const res = createMockRes();
|
||||
handler({ res });
|
||||
|
||||
expect(res.body).toEqual({ color: "red", theme: "light" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user