Updates tests for installer, config service and process control

This commit is contained in:
thatben 2025-04-21 15:52:58 +02:00
parent 77a5da5be8
commit 0e2776f6a3
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
6 changed files with 61 additions and 7 deletions

View File

@ -54,8 +54,13 @@ export const mockOsService = {
export const mockCodexGlobals = {
getPublicIp: vi.fn(),
getTestnetSPRs: vi.fn(),
getEthProvider: vi.fn(),
};
export const mockCodexApp = {
openCodexApp: vi.fn(),
};
export const mockMarketplaceSetup = {
runClientWizard: vi.fn(),
};

View File

@ -3,8 +3,9 @@ import {
mockShellService,
mockOsService,
mockFsService,
mockConfigService,
mockMarketplaceSetup,
} from "../__mocks__/service.mocks.js";
import { mockConfigService } from "../__mocks__/service.mocks.js";
import { Installer } from "./installer.js";
describe("Installer", () => {
@ -32,6 +33,7 @@ describe("Installer", () => {
mockShellService,
mockOsService,
mockFsService,
mockMarketplaceSetup,
);
});
@ -109,9 +111,22 @@ describe("Installer", () => {
expect(installer.installCodexUnix).not.toHaveBeenCalled();
});
it("returns early when marketplace client wizard returns false", async () => {
installer.arePrerequisitesCorrect.mockResolvedValue(true);
mockMarketplaceSetup.runClientWizard.mockResolvedValue(false);
await installer.installCodex(processCallbacks);
expect(processCallbacks.installStarts).not.toHaveBeenCalled();
expect(processCallbacks.installSuccessful).not.toHaveBeenCalled();
expect(processCallbacks.downloadSuccessful).not.toHaveBeenCalled();
expect(installer.isCodexInstalled).not.toHaveBeenCalled();
expect(installer.installCodexWindows).not.toHaveBeenCalled();
expect(installer.installCodexUnix).not.toHaveBeenCalled();
});
describe("prerequisites OK", () => {
beforeEach(() => {
installer.arePrerequisitesCorrect.mockResolvedValue(true);
mockMarketplaceSetup.runClientWizard.mockResolvedValue(true);
installer.isCodexInstalled.mockResolvedValue(true);
});

View File

@ -10,9 +10,11 @@ import { ProcessControl } from "./processControl.js";
describe("ProcessControl", () => {
let processControl;
const mockEthProvider = "mockEthProvider";
beforeEach(() => {
vi.resetAllMocks();
mockCodexGlobals.getEthProvider.mockReturnValue(mockEthProvider);
processControl = new ProcessControl(
mockConfigService,
@ -195,7 +197,12 @@ describe("ProcessControl", () => {
expect(mockShellService.spawnDetachedProcess).toHaveBeenCalledWith(
exe,
config.codexRoot,
[`--config-file=${configFile}`],
[
`--config-file=${configFile}`,
"persistence",
`--eth-provider=${mockEthProvider}`,
`--eth-private-key=eth.key`, // duplicated in configService.
],
);
});
});

View File

@ -94,7 +94,7 @@ export class ConfigService {
this.fs.writeFile(
this.getCodexConfigFilePath(),
`data-dir="${datadir}"${nl}` +
`log-level="TRACE"${nl}` +
`log-level="DEBUG"${nl}` +
`log-file="${codexLogFile}"${nl}` +
`storage-quota=${this.config.storageQuota}${nl}` +
`disc-port=${this.config.ports.discPort}${nl}` +
@ -105,7 +105,7 @@ export class ConfigService {
`bootstrap-node=[${bootNodes}]${nl}` +
// Marketplace client parameters cannot be set via config file.
// Open issue: https://github.com/codex-storage/nim-codex/issues/1206
`${nl}`,
"",
);
};
}

View File

@ -112,6 +112,33 @@ describe("ConfigService", () => {
});
});
describe("getEthFilePaths", () => {
const result1 = "path/to/key";
const result2 = "path/to/address";
it("returns the key and address file paths", () => {
const configService = new ConfigService(mockFsService, mockOsService);
mockFsService.pathJoin = vi.fn();
mockFsService.pathJoin.mockReturnValueOnce(result1);
mockFsService.pathJoin.mockReturnValueOnce(result2);
expect(configService.getEthFilePaths()).toEqual({
key: result1,
address: result2,
});
expect(mockFsService.pathJoin).toHaveBeenCalledWith([
expectedDefaultConfig.codexRoot,
"eth.key",
]);
expect(mockFsService.pathJoin).toHaveBeenCalledWith([
expectedDefaultConfig.codexRoot,
"eth.address",
]);
});
});
describe("validateConfiguration", () => {
var configService;
var config;

View File

@ -91,12 +91,12 @@ export class MainMenu {
};
startCodex = async () => {
// const spinner = this.ui.createAndStartSpinner("Starting...");
const spinner = this.ui.createAndStartSpinner("Starting...");
try {
await this.processControl.startCodexProcess();
// this.ui.stopSpinnerSuccess(spinner);
this.ui.stopSpinnerSuccess(spinner);
} catch (exception) {
// this.ui.stopSpinnerError(spinner);
this.ui.stopSpinnerError(spinner);
this.ui.showErrorMessage(`Failed to start Codex. "${exception}"`);
}
};