@@ -5,6 +5,7 @@ Bot = require '../src/xmpp'
55
66assert = require ' assert'
77sinon = require ' sinon'
8+ uuid = require ' uuid'
89
910describe ' XmppBot' , ->
1011 describe ' #parseRooms()' , ->
@@ -997,3 +998,89 @@ describe 'XmppBot', ->
997998
998999 mock .verify ()
9991000 assert .ok bot .robot .logger .error .called
1001+
1002+ describe ' uuid_on_join' , () ->
1003+ beforeEach ->
1004+ uuid[' v4' ] = () -> ' fake-uuid-for-testing'
1005+ process .env .HUBOT_XMPP_UUID_ON_JOIN = true
1006+
1007+ bot = Bot .use ()
1008+
1009+ bot .client =
1010+ stub : ' xmpp client'
1011+
1012+ bot .robot =
1013+ name : ' bot'
1014+ logger :
1015+ debug : () ->
1016+ info : () ->
1017+ brain :
1018+ userForId : (id , options )->
1019+ user = {}
1020+ user[' name' ] = id
1021+ for k of (options or {})
1022+ user[k] = options[k]
1023+ return user
1024+
1025+ room =
1026+ jid : ' test@example.com'
1027+ password : false
1028+
1029+ it ' should call @client.send() with a uuid' , (done ) ->
1030+ bot .client .send = (message ) ->
1031+ if message .name == ' body'
1032+ assert .equal message .children .length , 1
1033+ assert .equal message .children [0 ], ' fake-uuid-for-testing'
1034+ done ()
1035+ bot .joinRoom room
1036+
1037+ it ' should ignore messages' , (done ) ->
1038+ stanza =
1039+ attrs :
1040+ type : ' groupchat'
1041+ name : ' message'
1042+ flag : ' ignore_me'
1043+ proxied = bot .readMessage
1044+ bot .readMessage = (message ) ->
1045+ proxied (message)
1046+ if message .flag == ' ignore_me'
1047+ done ()
1048+ bot .receive = (message ) ->
1049+ throw ' no message should be received'
1050+ bot .read stanza
1051+
1052+ it ' listen for the uuid before responding' , (done ) ->
1053+ stanza =
1054+ attrs :
1055+ type : ' groupchat'
1056+ from : ' test@example.com/bot'
1057+ name : ' message'
1058+ flag : ' join_me'
1059+ getChild : ->
1060+ body =
1061+ getText : ->
1062+ ' fake-uuid-for-testing'
1063+ proxied = bot .readMessage
1064+ bot .readMessage = (message ) ->
1065+ proxied (message)
1066+ assert .equal true , ' test@example.com' in bot .joined
1067+ if message .flag == ' join_me'
1068+ done ()
1069+ bot .receive = (message ) ->
1070+ throw ' no message should be received'
1071+ bot .read stanza
1072+
1073+ it ' should process messages after joining' , (done ) ->
1074+ stanza =
1075+ attrs :
1076+ type : ' groupchat'
1077+ from : ' test@example.com/someone'
1078+ name : ' message'
1079+ getChild : ->
1080+ body =
1081+ getText : ->
1082+ ' @bot howdy'
1083+ bot .receive = (message ) ->
1084+ assert .equal message, ' @bot howdy'
1085+ done ()
1086+ bot .read stanza
0 commit comments