Skip to content

Commit

Permalink
Merge pull request #602 from nyaruka/resend_fix
Browse files Browse the repository at this point in the history
Fix resend reponses when not all messages could be resent
  • Loading branch information
rowanseymour authored Mar 16, 2022
2 parents e6cf8ea + eabee9b commit fa60eaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion web/msg/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func handleResend(ctx context.Context, rt *runtime.Runtime, r *http.Request) (in

// response is the ids of the messages that were actually resent
resentMsgIDs := make([]flows.MsgID, len(resends))
for i, m := range msgs {
for i, m := range resends {
resentMsgIDs[i] = m.ID()
}
return map[string]interface{}{"msg_ids": resentMsgIDs}, http.StatusOK, nil
Expand Down
9 changes: 6 additions & 3 deletions web/msg/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ func TestServer(t *testing.T) {
cathyIn := testdata.InsertIncomingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "hello", models.MsgStatusHandled)
cathyOut := testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "how can we help", nil, models.MsgStatusSent, false)
bobOut := testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.VonageChannel, testdata.Bob, "this failed", nil, models.MsgStatusFailed, false)
georgeOut := testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.VonageChannel, testdata.George, "no URN", nil, models.MsgStatusFailed, false)
db.MustExec(`UPDATE msgs_msg SET contact_urn_id = NULL WHERE id = $1`, georgeOut.ID())

web.RunWebTests(t, ctx, rt, "testdata/resend.json", map[string]string{
"cathy_msgin_id": fmt.Sprintf("%d", cathyIn.ID()),
"cathy_msgout_id": fmt.Sprintf("%d", cathyOut.ID()),
"bob_msgout_id": fmt.Sprintf("%d", bobOut.ID()),
"cathy_msgin_id": fmt.Sprintf("%d", cathyIn.ID()),
"cathy_msgout_id": fmt.Sprintf("%d", cathyOut.ID()),
"bob_msgout_id": fmt.Sprintf("%d", bobOut.ID()),
"george_msgout_id": fmt.Sprintf("%d", georgeOut.ID()),
})
}
3 changes: 2 additions & 1 deletion web/msg/testdata/resend.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"msg_ids": [
$cathy_msgin_id$,
$cathy_msgout_id$,
$bob_msgout_id$
$bob_msgout_id$,
$george_msgout_id$
]
},
"status": 200,
Expand Down

0 comments on commit fa60eaf

Please sign in to comment.