diff --git a/handlers/kannel/kannel.go b/handlers/kannel/kannel.go index 90230a60e..d5e435f2d 100644 --- a/handlers/kannel/kannel.go +++ b/handlers/kannel/kannel.go @@ -53,7 +53,7 @@ func (h *handler) ReceiveMessage(channel courier.Channel, w http.ResponseWriter, kannelMsg := &kannelMessage{} err := handlers.DecodeAndValidateQueryParams(kannelMsg, r) if err != nil { - return nil, err + return nil, courier.WriteError(w, r, err) } // create our date from the timestamp @@ -77,7 +77,7 @@ func (h *handler) ReceiveMessage(channel courier.Channel, w http.ResponseWriter, type kannelMessage struct { ID string `validate:"required" name:"id"` Timestamp int64 `validate:"required" name:"ts"` - Message string `validate:"required" name:"message"` + Message string `name:"message"` Sender string `validate:"required" name:"sender"` } diff --git a/handlers/kannel/kannel_test.go b/handlers/kannel/kannel_test.go index 3625807d0..5634da1fa 100644 --- a/handlers/kannel/kannel_test.go +++ b/handlers/kannel/kannel_test.go @@ -12,6 +12,7 @@ import ( var ( receiveNoParams = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/" receiveValidMessage = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?backend=NIG_MTN&sender=%2B2349067554729&message=Join&ts=1493735509&id=asdf-asdf&to=24453" + receiveEmptyMessage = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?backend=NIG_MTN&sender=%2B2349067554729&message=&ts=1493735509&id=asdf-asdf&to=24453" statusNoParams = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status/" statusInvalidStatus = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status/?id=12345&status=66" statusValid = "/c/kn/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/status/?id=12345&status=4" @@ -24,7 +25,9 @@ var testChannels = []courier.Channel{ var handleTestCases = []ChannelHandleTestCase{ {Label: "Receive Valid Message", URL: receiveValidMessage, Data: "empty", Status: 200, Response: "Accepted", Text: Sp("Join"), URN: Sp("tel:+2349067554729"), External: Sp("asdf-asdf"), Date: Tp(time.Date(2017, 5, 2, 14, 31, 49, 0, time.UTC))}, - {Label: "Receive No Params", URL: receiveNoParams, Data: "empty", Status: 400, Response: "field 'message' required"}, + {Label: "Receive Empty Message", URL: receiveEmptyMessage, Data: "empty", Status: 200, Response: "Accepted", + Text: Sp(""), URN: Sp("tel:+2349067554729"), External: Sp("asdf-asdf"), Date: Tp(time.Date(2017, 5, 2, 14, 31, 49, 0, time.UTC))}, + {Label: "Receive No Params", URL: receiveNoParams, Data: "empty", Status: 400, Response: "field 'sender' required"}, {Label: "Status No Params", URL: statusNoParams, Status: 400, Response: "field 'status' required"}, {Label: "Status Invalid Status", URL: statusInvalidStatus, Status: 400, Response: "unknown status '66', must be one of 1,2,4,8,16"}, {Label: "Status Valid", URL: statusValid, Status: 200, Response: `"status":"S"`}, diff --git a/handlers/shaqodoon/shaqodoon.go b/handlers/shaqodoon/shaqodoon.go index 9f25f00e5..063e04d98 100644 --- a/handlers/shaqodoon/shaqodoon.go +++ b/handlers/shaqodoon/shaqodoon.go @@ -94,7 +94,7 @@ func (h *handler) ReceiveMessage(channel courier.Channel, w http.ResponseWriter, type shaqodoonMessage struct { From string `name:"from"` - Text string `validate:"required" name:"text"` + Text string `name:"text"` Date string `name:"date"` Time string `name:"time"` } diff --git a/handlers/shaqodoon/shaqodoon_test.go b/handlers/shaqodoon/shaqodoon_test.go index 00555eae0..930d54848 100644 --- a/handlers/shaqodoon/shaqodoon_test.go +++ b/handlers/shaqodoon/shaqodoon_test.go @@ -11,6 +11,7 @@ import ( var ( receiveValidMessage = "/c/sq/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?from=%2B2349067554729&text=Join" + receiveEmptyMessage = "/c/sq/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?from=%2B2349067554729&text=" receiveValidMessageWithDate = "/c/sq/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?from=%2B2349067554729&text=Join&date=2017-06-23T12:30:00.500Z" receiveValidMessageWithTime = "/c/sq/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/?from=%2B2349067554729&text=Join&time=2017-06-23T12:30:00Z" receiveNoParams = "/c/sq/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/receive/" @@ -25,11 +26,13 @@ var testChannels = []courier.Channel{ var handleTestCases = []ChannelHandleTestCase{ {Label: "Receive Valid Message", URL: receiveValidMessage, Data: "empty", Status: 200, Response: "Accepted", Text: Sp("Join"), URN: Sp("tel:+2349067554729")}, + {Label: "Receive Empty Message", URL: receiveEmptyMessage, Data: "empty", Status: 200, Response: "Accepted", + Text: Sp(""), URN: Sp("tel:+2349067554729")}, {Label: "Receive Valid Message With Date", URL: receiveValidMessageWithDate, Data: "empty", Status: 200, Response: "Accepted", Text: Sp("Join"), URN: Sp("tel:+2349067554729"), Date: Tp(time.Date(2017, 6, 23, 12, 30, 0, int(500*time.Millisecond), time.UTC))}, {Label: "Receive Valid Message With Time", URL: receiveValidMessageWithTime, Data: "empty", Status: 200, Response: "Accepted", Text: Sp("Join"), URN: Sp("tel:+2349067554729"), Date: Tp(time.Date(2017, 6, 23, 12, 30, 0, 0, time.UTC))}, - {Label: "Receive No Params", URL: receiveNoParams, Data: "empty", Status: 400, Response: "field 'text' required"}, + {Label: "Receive No Params", URL: receiveNoParams, Data: "empty", Status: 400, Response: "must have one of 'sender' or 'from' set"}, {Label: "Receive No Sender", URL: receiveNoSender, Data: "empty", Status: 400, Response: "must have one of 'sender' or 'from' set"}, {Label: "Receive Invalid Date", URL: receiveInvalidDate, Data: "empty", Status: 400, Response: "invalid date format, must be RFC 3339"}, }