CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
serialize.test.js144 linesDownload Raw Back to test
1'use strict'2 3const test = require('tape')4const URI = require('../')5 6test('URI Serialize', (t) => {7  let components = {8    scheme: undefined,9    userinfo: undefined,10    host: undefined,11    port: undefined,12    path: undefined,13    query: undefined,14    fragment: undefined15  }16  t.equal(URI.serialize(components), '', 'Undefined Components')17 18  components = {19    scheme: '',20    userinfo: '',21    host: '',22    port: 0,23    path: '',24    query: '',25    fragment: ''26  }27  t.equal(URI.serialize(components), '//@:0?#', 'Empty Components')28 29  components = {30    scheme: 'uri',31    userinfo: 'foo:bar',32    host: 'example.com',33    port: 1,34    path: 'path',35    query: 'query',36    fragment: 'fragment'37  }38  t.equal(URI.serialize(components), 'uri://foo:bar@example.com:1/path?query#fragment', 'All Components')39 40  components = {41    scheme: 'uri',42    host: 'example.com',43    port: '9000'44  }45  t.equal(URI.serialize(components), 'uri://example.com:9000', 'String port')46 47  t.equal(URI.serialize({ path: '//path' }), '/%2Fpath', 'Double slash path')48  t.equal(URI.serialize({ path: 'foo:bar' }), 'foo%3Abar', 'Colon path')49  t.equal(URI.serialize({ path: '?query' }), '%3Fquery', 'Query path')50 51  t.equal(URI.serialize({ host: '10.10.10.10' }), '//10.10.10.10', 'IPv4address')52 53  // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)54  t.equal(URI.serialize({ host: '10.10.10.10.example.com' }), '//10.10.10.10.example.com', 'Mixed IPv4address & reg-name')55 56  // IPv6address57  t.equal(URI.serialize({ host: '2001:db8::7' }), '//[2001:db8::7]', 'IPv6 Host')58  t.equal(URI.serialize({ host: '::ffff:129.144.52.38' }), '//[::ffff:129.144.52.38]', 'IPv6 Mixed Host')59  t.equal(URI.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }), '//[2606:2800:220:1:248:1893:25c8:1946]', 'IPv6 Full Host')60 61  // IPv6address with zone identifier, RFC 687462  t.equal(URI.serialize({ host: 'fe80::a%en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Unescaped Host')63  t.equal(URI.serialize({ host: 'fe80::a%25en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Escaped Host')64 65  t.end()66})67 68test('WS serialize', (t) => {69  t.equal(URI.serialize({ scheme: 'ws' }), 'ws:')70  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com' }), 'ws://example.com')71  t.equal(URI.serialize({ scheme: 'ws', resourceName: '/' }), 'ws:')72  t.equal(URI.serialize({ scheme: 'ws', resourceName: '/foo' }), 'ws:/foo')73  t.equal(URI.serialize({ scheme: 'ws', resourceName: '/foo?bar' }), 'ws:/foo?bar')74  t.equal(URI.serialize({ scheme: 'ws', secure: false }), 'ws:')75  t.equal(URI.serialize({ scheme: 'ws', secure: true }), 'wss:')76  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo' }), 'ws://example.com/foo')77  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar' }), 'ws://example.com/foo?bar')78  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', secure: false }), 'ws://example.com')79  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', secure: true }), 'wss://example.com')80  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')81  t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')82  t.end()83})84 85test('WSS serialize', (t) => {86  t.equal(URI.serialize({ scheme: 'wss' }), 'wss:')87  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com' }), 'wss://example.com')88  t.equal(URI.serialize({ scheme: 'wss', resourceName: '/' }), 'wss:')89  t.equal(URI.serialize({ scheme: 'wss', resourceName: '/foo' }), 'wss:/foo')90  t.equal(URI.serialize({ scheme: 'wss', resourceName: '/foo?bar' }), 'wss:/foo?bar')91  t.equal(URI.serialize({ scheme: 'wss', secure: false }), 'ws:')92  t.equal(URI.serialize({ scheme: 'wss', secure: true }), 'wss:')93  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo' }), 'wss://example.com/foo')94  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar' }), 'wss://example.com/foo?bar')95  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', secure: false }), 'ws://example.com')96  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', secure: true }), 'wss://example.com')97  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')98  t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')99 100  t.end()101})102 103test('URN serialize', (t) => {104// example from RFC 2141105  const components = {106    scheme: 'urn',107    nid: 'foo',108    nss: 'a123,456'109  }110  t.equal(URI.serialize(components), 'urn:foo:a123,456')111  // example from RFC 4122112  let uuidcomponents = {113    scheme: 'urn',114    nid: 'uuid',115    uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'116  }117  t.equal(URI.serialize(uuidcomponents), 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')118 119  uuidcomponents = {120    scheme: 'urn',121    nid: 'uuid',122    uuid: 'notauuid-7dec-11d0-a765-00a0c91e6bf6'123  }124  t.equal(URI.serialize(uuidcomponents), 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')125  t.end()126})127test('URN NID Override', (t) => {128  let components = URI.parse('urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6', { nid: 'uuid' })129  t.equal(components.error, undefined, 'errors')130  t.equal(components.scheme, 'urn', 'scheme')131  t.equal(components.path, undefined, 'path')132  t.equal(components.nid, 'foo', 'nid')133  t.equal(components.nss, undefined, 'nss')134  t.equal(components.uuid, 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', 'uuid')135 136  components = {137    scheme: 'urn',138    nid: 'foo',139    uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'140  }141  t.equal(URI.serialize(components, { nid: 'uuid' }), 'urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')142  t.end()143})144