2013-09-05 02:57:56 +00:00
|
|
|
/* global describe, postal, it, after, before, expect, ChannelDefinition */
|
2012-10-26 05:17:15 +00:00
|
|
|
describe( "ChannelDefinition", function () {
|
|
|
|
|
describe( "When initializing a channel definition", function () {
|
2012-12-20 07:32:45 +00:00
|
|
|
var chDef = new ChannelDefinition( "TestChannel" );
|
2012-10-26 05:17:15 +00:00
|
|
|
it( "should set channel to TestChannel", function () {
|
|
|
|
|
expect( chDef.channel ).to.be( "TestChannel" );
|
2012-04-21 04:56:40 +00:00
|
|
|
} );
|
2012-10-26 05:17:15 +00:00
|
|
|
} );
|
|
|
|
|
describe( "When calling subscribe", function () {
|
2012-12-20 07:32:45 +00:00
|
|
|
var ch = new ChannelDefinition( "TestChannel" ),
|
2013-09-05 02:57:56 +00:00
|
|
|
sub = ch.subscribe( "TestTopic", function () {} );
|
2012-10-26 05:17:15 +00:00
|
|
|
it( "subscription should be instance of SubscriptionDefinition", function () {
|
|
|
|
|
expect( sub instanceof SubscriptionDefinition ).to.be.ok();
|
|
|
|
|
} );
|
|
|
|
|
} );
|
2013-09-05 02:57:56 +00:00
|
|
|
describe( "When publishing from a channel definition", function () {
|
2013-01-11 22:02:32 +00:00
|
|
|
var channel, subscription;
|
2013-09-05 02:57:56 +00:00
|
|
|
beforeEach( function () {
|
|
|
|
|
channel = postal.channel( "OhHai" );
|
|
|
|
|
} );
|
|
|
|
|
afterEach( function () {
|
2013-01-11 22:02:32 +00:00
|
|
|
postal.utils.reset();
|
|
|
|
|
channel = undefined;
|
|
|
|
|
subscription = undefined;
|
2013-09-05 02:57:56 +00:00
|
|
|
} );
|
|
|
|
|
it( "Should allow a topic only to be used", function ( done ) {
|
|
|
|
|
subscription = channel.subscribe( "topic.only", function ( d, e ) {
|
|
|
|
|
expect( typeof d === "undefined" ).to.be( true );
|
|
|
|
|
expect( e.topic ).to.be( "topic.only" );
|
|
|
|
|
done();
|
|
|
|
|
} );
|
|
|
|
|
channel.publish( "topic.only" );
|
|
|
|
|
} );
|
|
|
|
|
it( "Should allow a topic and data argument to be used", function ( done ) {
|
|
|
|
|
subscription = channel.subscribe( "topic.and.data", function ( d, e ) {
|
|
|
|
|
expect( d ).to.be( "hai" );
|
|
|
|
|
expect( e.topic ).to.be( "topic.and.data" );
|
|
|
|
|
done();
|
|
|
|
|
} );
|
|
|
|
|
channel.publish( "topic.and.data", "hai" );
|
|
|
|
|
} );
|
|
|
|
|
it( "Should allow an envelope argument to be used", function ( done ) {
|
|
|
|
|
subscription = channel.subscribe( "envelope", function ( d, e ) {
|
|
|
|
|
expect( e.channel ).to.be( "OhHai" );
|
|
|
|
|
expect( e.data ).to.be( "hai" );
|
|
|
|
|
expect( e.foo ).to.be( "bar" );
|
|
|
|
|
done();
|
|
|
|
|
} );
|
|
|
|
|
channel.publish( { topic : "envelope", data : "hai", foo : "bar" } );
|
|
|
|
|
} );
|
|
|
|
|
} );
|
2012-04-21 04:56:40 +00:00
|
|
|
} );
|