UNPKG

textiot

Version:

A framework for building web and native (IoT) Dapps on the IPFS network

57 lines (56 loc) 2.46 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; 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 config_1 = __importDefault(require("../config")); const config_2 = require("./__static__/config"); const opts = { url: 'http://127.0.0.1', port: 40600, version: 0 }; const ROOT = `${opts.url}:${opts.port}`; const config = new config_1.default(opts); describe('config get', () => { it('should resolve to valid return value', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .get('/api/v0/config/Addresses/API') .reply(200, `"${ROOT}"`); nock_1.default(ROOT) .get('/api/v0/config/Not/Valid') .replyWithError({ message: 'empty struct value', code: 400 }); expect(yield config.get('Addresses.API')).toEqual(ROOT); })); }); describe('config get whole thing', () => { it('should resolve to valid return value', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .get('/api/v0/config') .reply(200, config_2.config); expect(yield config.get()).toEqual(config_2.config); })); }); describe('config set', () => { it('should resolve to boolean', () => __awaiter(void 0, void 0, void 0, function* () { // const patch = [{ op: 'replace', path: 'IsServer', value: true }] // TODO: Specify patch body matching nock_1.default(ROOT) .patch('/api/v0/config') .reply(204); expect(yield config.set('IsServer', true)).toEqual(true); })); });