@@ -24,7 +24,11 @@ describe('constructor', () => {
2424 assert . equal ( channel . state , 'closed' )
2525 assert . equal ( channel . topic , 'topic' )
2626 assert . deepEqual ( channel . params , {
27- config : { broadcast : { ack : false , self : false } , presence : { key : '' } , private : false } ,
27+ config : {
28+ broadcast : { ack : false , self : false } ,
29+ presence : { key : '' } ,
30+ private : false ,
31+ } ,
2832 one : 'two' ,
2933 } )
3034 assert . deepEqual ( channel . socket , socket )
@@ -40,7 +44,11 @@ describe('constructor', () => {
4044
4145 assert . deepEqual ( joinPush . channel , channel )
4246 assert . deepEqual ( joinPush . payload , {
43- config : { broadcast : { ack : false , self : false } , presence : { key : '' } , private : false } ,
47+ config : {
48+ broadcast : { ack : false , self : false } ,
49+ presence : { key : '' } ,
50+ private : false ,
51+ } ,
4452 one : 'two' ,
4553 } )
4654 assert . equal ( joinPush . event , 'phx_join' )
@@ -1232,7 +1240,7 @@ describe('send', () => {
12321240 socket = new RealtimeClient ( 'ws://localhost:4000/socket' , {
12331241 params : { apikey : 'abc123' } ,
12341242 } )
1235- channel = socket . channel ( 'topic' , { one : 'two' } )
1243+ channel = socket . channel ( 'topic' , { one : 'two' , config : { private : true } } )
12361244 } )
12371245
12381246 afterEach ( ( ) => {
@@ -1275,6 +1283,16 @@ describe('send', () => {
12751283 } )
12761284
12771285 it ( 'sends message via http request to Broadcast endpoint when not subscribed to channel' , async ( ) => {
1286+ const expectedBody = {
1287+ method : 'POST' ,
1288+ headers : {
1289+ Authorization : 'Bearer abc123' ,
1290+ apikey : 'abc123' ,
1291+ 'Content-Type' : 'application/json' ,
1292+ } ,
1293+ body : '{"messages":[{"topic":"topic","event":"test","private":true}]}' ,
1294+ }
1295+
12781296 pushStub = sinon . stub ( channel , '_fetchWithTimeout' )
12791297 pushStub . returns ( new Response ( ) )
12801298
@@ -1285,7 +1303,12 @@ describe('send', () => {
12851303 } )
12861304
12871305 assert . equal ( res , 'ok' )
1288- assert . ok ( pushStub . calledOnceWith ( 'http://localhost:4000/api/broadcast' ) )
1306+ assert . ok (
1307+ pushStub . calledOnceWith (
1308+ 'http://localhost:4000/api/broadcast' ,
1309+ expectedBody
1310+ )
1311+ )
12891312 } )
12901313} )
12911314
0 commit comments