UNPKG

@platform/cell.client

Version:

A strongly typed HTTP client for operating with a CellOS service end-point.

103 lines (102 loc) 4.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var test_1 = require("../test"); var __1 = require(".."); var http_1 = require("@platform/http"); describe('HttpClient', function () { describe('static', function () { it('isClient', function () { var test = function (input, expected) { var res = __1.HttpClient.isClient(input); (0, test_1.expect)(res).to.eql(expected); }; test(undefined, false); test(null, false); test('', false); test({}, false); test({ request$: 123, response$: 'hello' }, false); test(__1.HttpClient.create(), true); }); }); describe('create', function () { it('parses host => origin', function () { var test = function (host, expected) { var res = __1.HttpClient.create(host); (0, test_1.expect)(res.origin).to.eql(expected); }; test(80, 'http://localhost'); test(1234, 'http://localhost:1234'); test('1234', 'http://localhost:1234'); test('localhost:8080', 'http://localhost:8080'); test('https://localhost:8080', 'http://localhost:8080'); test('https://domain.com', 'https://domain.com'); test('https://domain.com:1234', 'https://domain.com:1234'); test('domain.com:1234', 'https://domain.com:1234'); }); it('disposable', function () { var client = __1.HttpClient.create({ host: 1234 }); var fired = 0; client.dispose$.subscribe(function () { return fired++; }); client.dispose(); client.dispose(); (0, test_1.expect)(fired).to.eql(1); }); it('takes host from object', function () { var client = __1.HttpClient.create({ host: 1234 }); (0, test_1.expect)(client.origin).to.eql('http://localhost:1234'); }); it('uses given [IHttpClient]', function () { var http = http_1.Http.create({ headers: { foo: 'hello' } }); var client = __1.HttpClient.create({ http: http }); var clientHttp = client.http; (0, test_1.expect)(clientHttp).to.equal(http); (0, test_1.expect)(clientHttp.headers.foo).to.eql('hello'); }); }); it('client.ns', function () { var uri = 'ns:foo'; var client = __1.HttpClient.create(); var ns = client.ns(uri); (0, test_1.expect)(ns.toString()).to.eql(uri); }); it('client.ns (without "ns:" prefix)', function () { var client = __1.HttpClient.create(); var ns = client.ns('foo'); (0, test_1.expect)(ns.toString()).to.eql('ns:foo'); }); it('client.ns (from CELL | ROW | COLUMN | FILE)', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var client, test; return tslib_1.__generator(this, function (_a) { client = __1.HttpClient.create(); test = function (input) { var ns = client.ns(input); (0, test_1.expect)(ns.uri.toString()).to.eql('ns:foo'); }; test('foo'); test(' ns:foo '); test('cell:foo:A1'); test('cell:foo:A'); test('cell:foo:1'); test('file:foo:abc'); test(test_1.Uri.ns('foo')); test(test_1.Uri.cell('cell:foo:A1')); test(test_1.Uri.row('cell:foo:1')); test(test_1.Uri.column('cell:foo:A')); test(test_1.Uri.file('file:foo:abc')); return [2]; }); }); }); it('client.cell', function () { var uri = 'cell:foo:A1'; var client = __1.HttpClient.create(); var cell = client.cell(uri); (0, test_1.expect)(cell.toString()).to.eql(uri); }); it('client.file', function () { var uri = 'file:foo:123'; var client = __1.HttpClient.create(); var file = client.file(uri); (0, test_1.expect)(file.toString()).to.eql(uri); }); });