UNPKG

@helium/http

Version:

HTTP library for interacting with the Helium blockchain API

95 lines 3.97 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 citiesFixture = (params = {}) => (Object.assign({ short_state: 'mock short_state', short_country: 'mock short_country', short_city: 'mock short_city', long_state: 'mock long_state', long_country: 'mock long_country', long_city: 'mock long_city', hotspot_count: 100, online_count: 90, offline_count: 10 }, params)); describe('list', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/cities') .reply(200, { data: [ citiesFixture({ city_id: 'mock-1' }), citiesFixture({ city_id: 'mock-2' }), citiesFixture({ city_id: 'mock-3' }), ], }); (0, nock_1.default)('https://api.helium.io') .get('/v1/cities') .query({ order: 'hotspot_count' }) .reply(200, { data: [citiesFixture({ city_id: 'mock-la-1' })], }); (0, nock_1.default)('https://api.helium.io') .get('/v1/cities') .query({ order: 'online_count' }) .reply(200, { data: [citiesFixture({ city_id: 'mock-nyc-1' })], }); (0, nock_1.default)('https://api.helium.io') .get('/v1/cities') .query({ order: 'offline_count' }) .reply(200, { data: [citiesFixture({ city_id: 'mock-chi-1' })], }); it('lists cities', async () => { const client = new Client_1.default(); const list = await client.cities.list(); const cities = await list.take(10); expect(cities.length).toBe(3); expect(cities[0].cityId).toBe('mock-1'); expect(cities[1].cityId).toBe('mock-2'); expect(cities[2].cityId).toBe('mock-3'); }); it('orders by hotspot count', async () => { const client = new Client_1.default(); const list = await client.cities.list({ order: 'hotspotCount' }); const cities = await list.take(1); expect(cities[0].cityId).toBe('mock-la-1'); }); it('orders by online count', async () => { const client = new Client_1.default(); const list = await client.cities.list({ order: 'onlineCount' }); const cities = await list.take(1); expect(cities[0].cityId).toBe('mock-nyc-1'); }); it('orders by offline count', async () => { const client = new Client_1.default(); const list = await client.cities.list({ order: 'offlineCount' }); const cities = await list.take(1); expect(cities[0].cityId).toBe('mock-chi-1'); }); }); describe('get', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/cities/mock-sf-1') .reply(200, { data: citiesFixture({ city_id: 'mock-sf-1' }), }); it('gets city info for given city id', async () => { const client = new Client_1.default(); const city = await client.cities.get('mock-sf-1'); expect(city.cityId).toBe('mock-sf-1'); expect(city.hotspotCount).toBe(100); expect(city.onlineCount).toBe(90); expect(city.offlineCount).toBe(10); }); }); describe('search', () => { (0, nock_1.default)('https://api.helium.io') .get('/v1/cities?search=san%20francisco') .reply(200, { data: [citiesFixture({ city_id: 'mock-sf-1' }), citiesFixture({ city_id: 'mock-sf-2' })], }); it('searches cities', async () => { const client = new Client_1.default(); const list = await client.cities.list({ query: 'san francisco' }); const cities = await list.take(10); expect(cities.length).toBe(2); expect(cities[0].cityId).toBe('mock-sf-1'); expect(cities[1].cityId).toBe('mock-sf-2'); }); }); //# sourceMappingURL=Cities.spec.js.map