initial commit
[urlittler] / test / src / db / base.js
1 /* eslint-env mocha */
2 /* eslint-disable capitalized-comments */
3
4 'use strict';
5
6 const assert = require('assert');
7 const sinon = require('sinon');
8 const BaseDatabase = require('../../../src/db/base');
9 const DBErrors = require('../../../src/db/errors');
10
11 const noExpectedException = 'did not get expected exception';
12
13 describe('BaseDatabase', function () {
14 let logger, db;
15
16 beforeEach(function () {
17 logger = { error: () => {} };
18 // logger = console;
19 db = new BaseDatabase(logger);
20 });
21
22 afterEach(function () {
23 sinon.restore();
24 });
25
26 describe('_camelfy', function () {
27 it('empty arg', function () {
28 const result = BaseDatabase._camelfy();
29 assert.strictEqual(result, undefined);
30 });
31 it('no change', function () {
32 const str = 'camelCase';
33 const result = BaseDatabase._camelfy(str);
34 assert.strictEqual(result, str);
35 });
36 it('does expected', function () {
37 const str = 'snake_case_thing';
38 const result = BaseDatabase._camelfy(str);
39 assert.strictEqual(result, 'snakeCaseThing');
40 });
41 }); // _camelfy
42
43 describe('interface', function () {
44 it('covers methods', async function () {
45 const methods = [
46 'context',
47 'transaction',
48 'getAuthById',
49 'insertLink',
50 'getLinkById',
51 'getLinkByUrl',
52 'accessLink',
53 'expireLink',
54 'updateLink',
55 'getAllLinks',
56 ];
57 const invokedMethods = methods.map(async (m) => {
58 try {
59 // eslint-disable-next-line security/detect-object-injection
60 await db[m]();
61 assert.fail(noExpectedException);
62 } catch (e) {
63 assert(e instanceof DBErrors.NotImplemented);
64 }
65 });
66 await Promise.all(invokedMethods);
67 });
68 }); // interface
69
70 });