Skip to content

Update gocommon #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/nyaruka/ezconf v0.3.0
github.com/nyaruka/gocommon v1.54.5
github.com/nyaruka/gocommon v1.54.6
github.com/nyaruka/null/v3 v3.0.0
github.com/nyaruka/redisx v0.8.0
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk=
github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU=
github.com/nyaruka/gocommon v1.54.5 h1:k5VXfXWZoE33wH/v5AgHQPbYjMBD6UsAz04uNnhp6bo=
github.com/nyaruka/gocommon v1.54.5/go.mod h1:rWkEIpYIK98zL9Qm6PeMXJ+84WcWlArf01RfuWWCYvQ=
github.com/nyaruka/gocommon v1.54.6 h1:cVe+d1upTLdNl/jIvpJhjcxrwsTYU7qGvhPckJsK1ig=
github.com/nyaruka/gocommon v1.54.6/go.mod h1:rWkEIpYIK98zL9Qm6PeMXJ+84WcWlArf01RfuWWCYvQ=
github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s=
github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE=
github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw=
Expand Down
50 changes: 40 additions & 10 deletions handlers/mblox/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var testChannels = []courier.Channel{
test.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "MB", "2020", "BR", map[string]any{"username": "zv-username", "password": "zv-password"}),
test.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "MB", "2020", "US", map[string]any{"username": "zv-username", "password": "zv-password"}),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@norkans7 so seems 12067799294 is a valid local Brazilian number.. and if you pass BR then gocommon currently gives you back +5512067799294 rather than +12067799294.. I think that's ok.. this is a weird test passing US numbers for BR channel.

I guess if we know a channel is giving us international numbers we could manually add + before parsing... or don't pass the channel country because the channel in that case doesn't really have a country.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the BR was from the test copied and pasted

}

var (
Expand Down Expand Up @@ -62,13 +62,31 @@ var (
)

var testCases = []IncomingTestCase{
{Label: "Receive Valid", URL: receiveURL, Data: validReceive, ExpectedRespStatus: 200, ExpectedBodyContains: "Message Accepted",
ExpectedMsgText: Sp("Hello World"), ExpectedURN: "tel:+12067799294", ExpectedDate: time.Date(2016, 3, 30, 19, 33, 06, 643000000, time.UTC),
ExpectedExternalID: "OzQ5UqIOdoY8"},

{Label: "Receive Missing Params", URL: receiveURL, Data: missingParamsRecieve, ExpectedRespStatus: 400, ExpectedBodyContains: "missing one of 'id', 'from', 'to', 'body' or 'received_at' in request body"},
{Label: "Invalid URN", URL: receiveURL, Data: invalidURN, ExpectedRespStatus: 400, ExpectedBodyContains: "phone number supplied is not a number"},

{
Label: "Receive Valid",
URL: receiveURL,
Data: validReceive,
ExpectedRespStatus: 200,
ExpectedBodyContains: "Message Accepted",
ExpectedMsgText: Sp("Hello World"),
ExpectedURN: "tel:+12067799294",
ExpectedDate: time.Date(2016, 3, 30, 19, 33, 06, 643000000, time.UTC),
ExpectedExternalID: "OzQ5UqIOdoY8",
},
{
Label: "Receive Missing Params",
URL: receiveURL,
Data: missingParamsRecieve,
ExpectedRespStatus: 400,
ExpectedBodyContains: "missing one of 'id', 'from', 'to', 'body' or 'received_at' in request body",
},
{
Label: "Invalid URN",
URL: receiveURL,
Data: invalidURN,
ExpectedRespStatus: 400,
ExpectedBodyContains: "phone number supplied is not a number",
},
{
Label: "Status Valid",
URL: receiveURL,
Expand All @@ -77,8 +95,20 @@ var testCases = []IncomingTestCase{
ExpectedBodyContains: `"status":"D"`,
ExpectedStatuses: []ExpectedStatus{{ExternalID: "12345", Status: courier.MsgStatusDelivered}},
},
{Label: "Status Unknown", URL: receiveURL, Data: unknownStatus, ExpectedRespStatus: 400, ExpectedBodyContains: `unknown status 'INVALID'`},
{Label: "Status Missing Batch ID", URL: receiveURL, Data: missingBatchID, ExpectedRespStatus: 400, ExpectedBodyContains: "missing one of 'batch_id' or 'status' in request body"},
{
Label: "Status Unknown",
URL: receiveURL,
Data: unknownStatus,
ExpectedRespStatus: 400,
ExpectedBodyContains: `unknown status 'INVALID'`,
},
{
Label: "Status Missing Batch ID",
URL: receiveURL,
Data: missingBatchID,
ExpectedRespStatus: 400,
ExpectedBodyContains: "missing one of 'batch_id' or 'status' in request body",
},
}

func TestIncoming(t *testing.T) {
Expand Down
Loading