mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 04:45:07 +00:00
add tests for the notifier module
This commit is contained in:
parent
fa48a5269a
commit
ecf890d20c
@ -25,7 +25,7 @@ exports.init = function(params, callback) {
|
||||
};
|
||||
|
||||
/*
|
||||
* Check if this completed build should be notified, then notify
|
||||
* Check if that's completed build should be notified, then notify
|
||||
*/
|
||||
exports.send = function(build, callback) {
|
||||
callback = callback || utils.logErrorCallback;
|
||||
|
@ -5,3 +5,4 @@ require('./scm');
|
||||
require('./executor');
|
||||
require('./node');
|
||||
require('./distributor');
|
||||
require('./notifier');
|
||||
|
154
test/notifier.js
Normal file
154
test/notifier.js
Normal file
@ -0,0 +1,154 @@
|
||||
'use strict';
|
||||
|
||||
var notifier = require('../lib/notifier'),
|
||||
expect = require('expect.js'),
|
||||
sinon = require('sinon');
|
||||
|
||||
|
||||
describe('notifier module', function() {
|
||||
|
||||
function TestNotifier() {
|
||||
}
|
||||
TestNotifier.prototype.init = sinon.spy(function(params, callback) {
|
||||
callback();
|
||||
});
|
||||
TestNotifier.prototype.send = sinon.spy(function(params, callback) {
|
||||
callback();
|
||||
});
|
||||
|
||||
var sendSpy = TestNotifier.prototype.send;
|
||||
|
||||
describe('before test', function() {
|
||||
it('should allow rigester test notifier', function() {
|
||||
notifier.register('test', TestNotifier);
|
||||
});
|
||||
|
||||
it('should be intialized without errors', function(done) {
|
||||
notifier.init({}, done);
|
||||
});
|
||||
|
||||
it('test notifier init method should be called during init', function() {
|
||||
expect(TestNotifier.prototype.init.calledOnce).equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
var build;
|
||||
|
||||
describe('exceptions', function() {
|
||||
it('set build to uncompleted', function() {
|
||||
build = {completed: false};
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('error should be thrown for uncompleted build', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).ok();
|
||||
expect(err.message).match(/Build should be completed/);
|
||||
expect(sendSpy.calledOnce).equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('set build to completed', function() {
|
||||
build = {completed: true, status: 'done', project: {}};
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('will do nothing if notify section isn`t set for project', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).not.ok();
|
||||
expect(sendSpy.calledOnce).equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('notify on success', function() {
|
||||
it('set build info', function() {
|
||||
build = {
|
||||
completed: true,
|
||||
status: 'done',
|
||||
project: {
|
||||
notify: {
|
||||
on: ['success'],
|
||||
to: {test: ['recipient1', 'recipient2']}
|
||||
}
|
||||
}
|
||||
};
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('should notify when build is done', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).not.ok();
|
||||
expect(sendSpy.calledOnce).equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be notified with right params', function() {
|
||||
expect(sendSpy.calledWith({
|
||||
notifyReason: {strategy: 'success'},
|
||||
build: build
|
||||
})).equal(true);
|
||||
});
|
||||
|
||||
it('set build to error', function() {
|
||||
build.status = 'error';
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('should not notify when build is error', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).not.ok();
|
||||
expect(sendSpy.calledOnce).equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('notify on fail', function() {
|
||||
it('set build info', function() {
|
||||
build = {
|
||||
completed: true,
|
||||
status: 'error',
|
||||
project: {
|
||||
notify: {
|
||||
on: ['fail'],
|
||||
to: {test: ['recipient1', 'recipient2']}
|
||||
}
|
||||
}
|
||||
};
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('should notify when build with error', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).not.ok();
|
||||
expect(sendSpy.calledOnce).equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be notified with right params', function() {
|
||||
expect(sendSpy.calledWith({
|
||||
notifyReason: {strategy: 'fail'},
|
||||
build: build
|
||||
})).equal(true);
|
||||
});
|
||||
|
||||
it('set build to done', function() {
|
||||
build.status = 'done';
|
||||
sendSpy.reset();
|
||||
});
|
||||
|
||||
it('should not notify when build is done', function(done) {
|
||||
notifier.send(build, function(err) {
|
||||
expect(err).not.ok();
|
||||
expect(sendSpy.calledOnce).equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user