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,
} from "../utils/appData.js";
describe("ConfigService", () => {
const configPath = "/path/to/config.json";
const expectedDefaultConfig = {
function getDefaultConfig() {
return {
codexExe: "",
codexInstallPath: getCodexBinPath(),
codexConfigFilePath: getCodexConfigFilePath(),
@ -24,9 +23,15 @@ describe("ConfigService", () => {
apiPort: 8080,
},
};
}
describe("ConfigService", () => {
const configPath = "/path/to/config.json";
var expectedDefaultConfig = getDefaultConfig();
beforeEach(() => {
vi.resetAllMocks();
expectedDefaultConfig = getDefaultConfig();
mockFsService.pathJoin.mockReturnValue(configPath);
});
@ -92,6 +97,7 @@ describe("ConfigService", () => {
beforeEach(() => {
config = expectedDefaultConfig;
config.codexExe = "codex.exe";
configService = new ConfigService(mockFsService);
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", () => {