use separate base64url module, update dependencies and devDependencies
[squeep-indieauth-helper] / test / lib / common.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const common = require('../../lib/common');
6
7 describe('common', function () {
8 describe('fileScope', function () {
9 it('names a file path', function () {
10 const filename = 'lib/foo/bar.js';
11 const result = common.fileScope(filename)('baz');
12 assert.strictEqual(result, 'bar:baz');
13 });
14 it('names an index path', function () {
15 const filename = 'lib/foo/index.js';
16 const result = common.fileScope(filename)('baz');
17 assert.strictEqual(result, 'foo:baz');
18 });
19 }); // fileScope
20
21 describe('pick', function () {
22 it('picks', function () {
23 const srcObj = {
24 a: 1,
25 b: 2,
26 c: 3,
27 };
28 const result = common.pick(srcObj, ['a', 'c', 'd']);
29 assert.deepStrictEqual(result, {
30 'a': 1,
31 'c': 3,
32 });
33 });
34 }); // pick
35
36 describe('logTruncate', function () {
37 it('returns short string', function () {
38 const str = 'this is a short string';
39 const result = common.logTruncate(str, 100);
40 assert.strictEqual(result, str);
41 });
42 it('truncates long string', function () {
43 const str = 'this is not really a very long string but it is long enough for this test';
44 const result = common.logTruncate(str, 10);
45 assert(result.length < str.length);
46 });
47 }); // logTruncate
48
49 describe('axiosResponseLogData', function () {
50 it('covers', function () {
51 const response = {
52 status: 200,
53 statusText: 'OK',
54 headers: {
55 'Content-Type': 'text/plain',
56 },
57 otherData: 'blah',
58 data: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green Meadows," said Old Mother West Wind, “and there I saw the Best Thing in the World.”',
59 };
60 const expected = {
61 status: 200,
62 statusText: 'OK',
63 headers: {
64 'Content-Type': 'text/plain',
65 },
66 data: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)',
67 };
68 const result = common.axiosResponseLogData(response);
69 assert.deepStrictEqual(result, expected);
70 });
71 it('covers no data', function () {
72 const response = {
73 status: 200,
74 statusText: 'OK',
75 headers: {
76 'Content-Type': 'text/plain',
77 },
78 };
79 const expected = {
80 status: 200,
81 statusText: 'OK',
82 headers: {
83 'Content-Type': 'text/plain',
84 },
85 };
86 const result = common.axiosResponseLogData(response);
87 assert.deepStrictEqual(result, expected);
88 });
89 }); // axiosResponseLogData
90
91 }); // common