1 | 'use strict';
|
2 |
|
3 | var _chai = require('chai');
|
4 |
|
5 | var _DataAPI = require('./DataAPI');
|
6 |
|
7 | var _DataAPI2 = _interopRequireDefault(_DataAPI);
|
8 |
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | describe('Initialization', () => {
|
16 | it('should initialize with options', () => {
|
17 | const dataAPI = new _DataAPI2.default();
|
18 | const initResult = dataAPI.initialize({
|
19 | environment: 'unit-test',
|
20 | heartbeatInterval: 42,
|
21 | logglySubdomain: process.env.CLIO_LOGGLY_SUBDOMAIN,
|
22 | logglyToken: process.env.CLIO_LOGGLY_TOKEN,
|
23 | logLevel: 'ERROR',
|
24 | mongoUrl: process.env.CLIO_MONGO_URL,
|
25 | port: 15926
|
26 | });
|
27 | _chai.assert.equal(true, initResult);
|
28 | _chai.assert.equal('unit-test', dataAPI.environment);
|
29 | _chai.assert.equal(42, _DataAPI2.default.heartbeatInterval);
|
30 | _chai.assert.equal(true, !!_DataAPI.logger);
|
31 | _chai.assert.deepEqual(['console', 'dailyRotateFile', 'loggly'], Object.keys(_DataAPI.logger.transports));
|
32 | _chai.assert.equal('ERROR', dataAPI.logLevel.name);
|
33 | _chai.assert.equal(process.env.CLIO_MONGO_URL, dataAPI.mongoUrl);
|
34 | _chai.assert.equal(15926, dataAPI.port);
|
35 | });
|
36 |
|
37 | it('should initialize without options', () => {
|
38 | const dataAPI = new _DataAPI2.default();
|
39 | _chai.assert.equal(true, dataAPI.initialize());
|
40 | _chai.assert.equal('', dataAPI.environment);
|
41 | _chai.assert.equal(10, _DataAPI2.default.heartbeatInterval);
|
42 | _chai.assert.equal(true, !!_DataAPI.logger);
|
43 | _chai.assert.deepEqual(['console', 'dailyRotateFile'], Object.keys(_DataAPI.logger.transports));
|
44 | _chai.assert.equal('DEBUG', dataAPI.logLevel.name);
|
45 | _chai.assert.equal('mongodb://localhost', dataAPI.mongoUrl);
|
46 | _chai.assert.equal(15925, dataAPI.port);
|
47 | });
|
48 |
|
49 | it('should return false if initialize with heartbeat interval of 0', () => {
|
50 | _chai.assert.equal(false, new _DataAPI2.default().initialize({ heartbeatInterval: 0 }));
|
51 | });
|
52 |
|
53 | it('should return false if initialize with Mongo URL of invalid scheme', () => {
|
54 | _chai.assert.equal(false, new _DataAPI2.default().initialize({ mongoUrl: 'invalid://localhost' }));
|
55 | });
|
56 |
|
57 | it('should return false if initialize with out of range port', () => {
|
58 | _chai.assert.equal(false, new _DataAPI2.default().initialize({ port: -1 }));
|
59 | _chai.assert.equal(false, new _DataAPI2.default().initialize({ port: 0 }));
|
60 | _chai.assert.equal(false, new _DataAPI2.default().initialize({ port: 70000 }));
|
61 | });
|
62 | });
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
\ | No newline at end of file |