mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-27 14:31:17 -07:00
Reduce output of config validation errors
This commit is contained in:
@@ -2,12 +2,15 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import createMockRes from "test-utils/create-mock-res";
|
||||
|
||||
const { checkAndCopyConfig } = vi.hoisted(() => ({
|
||||
const { checkAndCopyConfig, getSettings } = vi.hoisted(() => ({
|
||||
checkAndCopyConfig: vi.fn(),
|
||||
getSettings: vi.fn(() => ({})),
|
||||
}));
|
||||
|
||||
vi.mock("utils/config/config", () => ({
|
||||
default: checkAndCopyConfig,
|
||||
getSettings,
|
||||
CONF_DIR: "/tmp",
|
||||
}));
|
||||
|
||||
import handler from "pages/api/validate";
|
||||
@@ -18,13 +21,28 @@ describe("pages/api/validate", () => {
|
||||
});
|
||||
|
||||
it("returns errors for any configs that don't validate", async () => {
|
||||
checkAndCopyConfig.mockReturnValueOnce(true).mockReturnValueOnce("settings bad").mockReturnValue(true);
|
||||
checkAndCopyConfig
|
||||
.mockReturnValueOnce(true)
|
||||
.mockReturnValueOnce({
|
||||
name: "YAMLException",
|
||||
config: "settings.yaml",
|
||||
reason: "settings bad",
|
||||
mark: { line: 1 },
|
||||
})
|
||||
.mockReturnValue(true);
|
||||
|
||||
const req = {};
|
||||
const res = createMockRes();
|
||||
|
||||
await handler(req, res);
|
||||
|
||||
expect(res.body).toEqual(["settings bad"]);
|
||||
expect(res.body).toEqual([
|
||||
{
|
||||
name: "YAMLException",
|
||||
config: "settings.yaml",
|
||||
reason: "settings bad",
|
||||
mark: { line: 1 },
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user