minor refactoring in router, clarifying names and complicating parameter objects
[squeep-api-dingus] / test / lib / router / path-parameter.js
diff --git a/test/lib/router/path-parameter.js b/test/lib/router/path-parameter.js
new file mode 100644 (file)
index 0000000..9b2fb1e
--- /dev/null
@@ -0,0 +1,51 @@
+/* eslint-env mocha */
+'use strict';
+
+const assert = require('assert');
+const PathParameter = require('../../../lib/router/path-parameter');
+
+const noExpectedException = 'did not receive expected exception';
+describe('PathParameter', function () {
+  beforeEach(function () {
+    PathParameter._flush();
+  });
+  it('requires a parameter', function () {
+    try {
+      new PathParameter();
+      assert.fail(noExpectedException);
+    } catch (e) {
+      assert(e instanceof RangeError, noExpectedException);
+    }
+  });
+  it('requires parameter be a string', function () {
+    try {
+      new PathParameter({});
+      assert.fail(noExpectedException);
+    } catch (e) {
+      assert(e instanceof RangeError, noExpectedException);
+    }
+  });
+  it('creates a parameter object', function () {
+    const p = new PathParameter('foo');
+    assert(p instanceof PathParameter);
+    assert.strictEqual(p.parameter, 'foo');
+  });
+  it('duplicate parameters are the same object', function () {
+    const p1 = new PathParameter('foo');
+    const p2 = new PathParameter('foo');
+    assert.strictEqual(p1, p2);
+  });
+  it('shows itself', function () {
+    const p = new PathParameter('foo');
+    assert(p.toString().includes('foo'));
+  });
+  it('parameters are immutable', function () {
+    const p = new PathParameter('foo');
+    try {
+      p[PathParameter.kPathParameter] = 'bar';
+      assert.fail(noExpectedException);
+    } catch (e) {
+      assert(e instanceof TypeError, noExpectedException);
+    }
+  });
+}); // PathParameter
\ No newline at end of file