Skip to content

Commit

Permalink
Merge pull request #649 from nyaruka/update_goflow
Browse files Browse the repository at this point in the history
Update to latest goflow and gocommon
  • Loading branch information
rowanseymour authored Aug 5, 2022
2 parents 7465550 + 777c741 commit c24b5c6
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 88 deletions.
4 changes: 2 additions & 2 deletions core/goflow/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestEngineWebhook(t *testing.T) {

defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, "OK")},
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, []byte("OK"))},
}))

request, err := http.NewRequest("GET", "http://rapidpro.io", nil)
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestSimulatorWebhook(t *testing.T) {

defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, "OK")},
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, []byte("OK"))},
}))

request, err := http.NewRequest("GET", "http://rapidpro.io", nil)
Expand Down
6 changes: 3 additions & 3 deletions core/handlers/airtime_transferred_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ func TestAirtimeTransferred(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://dvs-api.dtone.com/v1/lookup/mobile-number/+16055741111": {
httpx.NewMockResponse(200, nil, lookupNumberResponse), // successful mobile number lookup
httpx.NewMockResponse(200, nil, []byte(lookupNumberResponse)), // successful mobile number lookup
},
"https://dvs-api.dtone.com/v1/products?type=FIXED_VALUE_RECHARGE&operator_id=1596&per_page=100": {
httpx.NewMockResponse(200, nil, productsResponse),
httpx.NewMockResponse(200, nil, []byte(productsResponse)),
},
"https://dvs-api.dtone.com/v1/sync/transactions": {
httpx.NewMockResponse(200, nil, transactionRejectedResponse),
httpx.NewMockResponse(200, nil, []byte(transactionRejectedResponse)),
},
"https://dvs-api.dtone.com/v1/lookup/mobile-number/+16055743333": {
httpx.MockConnectionError, // timeout x 3 retries
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/service_called_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestServiceCalled(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.wit.ai/message?v=20200513&q=book+me+a+flight": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"text": "I want to book a flight to Quito",
"intents": [
{
Expand All @@ -29,7 +29,7 @@ func TestServiceCalled(t *testing.T) {
"confidence": 0.9024
}
]
}`),
}`)),
},
}))

Expand Down
8 changes: 4 additions & 4 deletions core/handlers/ticket_opened_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func TestTicketOpened(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
"https://nyaruka.zendesk.com/api/v2/any_channel/push.json": {
httpx.NewMockResponse(201, nil, `{
httpx.NewMockResponse(201, nil, []byte(`{
"results": [
{
"external_resource_id": "123",
"status": {"code": "success"}
}
]
}`),
}`)),
},
}))

Expand Down
10 changes: 5 additions & 5 deletions core/handlers/webhook_called_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func TestWebhookCalled(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"http://rapidpro.io/": {
httpx.NewMockResponse(200, nil, "OK"),
httpx.NewMockResponse(200, nil, "OK"),
httpx.NewMockResponse(200, nil, []byte("OK")),
httpx.NewMockResponse(200, nil, []byte("OK")),
},
"http://rapidpro.io/?unsub=1": {
httpx.NewMockResponse(410, nil, "Gone"),
httpx.NewMockResponse(410, nil, "Gone"),
httpx.NewMockResponse(410, nil, "Gone"),
httpx.NewMockResponse(410, nil, []byte("Gone")),
httpx.NewMockResponse(410, nil, []byte("Gone")),
httpx.NewMockResponse(410, nil, []byte("Gone")),
},
}))

Expand Down
6 changes: 3 additions & 3 deletions core/models/channel_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestChannelLogs(t *testing.T) {

defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, "OK")},
"http://rapidpro.io/bad": {httpx.NewMockResponse(400, nil, "Oops")},
"http://rapidpro.io/new": {httpx.NewMockResponse(200, nil, "OK")},
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, []byte("OK"))},
"http://rapidpro.io/bad": {httpx.NewMockResponse(400, nil, []byte("Oops"))},
"http://rapidpro.io/new": {httpx.NewMockResponse(200, nil, []byte("OK"))},
}))

oa, err := models.GetOrgAssets(ctx, rt, testdata.Org1.ID)
Expand Down
4 changes: 2 additions & 2 deletions core/models/http_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestHTTPLogger(t *testing.T) {
defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://temba.io": {
httpx.NewMockResponse(200, nil, `hello`),
httpx.NewMockResponse(400, nil, `world`),
httpx.NewMockResponse(200, nil, []byte(`hello`)),
httpx.NewMockResponse(400, nil, []byte(`world`)),
},
}))

Expand Down
8 changes: 4 additions & 4 deletions core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ func TestCloseTickets(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
}))

Expand Down Expand Up @@ -370,10 +370,10 @@ func TestReopenTickets(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
}))

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ require (
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.6
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.24.0
github.com/nyaruka/goflow v0.166.0
github.com/nyaruka/gocommon v1.25.0
github.com/nyaruka/goflow v0.167.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
github.com/nyaruka/redisx v0.2.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ 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.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.24.0 h1:zfluRa4h+Ms3hmed2vPov+PR/vWxtrTgBUEONRuuiIQ=
github.com/nyaruka/gocommon v1.24.0/go.mod h1:g6/d9drZXDUrtRSPe2Kf8lTUS+baHt/0G0dwHq3qeIU=
github.com/nyaruka/goflow v0.166.0 h1:Z/c9zXTwoDYA1jkkQXaoeymJ7uxV8fP0uuQbuICx89s=
github.com/nyaruka/goflow v0.166.0/go.mod h1:fvNZ3A3bCWyDqRhaRbJGeKYNaJpIAuEJGuqYFeWs0co=
github.com/nyaruka/gocommon v1.25.0 h1:/wi16Q9qUF3NOnRgM5q/c55dRtX0xLDHu7hDU0OTeWg=
github.com/nyaruka/gocommon v1.25.0/go.mod h1:g6/d9drZXDUrtRSPe2Kf8lTUS+baHt/0G0dwHq3qeIU=
github.com/nyaruka/goflow v0.167.0 h1:QumLikQm374tEl15MAwXTtryhByr+nvhYn5Az/DccVY=
github.com/nyaruka/goflow v0.167.0/go.mod h1:FIOgmEyu+fL6eupQ26hHePjCVTXZ4cuHQwFuQsmcuXE=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand Down
2 changes: 1 addition & 1 deletion services/ivr/vonage/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestResponseForSprint(t *testing.T) {
defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.nexmo.com/v1/calls": {
httpx.NewMockResponse(201, nil, `{"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356", "status": "started", "direction": "outbound"}`),
httpx.NewMockResponse(201, nil, []byte(`{"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356", "status": "started", "direction": "outbound"}`)),
},
}))

Expand Down
8 changes: 4 additions & 4 deletions services/tickets/mailgun/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func TestSendMessage(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.MockConnectionError,
httpx.NewMockResponse(400, nil, `{"message": "Something went wrong"}`), // non-200 response
httpx.NewMockResponse(200, nil, `xx`), // non-JSON response
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(400, nil, []byte(`{"message": "Something went wrong"}`)), // non-200 response
httpx.NewMockResponse(200, nil, []byte(`xx`)), // non-JSON response
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
}))
uuids.SetGenerator(uuids.NewSeededGenerator(12345))
Expand Down
22 changes: 11 additions & 11 deletions services/tickets/mailgun/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ func TestOpenAndForward(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.MockConnectionError,
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
httpx.NewMockResponse(200, nil, `{
}`)),
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
"http://myfiles.com/media/0123/attachment1.jpg": {
httpx.NewMockResponse(200, map[string]string{"Content-Type": "image/jpg"}, `MYIMAGE`),
httpx.NewMockResponse(200, map[string]string{"Content-Type": "image/jpg"}, []byte(`MYIMAGE`)),
},
}))

Expand Down Expand Up @@ -126,18 +126,18 @@ func TestCloseAndReopen(t *testing.T) {
uuids.SetGenerator(uuids.NewSeededGenerator(12345))
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
httpx.NewMockResponse(200, nil, `{
}`)),
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
httpx.NewMockResponse(200, nil, `{
}`)),
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
}))

Expand Down
19 changes: 10 additions & 9 deletions services/tickets/rocketchat/client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package rocketchat_test

import (
"net/http"
"testing"

"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/mailroom/services/tickets/rocketchat"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

const (
Expand All @@ -19,8 +20,8 @@ func TestCreateRoom(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/room": {
httpx.MockConnectionError,
httpx.NewMockResponse(400, nil, `{ "error": "There's no agents online" }`),
httpx.NewMockResponse(201, nil, `{ "id": "uiF7ybjsv7PSJGSw6" }`),
httpx.NewMockResponse(400, nil, []byte(`{ "error": "There's no agents online" }`)),
httpx.NewMockResponse(201, nil, []byte(`{ "id": "uiF7ybjsv7PSJGSw6" }`)),
},
}))

Expand All @@ -33,7 +34,7 @@ func TestCreateRoom(t *testing.T) {
Email: "bob@acme.com",
Phone: "+16055741111",
},
TicketID: "88ff1e41-c1f8-4637-af8e-d56acbde9171",
TicketID: "88ff1e41-c1f8-4637-af8e-d56acbde9171",
}

_, _, err := client.CreateRoom(room)
Expand All @@ -54,8 +55,8 @@ func TestCloseRoom(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/room.close": {
httpx.MockConnectionError,
httpx.NewMockResponse(400, nil, `{ "error": "Could not find a room for visitor token: 1234" }`),
httpx.NewMockResponse(204, nil, ``),
httpx.NewMockResponse(400, nil, []byte(`{ "error": "Could not find a room for visitor token: 1234" }`)),
httpx.NewMockResponse(204, nil, nil),
},
}))

Expand All @@ -79,8 +80,8 @@ func TestSendMessage(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/visitor-message": {
httpx.MockConnectionError,
httpx.NewMockResponse(400, nil, `{ "error": "Could not find a room for visitor token: 1234" }`),
httpx.NewMockResponse(201, nil, `{ "id": "tyLrD97j8TFZmT3Y6" }`),
httpx.NewMockResponse(400, nil, []byte(`{ "error": "Could not find a room for visitor token: 1234" }`)),
httpx.NewMockResponse(201, nil, []byte(`{ "id": "tyLrD97j8TFZmT3Y6" }`)),
},
}))

Expand Down
8 changes: 4 additions & 4 deletions services/tickets/rocketchat/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func TestOpenAndForward(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/room": {
httpx.MockConnectionError,
httpx.NewMockResponse(201, nil, `{ "id": "uiF7ybjsv7PSJGSw6" }`),
httpx.NewMockResponse(201, nil, []byte(`{ "id": "uiF7ybjsv7PSJGSw6" }`)),
},
baseURL + "/visitor-message": {
httpx.MockConnectionError,
httpx.NewMockResponse(201, nil, `{ "id": "tyLrD97j8TFZmT3Y6" }`),
httpx.NewMockResponse(201, nil, []byte(`{ "id": "tyLrD97j8TFZmT3Y6" }`)),
},
}))

Expand Down Expand Up @@ -118,8 +118,8 @@ func TestCloseAndReopen(t *testing.T) {
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
baseURL + "/room.close": {
httpx.MockConnectionError,
httpx.NewMockResponse(204, nil, ``),
httpx.NewMockResponse(204, nil, ``),
httpx.NewMockResponse(204, nil, nil),
httpx.NewMockResponse(204, nil, nil),
},
}))

Expand Down
4 changes: 2 additions & 2 deletions services/tickets/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func TestCloseTicket(t *testing.T) {

httpx.SetRequestor(httpx.NewMockRequestor(map[string][]httpx.MockResponse{
"https://api.mailgun.net/v3/tickets.rapidpro.io/messages": {
httpx.NewMockResponse(200, nil, `{
httpx.NewMockResponse(200, nil, []byte(`{
"id": "<20200426161758.1.590432020254B2BF@tickets.rapidpro.io>",
"message": "Queued. Thank you."
}`),
}`)),
},
}))

Expand Down
Loading

0 comments on commit c24b5c6

Please sign in to comment.