|
| 1 | +/*global describe, it*/ |
| 2 | +import * as assert from 'assert'; |
| 3 | +import * as chai from 'chai'; |
| 4 | +import {deleteAppConfig, getConfigs} from "../../../src/utils/configs.js"; |
| 5 | + |
| 6 | +let expect = chai.expect; |
| 7 | + |
| 8 | +describe('unit Tests', function () { |
| 9 | + |
| 10 | + it('verify config fail if APP_CONFIG not set properly', function () { |
| 11 | + const backEnv = process.env.APP_CONFIG; |
| 12 | + delete process.env.APP_CONFIG; |
| 13 | + deleteAppConfig(); |
| 14 | + let exceptionOccurred = false; |
| 15 | + try { |
| 16 | + getConfigs(); |
| 17 | + } catch (e) { |
| 18 | + expect(e.toString()).eql('Error: Please provide valid app config file by setting APP_CONFIG' + |
| 19 | + ' environment variable for example APP_CONFIG=./abc.json'); |
| 20 | + exceptionOccurred = true; |
| 21 | + } |
| 22 | + expect(exceptionOccurred).eql(true); |
| 23 | + process.env.APP_CONFIG = backEnv; |
| 24 | + |
| 25 | + }); |
| 26 | + it('getConfigShould pass', function () { |
| 27 | + let configs = getConfigs(); |
| 28 | + _verifyConfigs(configs); |
| 29 | + configs = getConfigs(); |
| 30 | + // call verify config second time |
| 31 | + _verifyConfigs(configs); |
| 32 | + |
| 33 | + }); |
| 34 | + it('default port should be 5000', function () { |
| 35 | + let configs = getConfigs(); |
| 36 | + _verifyConfigs(configs); |
| 37 | + configs = getConfigs(); |
| 38 | + // call verify config second time |
| 39 | + _verifyConfigs(configs); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +function _verifyConfigs(configs) { |
| 44 | + expect(configs.port).to.eql('5000'); |
| 45 | + expect(configs.authKey.length).to.eql(24); |
| 46 | + expect(configs.mysql.port).to.eql('3306'); |
| 47 | + expect(configs.mysql.user.length).to.gt(0); |
| 48 | + expect(configs.mysql.password.length).to.gt(0); |
| 49 | + expect(configs.mysql.host.length).to.gt(0); |
| 50 | + expect(configs.mysql.database.length).to.gt(0); |
| 51 | + |
| 52 | +} |
0 commit comments