@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
104 lines • 4.49 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { expect } from 'chai';
import { afterEach, beforeEach, describe, it } from 'mocha';
import sinon from 'sinon';
import { NodeCommandHandlers } from '../../../../src/commands/node/handlers.js';
import { DiagnosticsReporter } from '../../../../src/commands/util/diagnostics-reporter.js';
import { SoloError } from '../../../../src/core/errors/solo-error.js';
import { Flags as flags } from '../../../../src/commands/flags.js';
/**
* Creates a minimal stub for SoloLogger sufficient for NodeCommandHandlers construction.
*/
function makeLoggerStub() {
return {
info: sinon.stub(),
warn: sinon.stub(),
error: sinon.stub(),
debug: sinon.stub(),
showUser: sinon.stub(),
showUserError: sinon.stub(),
showList: sinon.stub(),
showJSON: sinon.stub(),
addMessageGroup: sinon.stub(),
getMessageGroup: sinon.stub().returns([]),
addMessageGroupMessage: sinon.stub(),
showMessageGroup: sinon.stub(),
getMessageGroupKeys: sinon.stub().returns([]),
showAllMessageGroups: sinon.stub(),
setDevMode: sinon.stub(),
isDevMode: sinon.stub().returns(false),
nextTraceId: sinon.stub(),
prepMeta: sinon.stub().callsFake((meta) => meta ?? {}),
flush: sinon.stub().callsFake((callback) => callback()),
};
}
describe('NodeCommandHandlers - report', () => {
let handlers;
let debugStub;
let isGhCliAvailableStub;
let createGitHubIssueStub;
let loggerStub;
beforeEach(() => {
loggerStub = makeLoggerStub();
const leaseManagerStub = sinon.stub();
const configManagerStub = sinon.createStubInstance(class FakeConfigManager {
update() { }
getFlag() {
return '';
}
});
const localConfigStub = sinon.stub();
const remoteConfigStub = sinon.stub();
const tasksStub = sinon.stub();
const configsStub = sinon.stub();
const k8FactoryStub = sinon.stub();
handlers = new NodeCommandHandlers(leaseManagerStub, configManagerStub, localConfigStub, remoteConfigStub, tasksStub, configsStub, k8FactoryStub);
// Inject the logger stub
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handlers.logger = loggerStub;
// Prevent the real `debug()` from running Listr tasks
debugStub = sinon.stub(NodeCommandHandlers.prototype, 'debug').resolves(true);
// Default: gh CLI not available
isGhCliAvailableStub = sinon.stub(DiagnosticsReporter, 'isGhCliAvailable').resolves(false);
// Stub createGitHubIssue to avoid real network calls
createGitHubIssueStub = sinon
.stub(DiagnosticsReporter, 'createGitHubIssue')
.resolves('https://github.com/hiero-ledger/solo/issues/999');
});
afterEach(() => {
sinon.restore();
});
it('throws SoloError when gh CLI is not available', async () => {
const argv = {
_: ['deployment', 'diagnostics', 'report'],
[flags.quiet.name]: true,
[flags.deployment.name]: 'test-deployment',
};
await expect(handlers.report(argv)).to.be.rejectedWith(SoloError, /GitHub CLI \(gh\) is required/);
expect(debugStub).to.have.been.calledOnce;
});
it('creates issue successfully when quiet flag is true and gh is available', async () => {
isGhCliAvailableStub.resolves(true);
const argv = {
_: ['deployment', 'diagnostics', 'report'],
[flags.quiet.name]: true,
[flags.deployment.name]: 'test-deployment',
};
const result = await handlers.report(argv);
expect(result).to.equal(true);
expect(debugStub).to.have.been.calledOnce;
expect(createGitHubIssueStub).to.have.been.calledOnce;
});
it('calls deployment diagnostics debug before checking for gh', async () => {
const argv = {
_: ['deployment', 'diagnostics', 'report'],
[flags.quiet.name]: true,
[flags.deployment.name]: 'test-deployment',
};
await expect(handlers.report(argv)).to.be.rejectedWith(SoloError);
// debug() must be called before the gh check
expect(debugStub).to.have.been.calledOnce;
expect(isGhCliAvailableStub).to.have.been.calledAfter(debugStub);
});
});
//# sourceMappingURL=handlers-report.test.js.map