UNPKG

textiot

Version:

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

59 lines (58 loc) 2.69 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 contacts_1 = __importDefault(require("../contacts")); const contacts_2 = require("./__static__/contacts"); const opts = { url: 'http://127.0.0.1', port: 40600, version: 0 }; const ROOT = `${opts.url}:${opts.port}`; const contacts = new contacts_1.default(opts); describe('contacts add', () => { it('should resolve to boolean', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .put('/api/v0/contacts/address', (body) => { return body.address === contacts_2.contacts.contact.address; }) .reply(204); expect(yield contacts.add('address', contacts_2.contacts.contact)).toEqual(true); })); }); describe('contacts get', () => { it('should resolve to a valid contact object', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .get('/api/v0/contacts/address') .reply(200, contacts_2.contacts.contact); expect(yield contacts.get('address')).toEqual(contacts_2.contacts.contact); })); }); describe('contacts list', () => { it('should resolve to array of contacts', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .get('/api/v0/contacts') .reply(200, { items: [contacts_2.contacts.contact] }); expect(yield contacts.list()).toEqual({ items: [contacts_2.contacts.contact] }); })); }); describe('contacts remove', () => { it('should resolve to boolean', () => __awaiter(void 0, void 0, void 0, function* () { nock_1.default(ROOT) .delete('/api/v0/contacts/address') .reply(204); expect(yield contacts.remove('address')).toEqual(true); })); });