Skip to content

Commit

Permalink
added new tests to bring code coverage up
Browse files Browse the repository at this point in the history
  • Loading branch information
Akamaozu committed Jun 24, 2016
1 parent 5ca1c8c commit e29f733
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cjs-noticeboard.js
Expand Up @@ -85,7 +85,7 @@ module.exports = function(){
isLoggingOps = _self.settings.logOps;

// if the subscription list DNE or watcher isn't on the list, exit
if( !_self.watchers[notice] || !_self.watchers[notice][watcher] ){ return; }
if( !_self.watchers[notice] || !_self.watchers[notice][watcher] ){ return false; }

// ignore
delete _self.watchers[notice][watcher];
Expand Down
153 changes: 147 additions & 6 deletions test/test.js
Expand Up @@ -120,6 +120,69 @@ describe('Noticeboard Test Suite', function(){
assert.equal( overwrote_watcher, false, 'previous watcher was overwritten');
});

it('"watch" will return false if notice id is not a string', function(){

var result;

result = test_board.watch(1, 'watcher-id', function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though notice id is a number');

result = test_board.watch([], 'watcher-id', function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though notice id is an array');

result = test_board.watch({}, 'watcher-id', function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though notice id is an object');

result = test_board.watch(null, 'watcher-id', function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though notice id is null');
});

it('"watch" will return false if watcher id is not a string', function(){

var result;

result = test_board.watch('notice-id', 1, function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though watcher id is a number');

result = test_board.watch('notice-id', [], function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though watcher id is an array');

result = test_board.watch('notice-id', {}, function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though watcher id is an object');

result = test_board.watch('notice-id', null, function(){});

assert.equal( result, false, 'Watcher sucessfully started watching though watcher id is null');
});

it('"watch" will return false if callback is not a function', function(){

var result;

result = test_board.watch('notice-id', 'watcher-id', 1);

assert.equal( result, false, 'Watcher sucessfully started watching though callback is a number');

result = test_board.watch('notice-id', 'watcher-id', []);

assert.equal( result, false, 'Watcher sucessfully started watching though callback is an array');

result = test_board.watch('notice-id', 'watcher-id', {});

assert.equal( result, false, 'Watcher sucessfully started watching though callback is an object');

result = test_board.watch('notice-id', 'watcher-id', null);

assert.equal( result, false, 'Watcher sucessfully started watching though callback is null');
});

it('"notify" triggers a watcher\'s callback', function(done){

var notice, watcher, message,
Expand Down Expand Up @@ -162,6 +225,27 @@ describe('Noticeboard Test Suite', function(){
test_board.notify(notice, message);
});

it('"notify" will return false if notice id is not a string', function(){

var result;

result = test_board.notify(1, 'watcher-id');

assert.equal( result, false, 'Notify sucessful even though notice id is a number');

result = test_board.notify([], 'watcher-id');

assert.equal( result, false, 'Notify sucessful even though notice id is an array');

result = test_board.notify({}, 'watcher-id');

assert.equal( result, false, 'Notify sucessful even though notice id is an object');

result = test_board.notify(null, 'watcher-id');

assert.equal( result, false, 'Notify sucessful even though notice id is null');
});

it('"watch" triggers callback if useCache is true and cache exists', function(done){

var notice, watcher, options,
Expand Down Expand Up @@ -227,7 +311,62 @@ describe('Noticeboard Test Suite', function(){

watcher_list = test_board.watchers[notice];
assert.equal(typeof watcher_list[watcher] === "undefined", true, 'watcher hasn\'t been removed from watcher list');
});
});

it('"ignore" returns false if watcher does not exist', function(){

var notice, watcher,
watcher_removed;

notice = 'non-existent-notice';
watcher = 'test-suite';

watcher_removed = test_board.ignore(notice, watcher);

assert.equal(watcher_removed, false, 'returned true even though watcher did not exist prior to execution');
});

it('"ignore" will return false if notice id is not a string', function(){

var result;

result = test_board.ignore(1, 'watcher-id');

assert.equal( result, false, 'Ignore sucessful even though notice id is a number');

result = test_board.ignore([], 'watcher-id');

assert.equal( result, false, 'Ignore sucessful even though notice id is an array');

result = test_board.ignore({}, 'watcher-id');

assert.equal( result, false, 'Ignore sucessful even though notice id is an object');

result = test_board.ignore(null, 'watcher-id');

assert.equal( result, false, 'Ignore sucessful even though notice id is null');
});

it('"ignore" will return false if watcher id is not a string', function(){

var result;

result = test_board.ignore('notice-id', 1);

assert.equal( result, false, 'Ignore sucessful even though watcher id is a number');

result = test_board.ignore('notice-id', []);

assert.equal( result, false, 'Ignore sucessful even though watcher id is an array');

result = test_board.ignore('notice-id', {});

assert.equal( result, false, 'Ignore sucessful even though watcher id is an object');

result = test_board.ignore('notice-id', null);

assert.equal( result, false, 'Ignore sucessful even though watcher id is null');
});

it('"once" ignores a notice after its callback has been fired', function(done){

Expand Down Expand Up @@ -302,13 +441,15 @@ describe('Noticeboard Test Suite', function(){

beforeEach(function(){

// drop all watchers
for(var watcher in test_board.watchers){
test_board = new Noticeboard({ logging: true, logOps: true });

if( !test_board.watchers.hasOwnProperty(watcher) ){ continue; }
// // drop all watchers
// for(var watcher in test_board.watchers){

delete test_board.watchers[watcher];
}
// if( !test_board.watchers.hasOwnProperty(watcher) ){ continue; }

// delete test_board.watchers[watcher];
// }
});

it('"settings.logOps" determines if noticeboard operations send "log-entry" notices', function(done){
Expand Down

0 comments on commit e29f733

Please sign in to comment.