Skip to content

Commit

Permalink
Merge pull request #135 from ibm-watson-iot/codeCoverageJonah
Browse files Browse the repository at this point in the history
Code coverage and minor corrections
  • Loading branch information
JonahLuckett authored Oct 21, 2019
2 parents 972d362 + dcd6249 commit 2a43371
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@babel/core": "7.4.4",
"@babel/preset-env": "7.4.4",
"@babel/register": "7.4.4",
"@cloudant/cloudant": "2.1.0",
"@cloudant/cloudant": "^2.1.0",
"@istanbuljs/nyc-config-babel": "^2.1.1",
"babel-plugin-istanbul": "^5.1.4",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"coveralls": "3.0.3",
"mocha": "6.1.4",
"mocha-steps": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/application/ApplicationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class ApplicationConfig extends BaseConfig{
var validLevels = ["error", "warning", "info", "debug"];
if (!(validLevels.includes(data["options"]["logLevel"])))
{
throw new Error("Optional setting options.logLevel must be one of error, warning, info, debug" + data["options"]["logLevel"])
throw new Error("Optional setting options.logLevel (Currently: " + data["options"]["logLevel"] + ") must be one of error, warning, info, debug")
}
}
else
Expand Down
36 changes: 36 additions & 0 deletions test/ApplicationConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,40 @@ describe('WIoTP Application Configuration', () => {
expect(config.options.http.verify).to.equal(true);
});

it('Missing auth.key throws error', () => {
let identity = null;
let auth = {key: null};
let options = null;
var applicationConfigTest = function(){new ApplicationConfig(identity, auth, options)};
expect(applicationConfigTest).to.throw('Missing auth.key from configuration');
});

it('Missing auth.token throws error', () => {
let identity = null;
let auth = {key: "MyKey", token: null};
let options = null;
var applicationConfigTest = function(){new ApplicationConfig(identity, auth, options)};
expect(applicationConfigTest).to.throw('Missing auth.token from configuration');
});

it('Initialise without auth to induce quickstart', () => {
let identity = null;
let auth = null;
let options = null;

let config = new ApplicationConfig(identity, auth, options);
expect(config.getOrgId()).to.equal("quickstart");
});

it('Load port as a string with environment variables', () => {
process.env['WIOTP_OPTIONS_MQTT_PORT'] = '8883';
let config = ApplicationConfig.parseEnvVars();
expect(config.options.mqtt.port).to.equal(8883);
});

it('Incorrect logLevel in config file throws error', () => {
var applicationConfigTest = function(){new ApplicationConfig.parseConfigFile("./test/incorrectLogLevelTest.spec.yaml")};
expect(applicationConfigTest).to.throw('Optional setting options.logLevel (Currently: notALogLevel) must be one of error, warning, info, debug');
});

});
15 changes: 9 additions & 6 deletions test/DeviceConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@ console.info = () => {};
describe('WIoTP Device Configuration', () => {

it('Initialise with the minimum required configuration', () => {
let identity = {orgId: "orgid", typeId: "mytypeid", deviceId: "mydeviceid"};
let identity = {orgId: "myOrg", typeId: "myType", deviceId: "myDevice"};
let auth = {token: "myToken"};
let options = null;

let config = new DeviceConfig(identity, auth, options);
expect(config.getOrgId()).to.equal("orgid");
expect(config.getOrgId()).to.equal("myOrg");
expect(config.options.logLevel).to.equal("info");
expect(config.options.domain).to.equal("internetofthings.ibmcloud.com");
expect(config.options.mqtt.transport).to.equal("tcp");
expect(config.options.mqtt.port).to.equal(8883);
});

it('Load mimimal configuration from environment variables', () => {
process.env['WIOTP_IDENTITY_ORGID'] = 'testOrg';
process.env['WIOTP_IDENTITY_DEVICEID'] = 'testDevice';
process.env['WIOTP_IDENTITY_ORGID'] = 'myOrg';
process.env['WIOTP_IDENTITY_DEVICEID'] = 'MyDevice';
process.env['WIOTP_IDENTITY_TYPEID'] = 'myType';
let config = DeviceConfig.parseEnvVars();
expect(config.options.logLevel).to.equal("info");
expect(config.options.domain).to.equal("internetofthings.ibmcloud.com");
expect(config.options.mqtt.transport).to.equal("tcp");
expect(config.options.mqtt.port).to.equal(8883);
delete process.env['WIOTP_IDENTITY_ORGID'];
delete process.env['WIOTP_IDENTITY_DEVICEID'];
delete process.env['WIOTP_IDENTITY_TYPEID'];

});

it('Load configuration from yaml config file', () => {
Expand Down Expand Up @@ -114,8 +117,8 @@ describe('WIoTP Device Configuration', () => {
expect(deviceConfigTest).to.throw('Missing auth.token from configuration');
});

it('Missing config file throws error', () => {
var deviceConfigTest = function(){new DeviceConfig.parseConfigFile("./test/DeviceConfigFileLogLevelTest.spec.yaml")};
it('Incorrect logLevel in config file throws error', () => {
var deviceConfigTest = function(){new DeviceConfig.parseConfigFile("./test/incorrectLogLevelTest.spec.yaml")};
expect(deviceConfigTest).to.throw('Optional setting options.logLevel (Currently: notALogLevel) must be one of error, warning, info, debug');
});

Expand Down
17 changes: 0 additions & 17 deletions test/DeviceConfigFileLogLevelTest.spec.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions test/incorrectLogLevelTest.spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
options:
logLevel: notALogLevel

0 comments on commit 2a43371

Please sign in to comment.