minor refactoring in router, clarifying names and complicating parameter objects
[squeep-api-dingus] / test / lib / router / path-parameter.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const PathParameter = require('../../../lib/router/path-parameter');
6
7 const noExpectedException = 'did not receive expected exception';
8 describe('PathParameter', function () {
9 beforeEach(function () {
10 PathParameter._flush();
11 });
12 it('requires a parameter', function () {
13 try {
14 new PathParameter();
15 assert.fail(noExpectedException);
16 } catch (e) {
17 assert(e instanceof RangeError, noExpectedException);
18 }
19 });
20 it('requires parameter be a string', function () {
21 try {
22 new PathParameter({});
23 assert.fail(noExpectedException);
24 } catch (e) {
25 assert(e instanceof RangeError, noExpectedException);
26 }
27 });
28 it('creates a parameter object', function () {
29 const p = new PathParameter('foo');
30 assert(p instanceof PathParameter);
31 assert.strictEqual(p.parameter, 'foo');
32 });
33 it('duplicate parameters are the same object', function () {
34 const p1 = new PathParameter('foo');
35 const p2 = new PathParameter('foo');
36 assert.strictEqual(p1, p2);
37 });
38 it('shows itself', function () {
39 const p = new PathParameter('foo');
40 assert(p.toString().includes('foo'));
41 });
42 it('parameters are immutable', function () {
43 const p = new PathParameter('foo');
44 try {
45 p[PathParameter.kPathParameter] = 'bar';
46 assert.fail(noExpectedException);
47 } catch (e) {
48 assert(e instanceof TypeError, noExpectedException);
49 }
50 });
51 }); // PathParameter