Test Report

0
0
3
141

ID Title Duration (ms)
1 K7 should register the plugin 130
2 K7 should register the plugin with an array of models in options 6
3 K7 should register the plugin with adapter as string 3

Code Coverage Report

95.92%
49
47
2

index.js

100%
1
1
0
Line Lint Hits Source
1 1 module.exports = require('./lib');
2

lib/index.js

100%
13
13
0
Line Lint Hits Source
1 'use strict';
2
3 // Load Modules
4
5 1 const K7 = require('./k7');
6
7 1 exports.register = function (server, options, next) {
8 const k7 = new K7(server, options);
9
10 3 server.expose('k7', k7);
11
12 3 k7.load();
13
14 3 server.decorate('server', 'database', k7.database);
15
16 3 return next();
17 };
18
19 1 exports.register.attributes = {
20 pkg: require('../package.json')
21 };
22

lib/k7.js

94.29%
35
33
2
Line Lint Hits Source
1 'use strict';
2
3 // Load modules
4
5 1 const Hoek = require('hoek');
6
7 // Declare internals
8
9 1 let internals = {};
10
11 1 internals.defaults = {
12 connectionString: '',
13 connectionOptions: {},
14 models: ''
15 };
16
17 1 module.exports = internals.K7 = function (server, options) {
18
options =
options
||
{}
;
19
20 3 Hoek.assert(this instanceof internals.K7, 'K7 must be instantiated using new');
21 3 Hoek.assert(server, 'server required to create k7');
22
23 3 options = Hoek.applyToDefaults(internals.defaults, options);
24
25 3 this.settings = options;
26 3 this.database = {};
27
28 3 if (!Array.isArray(this.settings.models)) {
29 1 this.settings.models = [this.settings.models];
30 }
31 };
32
33 1 internals.K7.prototype.load = function (cb) {
34 let Adapter = this.settings.adapter;
35
36 3 if (typeof this.settings.adapter === 'string') {
37 1 Adapter = require(this.settings.adapter);
38 }
39
40 3 const reachOptions = {
41 functions: true
42 };
43
44
const adapterName =
Hoek.reach(Adapter, 'attributes.name', reachOptions)
||
'adapter'
;
45
46 3 Hoek.assert(typeof Adapter === 'function', adapterName + ' must be a constructor function');
47
48 3 this.adapter = new Adapter(this.settings);
49
50 3 Hoek.assert(typeof this.adapter.load === 'function', adapterName + ' must be a load function');
51
52 3 this.database = this.adapter.load();
53 };
54

Linting Report

Nothing to show here, linting is disabled.