fixes tests for configService

This commit is contained in:
ThatBen 2025-04-15 15:22:39 +02:00
parent 03dd11d57e
commit 3ee6425200
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB

View File

@ -9,9 +9,8 @@ import {
getCodexLogsDefaultPath, getCodexLogsDefaultPath,
} from "../utils/appData.js"; } from "../utils/appData.js";
describe("ConfigService", () => { function getDefaultConfig() {
const configPath = "/path/to/config.json"; return {
const expectedDefaultConfig = {
codexExe: "", codexExe: "",
codexInstallPath: getCodexBinPath(), codexInstallPath: getCodexBinPath(),
codexConfigFilePath: getCodexConfigFilePath(), codexConfigFilePath: getCodexConfigFilePath(),
@ -24,9 +23,15 @@ describe("ConfigService", () => {
apiPort: 8080, apiPort: 8080,
}, },
}; };
}
describe("ConfigService", () => {
const configPath = "/path/to/config.json";
var expectedDefaultConfig = getDefaultConfig();
beforeEach(() => { beforeEach(() => {
vi.resetAllMocks(); vi.resetAllMocks();
expectedDefaultConfig = getDefaultConfig();
mockFsService.pathJoin.mockReturnValue(configPath); mockFsService.pathJoin.mockReturnValue(configPath);
}); });
@ -92,7 +97,8 @@ describe("ConfigService", () => {
beforeEach(() => { beforeEach(() => {
config = expectedDefaultConfig; config = expectedDefaultConfig;
config.codexExe = "codex.exe";
configService = new ConfigService(mockFsService); configService = new ConfigService(mockFsService);
configService.config = config; configService.config = config;
}); });
@ -105,7 +111,41 @@ describe("ConfigService", () => {
); );
}); });
it("throws when codexConfigFilePath is not set", () => {
config.codexConfigFilePath = "";
expect(configService.validateConfiguration).toThrow(
"Missing config value: codexConfigFilePath",
);
});
it("throws when dataDir is not set", () => {
config.dataDir = "";
expect(configService.validateConfiguration).toThrow(
"Missing config value: dataDir",
);
});
it("throws when logsDir is not set", () => {
config.logsDir = "";
expect(configService.validateConfiguration).toThrow(
"Missing config value: logsDir",
);
});
it("throws when storageQuota is less than 100 MB", () => {
config.storageQuota = 1024 * 1024 * 99;
expect(configService.validateConfiguration).toThrow(
"Storage quota must be at least 100MB",
);
});
it("passes validation for default config when codexExe is set", () => {
expect(configService.validateConfiguration).not.toThrow();
});
}); });
describe("writecodexConfigFile", () => { describe("writecodexConfigFile", () => {