UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

67 lines 2.98 kB
// SPDX-License-Identifier: Apache-2.0 import { expect } from 'chai'; import sinon from 'sinon'; import { DefaultKindClient } from '../../../../../src/integration/kind/impl/default-kind-client.js'; import { KindVersion } from '../../../../../src/integration/kind/model/kind-version.js'; import { VersionRequest } from '../../../../../src/integration/kind/request/version-request.js'; import { KindExecutionBuilder } from '../../../../../src/integration/kind/execution/kind-execution-builder.js'; import { SemanticVersion } from '../../../../../src/business/utils/semantic-version.js'; describe('DefaultKindClient - version', () => { let client; beforeEach(() => { client = new DefaultKindClient('/usr/local/bin/kind'); }); afterEach(() => { sinon.restore(); }); it('should return SemanticVersion<string> from KindVersion', async () => { // Arrange const fakeSemanticVersion = new SemanticVersion('0.20.0'); const fakeKindVersion = sinon.createStubInstance(KindVersion); fakeKindVersion.getVersion.returns(fakeSemanticVersion); // Stub VersionRequest.prototype.apply to do nothing sinon.stub(VersionRequest.prototype, 'apply').callsFake(() => { }); // Stub KindExecutionBuilder.prototype.build to return a fake execution const fakeExecution = { responseAs: sinon.stub().resolves(fakeKindVersion), }; // @ts-ignore sinon.stub(KindExecutionBuilder.prototype, 'build').returns(fakeExecution); // Act const result = await client.version(); // Assert expect(result).to.be.instanceOf((SemanticVersion)); expect(result.toString()).to.equal('0.20.0'); expect(fakeExecution.responseAs.calledOnce).to.be.true; }); it('should throw if execution is a Promise', async () => { sinon.stub(VersionRequest.prototype, 'apply').callsFake(() => { }); // @ts-ignore sinon.stub(KindExecutionBuilder.prototype, 'build').returns(Promise.resolve()); try { await client.version(); expect.fail('Expected error'); } catch (error) { expect(error).to.be.instanceOf(TypeError); expect(error.message).to.equal('Unexpected async execution'); } }); it('should throw if result is not KindVersion', async () => { sinon.stub(VersionRequest.prototype, 'apply').callsFake(() => { }); const fakeExecution = { responseAs: sinon.stub().resolves({}), }; // @ts-ignore sinon.stub(KindExecutionBuilder.prototype, 'build').returns(fakeExecution); try { await client.version(); expect.fail('Expected error'); } catch (error) { expect(error).to.be.instanceOf(TypeError); expect(error.message).to.equal('Unexpected response type'); } }); }); //# sourceMappingURL=version.test.js.map