@@ -177,19 +177,19 @@ describe('BootBot', () => {
177177 const spy = sinon . spy ( bot , 'sendRequest' ) ;
178178 const elements = [
179179 {
180- "title" :"Welcome to Peter\'s Hats" ,
181- "image_url" :"http://petersapparel.parseapp.com/img/item100-thumb.png" ,
182- "subtitle" :"We\'ve got the right hat for everyone." ,
183- "buttons" :[
180+ "title" : "Welcome to Peter\'s Hats" ,
181+ "image_url" : "http://petersapparel.parseapp.com/img/item100-thumb.png" ,
182+ "subtitle" : "We\'ve got the right hat for everyone." ,
183+ "buttons" : [
184184 {
185- "type" :"web_url" ,
186- "url" :"https://petersapparel.parseapp.com/view_item?item_id=100" ,
187- "title" :"View Website"
185+ "type" : "web_url" ,
186+ "url" : "https://petersapparel.parseapp.com/view_item?item_id=100" ,
187+ "title" : "View Website"
188188 } ,
189189 {
190- "type" :"postback" ,
191- "title" :"Start Chatting" ,
192- "payload" :"USER_DEFINED_PAYLOAD"
190+ "type" : "postback" ,
191+ "title" : "Start Chatting" ,
192+ "payload" : "USER_DEFINED_PAYLOAD"
193193 }
194194 ]
195195 }
@@ -234,4 +234,83 @@ describe('BootBot', () => {
234234 bot . sendAttachment ( userId , type , url ) ;
235235 expect ( spy . calledWith ( expected ) ) . to . equal ( true ) ;
236236 } ) ;
237- } ) ;
237+
238+ describe ( '_handleEvent' , ( ) => {
239+ let pageId = 123456 ;
240+
241+ it ( 'should set optin origin to send_to_messenger when sender exists' , ( ) => {
242+ const type = 'authentication' ;
243+ const event = {
244+ sender : {
245+ id : userId
246+ } ,
247+ recipient : {
248+ id : pageId
249+ } ,
250+ timestamp : 1234567890 ,
251+ optin : {
252+ ref : 'PASS_THROUGH_PARAM'
253+ }
254+ } ;
255+
256+ bot . _handleEvent ( type , event ) ;
257+ expect ( bot . optinOrigin ) . to . equal ( 'send_to_messenger' ) ;
258+ } ) ;
259+
260+ it ( 'should set optin origin to checkbox_plugin when sender not exists' , ( ) => {
261+ const type = 'authentication' ;
262+ const event = {
263+ recipient : {
264+ id : pageId
265+ } ,
266+ timestamp : 1234567890 ,
267+ optin : {
268+ ref : "PASS_THROUGH_PARAM" ,
269+ user_ref : userId
270+ }
271+ }
272+
273+ bot . _handleEvent ( type , event ) ;
274+ expect ( bot . optinOrigin ) . to . equal ( 'checkbox_plugin' ) ;
275+ } ) ;
276+
277+ it ( 'optin origin should be null when tpye is not authentication' , ( ) => {
278+ const type = 'read' ;
279+ const event = {
280+ sender : {
281+ id : userId
282+ } ,
283+ recipient : {
284+ id : pageId
285+ } ,
286+ timestamp : 1234567890 ,
287+ optin : {
288+ ref : 'PASS_THROUGH_PARAM'
289+ }
290+ } ;
291+
292+ bot . _handleEvent ( type , event ) ;
293+ expect ( bot . optinOrigin ) . to . be . null ;
294+ } ) ;
295+
296+ it ( 'should call emit once' , ( ) => {
297+ const spy = sinon . spy ( bot , 'emit' ) ;
298+ const type = 'read' ;
299+ const event = {
300+ sender : {
301+ id : userId
302+ } ,
303+ recipient : {
304+ id : pageId
305+ } ,
306+ timestamp : 1234567890 ,
307+ optin : {
308+ ref : 'PASS_THROUGH_PARAM'
309+ }
310+ } ;
311+
312+ bot . _handleEvent ( type , event ) ;
313+ expect ( spy . calledOnce ) . to . equal ( true ) ;
314+ } ) ;
315+ } ) ;
316+ } ) ;
0 commit comments