Skip to content

Commit

Permalink
Fix callback URL and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 14, 2017
1 parent 6970f63 commit ad88d29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion handlers/twilio/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (h *handler) StatusMessage(channel courier.Channel, w http.ResponseWriter,
func (h *handler) SendMsg(msg courier.Msg) (courier.MsgStatus, error) {
// build our callback URL
callbackDomain := msg.Channel().CallbackDomain(h.Server().Config().Domain)
callbackURL := fmt.Sprintf("https://%s/c/t/%s/status?id=%d&action=callback", callbackDomain, msg.Channel().UUID(), msg.ID().Int64)
callbackURL := fmt.Sprintf("https://%s/c/%s/%s/status?id=%d&action=callback", callbackDomain, strings.ToLower(msg.Channel().ChannelType().String()), msg.Channel().UUID(), msg.ID().Int64)

accountSID := msg.Channel().StringConfigForKey(configAccountSID, "")
if accountSID == "" {
Expand Down
30 changes: 15 additions & 15 deletions handlers/twilio/twilio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var defaultSendTestCases = []ChannelSendTestCase{
Text: "Simple Message ☺", URN: "tel:+250788383383",
Status: "W", ExternalID: "1002",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "Simple Message ☺", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "Simple Message ☺", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
Path: "/Account/accountSID/Messages.json",
Headers: map[string]string{"Authorization": "Basic YWNjb3VudFNJRDphdXRoVG9rZW4="},
SendPrep: setSendURL},
Expand All @@ -138,40 +138,40 @@ var defaultSendTestCases = []ChannelSendTestCase{
URN: "tel:+250788383383",
Status: "W", ExternalID: "1002",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "I need to keep adding more things to make it work", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "I need to keep adding more things to make it work", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
Path: "/Account/accountSID/Messages.json",
Headers: map[string]string{"Authorization": "Basic YWNjb3VudFNJRDphdXRoVG9rZW4="},
SendPrep: setSendURL},
{Label: "Error Sending",
Text: "Error Message", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ "error": "out of credits" }`, ResponseStatus: 401,
PostParams: map[string]string{"Body": "Error Message", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "Error Message", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Error Code",
Text: "Error Code", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ "code": 1001 }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "Error Code", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "Error Code", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Stopped Contact Code",
Text: "Stopped Contact", URN: "tel:+250788383383",
Status: "F",
ResponseBody: `{ "code": 21610 }`, ResponseStatus: 400,
PostParams: map[string]string{"Body": "Stopped Contact", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "Stopped Contact", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
SendPrep: setSendURL,
Stopped: true},
{Label: "No SID",
Text: "No SID", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "No SID", "To": "+250788383383", "From": "2020"},
PostParams: map[string]string{"Body": "No SID", "To": "+250788383383", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Send Attachment",
Text: "My pic!", URN: "tel:+250788383383", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"},
Status: "W",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "My pic!", "To": "+250788383383", "MediaUrl": "https://foo.bar/image.jpg", "From": "2020"},
PostParams: map[string]string{"Body": "My pic!", "To": "+250788383383", "MediaUrl": "https://foo.bar/image.jpg", "From": "2020", "StatusCallback": "https://localhost/c/t/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status?id=10&action=callback"},
SendPrep: setSendURL},
}

Expand All @@ -180,7 +180,7 @@ var tmsDefaultSendTestCases = []ChannelSendTestCase{
Text: "Simple Message ☺", URN: "tel:+250788383383",
Status: "W", ExternalID: "1002",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "Simple Message ☺", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "Simple Message ☺", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
Path: "/Account/accountSID/Messages.json",
Headers: map[string]string{"Authorization": "Basic YWNjb3VudFNJRDphdXRoVG9rZW4="},
SendPrep: setSendURL},
Expand All @@ -189,40 +189,40 @@ var tmsDefaultSendTestCases = []ChannelSendTestCase{
URN: "tel:+250788383383",
Status: "W", ExternalID: "1002",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "I need to keep adding more things to make it work", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "I need to keep adding more things to make it work", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
Path: "/Account/accountSID/Messages.json",
Headers: map[string]string{"Authorization": "Basic YWNjb3VudFNJRDphdXRoVG9rZW4="},
SendPrep: setSendURL},
{Label: "Error Sending",
Text: "Error Message", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ "error": "out of credits" }`, ResponseStatus: 401,
PostParams: map[string]string{"Body": "Error Message", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "Error Message", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Error Code",
Text: "Error Code", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ "code": 1001 }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "Error Code", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "Error Code", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Stopped Contact Code",
Text: "Stopped Contact", URN: "tel:+250788383383",
Status: "F",
ResponseBody: `{ "code": 21610 }`, ResponseStatus: 400,
PostParams: map[string]string{"Body": "Stopped Contact", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "Stopped Contact", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
SendPrep: setSendURL,
Stopped: true},
{Label: "No SID",
Text: "No SID", URN: "tel:+250788383383",
Status: "E",
ResponseBody: `{ }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "No SID", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "No SID", "To": "+250788383383", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
SendPrep: setSendURL},
{Label: "Send Attachment",
Text: "My pic!", URN: "tel:+250788383383", Attachments: []string{"image/jpeg:https://foo.bar/image.jpg"},
Status: "W",
ResponseBody: `{ "sid": "1002" }`, ResponseStatus: 200,
PostParams: map[string]string{"Body": "My pic!", "To": "+250788383383", "MediaUrl": "https://foo.bar/image.jpg", "MessagingServiceSID": "messageServiceSID"},
PostParams: map[string]string{"Body": "My pic!", "To": "+250788383383", "MediaUrl": "https://foo.bar/image.jpg", "MessagingServiceSID": "messageServiceSID", "StatusCallback": "https://localhost/c/tms/8eb23e93-5ecb-45ba-b726-3b064e0c56cd/status?id=10&action=callback"},
SendPrep: setSendURL},
}

Expand All @@ -233,7 +233,7 @@ func TestSending(t *testing.T) {
configAccountSID: "accountSID",
courier.ConfigAuthToken: "authToken"})

var tmsDefaultChannel = courier.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "T", "2020", "US",
var tmsDefaultChannel = courier.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56cd", "TMS", "2021", "US",
map[string]interface{}{
configMessagingServiceSID: "messageServiceSID",
configAccountSID: "accountSID",
Expand Down

0 comments on commit ad88d29

Please sign in to comment.