@@ -44,6 +44,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
4444 Attachments []utils.Attachment
4545 QuickReplies []string
4646 Topic flows.MsgTopic
47+ Unsendable flows.UnsendableReason
4748 Flow * testdata.Flow
4849 ResponseTo models.MsgID
4950 SuspendedOrg bool
@@ -120,6 +121,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
120121 Contact : testdata .Cathy ,
121122 URN : urns .NilURN ,
122123 URNID : models .URNID (0 ),
124+ Unsendable : flows .UnsendableReasonNoDestination ,
123125 Flow : testdata .Favorites ,
124126 ExpectedStatus : models .MsgStatusFailed ,
125127 ExpectedFailedReason : models .MsgFailedNoDestination ,
@@ -133,6 +135,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
133135 Contact : testdata .Cathy ,
134136 URN : urns .URN (fmt .Sprintf ("tel:+250700000001?id=%d" , testdata .Cathy .URNID )),
135137 URNID : testdata .Cathy .URNID ,
138+ Unsendable : flows .UnsendableReasonNoDestination ,
136139 Flow : testdata .Favorites ,
137140 ExpectedStatus : models .MsgStatusFailed ,
138141 ExpectedFailedReason : models .MsgFailedNoDestination ,
@@ -146,6 +149,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
146149 Contact : blake ,
147150 URN : urns .URN (fmt .Sprintf ("tel:+250700000007?id=%d" , blakeURNID )),
148151 URNID : blakeURNID ,
152+ Unsendable : flows .UnsendableReasonContactStatus ,
149153 Flow : testdata .Favorites ,
150154 ExpectedStatus : models .MsgStatusFailed ,
151155 ExpectedFailedReason : models .MsgFailedContact ,
@@ -158,6 +162,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
158162 now := time .Now ()
159163
160164 for _ , tc := range tcs {
165+ desc := fmt .Sprintf ("text='%s'" , tc .Text )
161166 db .MustExec (`UPDATE orgs_org SET is_suspended = $1 WHERE id = $2` , tc .SuspendedOrg , testdata .Org1 .ID )
162167
163168 oa , err := models .GetOrgAssetsWithRefresh (ctx , rt , testdata .Org1 .ID , models .RefreshOrg )
@@ -171,7 +176,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
171176 session .SetIncomingMsg (flows .MsgID (tc .ResponseTo ), null .NullString )
172177 }
173178
174- flowMsg := flows .NewMsgOut (tc .URN , assets .NewChannelReference (tc .ChannelUUID , "Test Channel" ), tc .Text , tc .Attachments , tc .QuickReplies , nil , tc .Topic )
179+ flowMsg := flows .NewMsgOut (tc .URN , assets .NewChannelReference (tc .ChannelUUID , "Test Channel" ), tc .Text , tc .Attachments , tc .QuickReplies , nil , tc .Topic , tc . Unsendable )
175180 msg , err := models .NewOutgoingFlowMsg (rt , oa .Org (), channel , session , flow , flowMsg , now )
176181
177182 assert .NoError (t , err )
@@ -191,8 +196,8 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
191196 }
192197 assert .Equal (t , tc .Flow .ID , msg .FlowID ())
193198
194- assert .Equal (t , tc .ExpectedStatus , msg .Status ())
195- assert .Equal (t , tc .ExpectedFailedReason , msg .FailedReason ())
199+ assert .Equal (t , tc .ExpectedStatus , msg .Status (), "status mismatch for %s" , desc )
200+ assert .Equal (t , tc .ExpectedFailedReason , msg .FailedReason (), "failed reason mismatch for %s" , desc )
196201 assert .Equal (t , tc .ExpectedMetadata , msg .Metadata ())
197202 assert .Equal (t , tc .ExpectedMsgCount , msg .MsgCount ())
198203 assert .Equal (t , now , msg .CreatedOn ())
@@ -216,7 +221,7 @@ func TestNewOutgoingFlowMsg(t *testing.T) {
216221
217222 // check that msg loop detection triggers after 20 repeats of the same text
218223 newOutgoing := func (text string ) * models.Msg {
219- flowMsg := flows .NewMsgOut (urns .URN (fmt .Sprintf ("tel:+250700000001?id=%d" , testdata .Cathy .URNID )), assets .NewChannelReference (testdata .TwilioChannel .UUID , "Twilio" ), text , nil , nil , nil , flows .NilMsgTopic )
224+ flowMsg := flows .NewMsgOut (urns .URN (fmt .Sprintf ("tel:+250700000001?id=%d" , testdata .Cathy .URNID )), assets .NewChannelReference (testdata .TwilioChannel .UUID , "Twilio" ), text , nil , nil , nil , flows .NilMsgTopic , flows . NilUnsendableReason )
220225 msg , err := models .NewOutgoingFlowMsg (rt , oa .Org (), channel , session , flow , flowMsg , now )
221226 require .NoError (t , err )
222227 return msg
@@ -261,6 +266,7 @@ func TestMarshalMsg(t *testing.T) {
261266 []string {"yes" , "no" },
262267 nil ,
263268 flows .MsgTopicPurchase ,
269+ flows .NilUnsendableReason ,
264270 )
265271
266272 // create a non-priority flow message.. i.e. the session isn't responding to an incoming message
@@ -318,6 +324,7 @@ func TestMarshalMsg(t *testing.T) {
318324 "Hi there" ,
319325 nil , nil , nil ,
320326 flows .NilMsgTopic ,
327+ flows .NilUnsendableReason ,
321328 )
322329 in1 := testdata .InsertIncomingMsg (db , testdata .Org1 , testdata .TwilioChannel , testdata .Cathy , "test" , models .MsgStatusHandled )
323330 session .SetIncomingMsg (flows .MsgID (in1 .ID ()), null .String ("EX123" ))
@@ -359,7 +366,7 @@ func TestMarshalMsg(t *testing.T) {
359366
360367 // try a broadcast message which won't have session and flow fields set
361368 bcastID := testdata .InsertBroadcast (db , testdata .Org1 , `eng` , map [envs.Language ]string {`eng` : "Blast" }, models .NilScheduleID , []* testdata.Contact {testdata .Cathy }, nil )
362- bcastMsg1 := flows .NewMsgOut (urn , assets .NewChannelReference (testdata .TwilioChannel .UUID , "Test Channel" ), "Blast" , nil , nil , nil , flows .NilMsgTopic )
369+ bcastMsg1 := flows .NewMsgOut (urn , assets .NewChannelReference (testdata .TwilioChannel .UUID , "Test Channel" ), "Blast" , nil , nil , nil , flows .NilMsgTopic , flows . NilUnsendableReason )
363370 msg3 , err := models .NewOutgoingBroadcastMsg (rt , oa .Org (), channel , cathy , bcastMsg1 , time .Date (2021 , 11 , 9 , 14 , 3 , 30 , 0 , time .UTC ), bcastID )
364371 require .NoError (t , err )
365372
@@ -492,8 +499,8 @@ func TestGetMsgRepetitions(t *testing.T) {
492499 oa := testdata .Org1 .Load (rt )
493500 _ , cathy := testdata .Cathy .Load (db , oa )
494501
495- msg1 := flows .NewMsgOut (testdata .Cathy .URN , nil , "foo" , nil , nil , nil , flows .NilMsgTopic )
496- msg2 := flows .NewMsgOut (testdata .Cathy .URN , nil , "bar" , nil , nil , nil , flows .NilMsgTopic )
502+ msg1 := flows .NewMsgOut (testdata .Cathy .URN , nil , "foo" , nil , nil , nil , flows .NilMsgTopic , flows . NilUnsendableReason )
503+ msg2 := flows .NewMsgOut (testdata .Cathy .URN , nil , "bar" , nil , nil , nil , flows .NilMsgTopic , flows . NilUnsendableReason )
497504
498505 assertRepetitions := func (m * flows.MsgOut , expected int ) {
499506 count , err := models .GetMsgRepetitions (rp , cathy , m )
@@ -660,12 +667,12 @@ func TestNewOutgoingIVR(t *testing.T) {
660667
661668 createdOn := time .Date (2021 , 7 , 26 , 12 , 6 , 30 , 0 , time .UTC )
662669
663- flowMsg := flows .NewMsgOut (testdata .Cathy .URN , vonage .ChannelReference (), "Hello" , []utils. Attachment { "audio/mp3: http://example.com/hi.mp3"}, nil , nil , flows . NilMsgTopic )
670+ flowMsg := flows .NewIVRMsgOut (testdata .Cathy .URN , vonage .ChannelReference (), "Hello" , "eng" , " http://example.com/hi.mp3" )
664671 dbMsg := models .NewOutgoingIVR (rt .Config , testdata .Org1 .ID , conn , flowMsg , createdOn )
665672
666673 assert .Equal (t , flowMsg .UUID (), dbMsg .UUID ())
667674 assert .Equal (t , "Hello" , dbMsg .Text ())
668- assert .Equal (t , []utils.Attachment {"audio/mp3 :http://example.com/hi.mp3" }, dbMsg .Attachments ())
675+ assert .Equal (t , []utils.Attachment {"audio:http://example.com/hi.mp3" }, dbMsg .Attachments ())
669676 assert .Equal (t , createdOn , dbMsg .CreatedOn ())
670677 assert .Equal (t , & createdOn , dbMsg .SentOn ())
671678
0 commit comments