@haechi-labs/henesis-cli
Version:
🚀 Command Line Interface tool to Utilize henesis
100 lines • 4.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const test_1 = require("@oclif/test");
const integration_1 = require("./integration");
const wretch_1 = tslib_1.__importDefault(require("wretch"));
const url_1 = require("./url");
const mock_1 = require("../mock");
const mockhttp = tslib_1.__importStar(require("mockttp"));
const types_1 = require("../types");
wretch_1.default().polyfills({
fetch: require('node-fetch'),
FormData: require('form-data'),
URLSearchParams: require('url').URLSearchParams,
});
process.env.HENESIS_TEST = 'true';
describe('IntegrationRpc', () => {
let integrationRpc;
const mockServer = mockhttp.getLocal();
// Start your servers
beforeEach(async () => {
const url = url_1.baseUrl();
integrationRpc = new integration_1.IntegrationRpc(url, url_1.rpcVersion);
await mockServer.start(8080);
});
afterEach(async () => {
await mockServer.stop();
});
describe('#getIntegrations()', async () => {
it('should get integration list', async () => {
const integrations = [mock_1.newMockIntegration(), mock_1.newMockIntegration()];
await mockServer.get('/integrations/v1').thenJson(200, integrations);
const response = await integrationRpc.getIntegrations();
test_1.expect(JSON.stringify(response)).to.deep.equal(JSON.stringify(integrations));
});
it('should throw invalid response format error', async () => {
const invalidJson = { invalid: 'error' };
await mockServer.get('/integrations/v1').thenJSON(200, invalidJson);
try {
await integrationRpc.getIntegrations();
}
catch (err) {
test_1.expect(err.toString()).to.equal('Error: Expected getIntegrationsList to return an array but it returned [object Object]');
}
});
});
describe('#getIntegration()', async () => {
it('should get a integration', async () => {
const integration = mock_1.newMockIntegration();
await mockServer
.get('/integrations/v1/' + integration.integrationId)
.thenJSON(200, integration);
const response = await integrationRpc.getIntegration(integration.integrationId);
test_1.expect(JSON.stringify(response)).to.deep.equal(JSON.stringify(integration));
});
});
describe('#getIntegrationByName()', async () => {
it('should get a integration by name', async () => {
const integration = mock_1.newMockIntegration();
await mockServer
.get('/integrations/v1/findByName')
.withQuery({ name: integration.name })
.thenJSON(200, integration);
const response = await integrationRpc.getIntegrationByName(integration.name);
test_1.expect(JSON.stringify(response)).to.deep.equal(JSON.stringify(integration));
});
});
describe('#updateIntegration()', async () => {
it('should update a integration', async () => {
const integration = mock_1.newMockIntegration();
integration.version = 'v3';
await mockServer
.put('/integrations/v1/' + integration.integrationId)
.thenJSON(200, integration);
const response = await integrationRpc.updateIntegration(integration.integrationId, {
version: 'v3',
});
test_1.expect(JSON.stringify(response)).to.deep.equal(JSON.stringify(integration));
});
});
describe('#createIntegration()', async () => {
it('should create a integration', async () => {
const integration = mock_1.newMockIntegration();
await mockServer.post('/integrations/v1').thenJSON(200, integration);
const response = await integrationRpc.createIntegration(new types_1.CreateIntegrationRequest(integration.name, integration.version, integration.apiVersion, new types_1.Blockchain(integration.blockchain.platform, integration.blockchain.network, integration.blockchain.threshold), integration.filter, integration.provider));
test_1.expect(JSON.stringify(response)).to.deep.equal(JSON.stringify(integration));
});
});
describe('#deleteIntegration()', async () => {
it('should delete a integration', async () => {
const integration = mock_1.newMockIntegration();
await mockServer
.delete('/integrations/v1/' + integration.integrationId)
.thenReply(200, undefined);
const response = await integrationRpc.deleteIntegration(integration.integrationId);
test_1.expect(response).to.deep.equal(null);
});
});
});
//# sourceMappingURL=integration.spec.js.map