Skip to content

Commit

Permalink
Allow empty messages for kannel and shaqodoon
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Aug 24, 2017
1 parent 6385731 commit e670898
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions handlers/kannel/kannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}

Expand Down
5 changes: 4 additions & 1 deletion handlers/kannel/kannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`},
Expand Down
2 changes: 1 addition & 1 deletion handlers/shaqodoon/shaqodoon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
5 changes: 4 additions & 1 deletion handlers/shaqodoon/shaqodoon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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"},
}
Expand Down

0 comments on commit e670898

Please sign in to comment.