UNPKG

@helium/http

Version:

HTTP library for interacting with the Helium blockchain API

44 lines 1.64 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const nock_1 = __importDefault(require("nock")); const Client_1 = __importDefault(require("../../Client")); const electionsFixture = (params = {}) => (Object.assign({ type: 'consensus_group_v1', time: 1234567890, proof: 'fake-proof', members: [ 'fake1', 'fake2', 'fake3', 'fake4', 'fake5', ], height: 123456, hash: 'fake-hash', delay: 0 }, params)); describe('get', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/transactions/fake-hash') .reply(200, { data: electionsFixture(), }); it('retrieves an election by hash', async () => { const client = new Client_1.default(); const election = await client.elections.get('fake-hash'); expect(election.hash).toBe('fake-hash'); }); }); describe('list', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/elections') .reply(200, { data: [ electionsFixture({ hash: 'fake-hash-1' }), electionsFixture({ hash: 'fake-hash-2' }), ], }); it('lists elections', async () => { const client = new Client_1.default(); const list = await client.elections.list(); const elections = await list.take(2); expect(elections[0].hash).toBe('fake-hash-1'); expect(elections[1].hash).toBe('fake-hash-2'); }); }); //# sourceMappingURL=Elections.spec.js.map