Skip to content

Commit

Permalink
fix(2051): fix function that does not exist (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
wahapo authored Dec 7, 2020
1 parent 1045116 commit 418318f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class SlackNotifier extends NotificationBase {
}

static validateConfig(config) {
return Joi.validate(config, SCHEMA_SLACK_SETTINGS);
return SCHEMA_SLACK_SETTINGS.validate(config);
}
}

Expand Down
99 changes: 99 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,103 @@ describe('index', () => {
});
});
});

describe('validate config', () => {
it('valid config with complete parameters', () => {
configMock = {
slack: {
channels: ['foo-channel'],
statuses: ['SUCCESS', 'FAILURE'],
minimized: true
}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('valid config with empty statuses', () => {
configMock = {
slack: {
channels: ['foo-channel'],
statuses: []
}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('valid config with a channel', () => {
configMock = {
slack: 'foo-channel'
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('valid config with channels', () => {
configMock = {
slack: ['foo-channel', 'bar-channel']
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('invalid config with empty parameters', () => {
configMock = {};
const { error } = SlackNotifier.validateConfig(configMock);

assert.instanceOf(error, Error);
assert.equal(error.name, 'ValidationError');
});

it('valid config with empty slack settings', () => {
configMock = {
slack: {}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('valid config without channels', () => {
configMock = {
slack: {
statuses: ['SUCCESS', 'FAILURE']
}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.isUndefined(error);
});

it('invalid config with empty channels', () => {
configMock = {
slack: {
channels: [],
statuses: ['SUCCESS', 'FAILURE']
}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.instanceOf(error, Error);
assert.equal(error.name, 'ValidationError');
});

it('invalid unknown status', () => {
configMock = {
slack: {
channels: ['foo-channel'],
statuses: ['DUMMY_STATUS']
}
};
const { error } = SlackNotifier.validateConfig(configMock);

assert.instanceOf(error, Error);
assert.equal(error.name, 'ValidationError');
});
});
});

0 comments on commit 418318f

Please sign in to comment.