all files / test/ tests.js

86.27% Statements 44/51
60% Branches 6/10
93.33% Functions 14/15
89.8% Lines 44/49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109                                                                                                                                  
var assert = require('assert');
 
var aws = require('aws-sdk');
 
var env = 'test';
var config = require('./unit-assets/config')[env];
var caniconfig = require('./unit-assets/Caniconfig');
 
var Cani = require('../cani');
 
 
// duplicate this for each module, pack the tests into the modules
// automate the testing of all of them?
 
var teststatus = '';
 
var tdata = require('./unit-assets/testdata');
 
describe('cani', function(){
 
    before(function(done){
	Cani.core.boot(caniconfig);
	done(null);
    });
 
 
/*
 
need to test:
cast
on
affirm
defirm
confirm
 
*/
    describe('cast', function(){
 
	describe('on, no flush', function(){
	    it('should call the callback properly when the notification is cast', function(done){
		
		var blah = Math.random();
		var times = 0;
 
		var fail = setTimeout(function(){
		    return done('notification callback flushed incorrectly');
		}, 2100);
 
		Cani.core.on('blah', function(asset){
		    Iif(blah !== asset) return done('asset not passed properly');
		    else if(++times === 2){
			clearTimeout(fail);
			return done(null);
		    }
		});
 
		Cani.core.cast('blah', false, blah);
		Cani.core.cast('blah', true, blah);
	    });
	});
 
	describe('on, flush', function(){
	    it('should call the callback properly when the notification is cast', function(done){
		
		var hmm = Math.random();
		var times = 0;
 
		var pass = setTimeout(function(){
		    return done(null);
		}, 1000);
 
		Cani.core.on('hmm', function(asset){
		    Iif(hmm !== asset){
			clearTimeout(pass);
			return done('asset not passed properly');
		    }
		    Iif(++times === 2){
			clearTimeout(pass);			
			return done('notification callback not flushed correctly');
		    }
		});
 
		Cani.core.cast('hmm', true, hmm);
		Cani.core.cast('hmm', true, hmm);
 
	    });
	});
    });
 
    describe('confirm', function(){
	describe('on, no flush', function(){
	    it('should stash the asset on affirm and resolve it on confirm', function(done){
		// do this test once for preregister, once for postregister
 
		var blah = Math.random();
 
		Cani.core.affirm('blah', blah);
 
		Cani.core.confirm('blah').then(function(asset){
		    Iif(blah !== asset) return done('asset not passed properly');
		    else return done(null);
		});
 
	    });
	});
    });
 
});