Skip to content
This repository was archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Add tests for get-config
Browse files Browse the repository at this point in the history
- Add test suite for `get-config`
- Fix `get-config` to handle merging nested `gpg` property correctly
  • Loading branch information
jarrodldavis committed Oct 14, 2017
1 parent 1b8d183 commit cb0e2a9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const defaultConfig = {
};

module.exports = async context => {
const repoConfig = await context.config('config.yml', { gpg: defaultConfig });
return repoConfig.gpg;
const repoConfig = await context.config('config.yml', { gpg: {} });
return Object.assign({}, defaultConfig, repoConfig.gpg);
};
43 changes: 43 additions & 0 deletions test/get-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const assert = require('assertive');

const getConfig = require('../lib/get-config');

const ContextMock = require('./mocks/context');

describe('get-config', () => {
it('should get the config', async () => {
// Arrange
const expected = { ignoreWebFlow: true };
const contextMock = new ContextMock(null, { gpg: expected });

// Act
const actual = await getConfig(contextMock);

// Assert
assert.deepEqual(expected, actual);
});

it('should return the default config if no GPG options are defined', async () => {
// Arrange
const expected = { ignoreWebFlow: false };
const contextMock = new ContextMock(null, {});

// Act
const actual = await getConfig(contextMock);

// Assert
assert.deepEqual(expected, actual);
});

it('should return the default config if other GPG options are defined', async () => {
// Arrange
const expected = { unused: 5, ignoreWebFlow: false };
const contextMock = new ContextMock(null, { gpg: { unused: 5 } });

// Act
const actual = await getConfig(contextMock);

// Assert
assert.deepEqual(expected, actual);
});
});
7 changes: 6 additions & 1 deletion test/mocks/context.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = class ContextMock {
constructor(payload) {
constructor(payload, config) {
this.payload = payload;
this.configObj = config;
}

repo(object) {
Expand All @@ -9,4 +10,8 @@ module.exports = class ContextMock {
repo: 'repo'
}, object);
}

async config() {
return Promise.resolve(this.configObj);
}
};

0 comments on commit cb0e2a9

Please sign in to comment.