From 88ad799d98106abf4fe8379b1b182c2df372aa56 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Fri, 24 Jun 2022 12:32:23 +0300 Subject: [PATCH] Adding missing field in SMS API (#119) * changed testdata messageObjectWithCreatedDatetime -> messageObjectWithScheduledDatetime * added missing fields * tests updated & added TestRead * update testdata * go version up * add read tests * add tests for Delete method * replace deprecated DialTLS with DialTLSContext * improve error_test * add GroupIds to messageRequest * add GroupIds to request and tests * remove bool in result of sms.Delete * update version to 8 * update client version --- .github/workflows/tests.yml | 2 +- UPGRADING.md | 5 + balance/balance.go | 2 +- balance/balance_test.go | 4 +- client.go | 2 +- contact/contact.go | 2 +- contact/contact_test.go | 2 +- conversation/api.go | 2 +- conversation/conversation.go | 2 +- conversation/conversation_test.go | 2 +- conversation/message.go | 2 +- conversation/message_test.go | 2 +- conversation/webhook.go | 2 +- conversation/webhook_test.go | 2 +- error_test.go | 18 +++ go.mod | 4 +- group/group.go | 4 +- group/group_test.go | 2 +- hlr/hlr.go | 2 +- hlr/hlr_test.go | 4 +- internal/mbtest/test_client.go | 2 +- internal/mbtest/test_server.go | 15 ++- lookup/lookup.go | 4 +- lookup/lookup_test.go | 4 +- mms/message.go | 2 +- mms/message_test.go | 4 +- number/number.go | 2 +- number/number_test.go | 2 +- recipient.go | 22 +++- signature_jwt/signature_test.go | 2 +- sms/message.go | 19 ++-- sms/message_test.go | 104 +++++++++++++++--- sms/testdata/binaryMessageObject.json | 7 +- sms/testdata/flashMessageObject.json | 7 +- sms/testdata/messageListObject.json | 36 +++++- sms/testdata/messageListScheduledObject.json | 45 ++++++-- sms/testdata/messageNotFound.json | 9 ++ sms/testdata/messageObject.json | 5 +- ...> messageObjectWithScheduledDatetime.json} | 7 +- sms/testdata/messageWithParamsObject.json | 5 +- sms/testdata/premiumMessageObject.json | 7 +- sms/testdata/readMessageObject.json | 43 ++++++++ sms/testdata/readScheduledMessageObject.json | 30 +++++ verify/verify.go | 2 +- verify/verify_test.go | 2 +- voice/call.go | 2 +- voice/callflow.go | 2 +- voice/leg.go | 2 +- voice/main_test.go | 2 +- voice/paginator.go | 2 +- voice/recording.go | 2 +- voice/recording_test.go | 2 +- voice/transcription.go | 2 +- voice/transcription_test.go | 2 +- voice/voice.go | 2 +- voice/voice_test.go | 2 +- voice/webhook.go | 2 +- voicemessage/voice_message.go | 2 +- voicemessage/voice_message_test.go | 4 +- 59 files changed, 375 insertions(+), 109 deletions(-) create mode 100644 sms/testdata/messageNotFound.json rename sms/testdata/{messageObjectWithCreatedDatetime.json => messageObjectWithScheduledDatetime.json} (78%) create mode 100644 sms/testdata/readMessageObject.json create mode 100644 sms/testdata/readScheduledMessageObject.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 209951e..2e62b01 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: true matrix: - go-version: [ 1.16.x, 1.17.x, 1.18.x] + go-version: [ 1.16.x, 1.17.x, 1.18.x ] name: Go ${{ matrix.go-version }} diff --git a/UPGRADING.md b/UPGRADING.md index 8049f0d..391b522 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -103,3 +103,8 @@ So all imports of `go-rest-api` are replaced as `go-rest-api/v6`. ## `v6.1.0` -> `v7.0.0` ### Verify Recipient type As v7 introduces support for using the Verify API with email recipients, the `Verify.Recipient` field has been changed from to a string type. + +## `v7.1.0` -> `v8.0.0` +### Update SMS API +Added [missed fields](https://github.com/messagebird/go-rest-api/pull/119/commits/f9331269238f1518dd35d798a0fbf251bb04bb62) in SMS API. +Updated `sms.Delete` method so now in return only error or nil as result. diff --git a/balance/balance.go b/balance/balance.go index 78728d8..7bd73d9 100644 --- a/balance/balance.go +++ b/balance/balance.go @@ -3,7 +3,7 @@ package balance import ( "net/http" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // Balance describes your balance information. diff --git a/balance/balance_test.go b/balance/balance_test.go index 0373733..2d4979a 100644 --- a/balance/balance_test.go +++ b/balance/balance_test.go @@ -4,8 +4,8 @@ import ( "net/http" "testing" - messagebird "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + messagebird "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/client.go b/client.go index 13b3ce9..cefc866 100644 --- a/client.go +++ b/client.go @@ -26,7 +26,7 @@ import ( const ( // ClientVersion is used in User-Agent request header to provide server with API level. - ClientVersion = "7.1.0" + ClientVersion = "8.0.0" // Endpoint points you to MessageBird REST API. Endpoint = "https://rest.messagebird.com" diff --git a/contact/contact.go b/contact/contact.go index 5b24d06..9cffda1 100644 --- a/contact/contact.go +++ b/contact/contact.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // Contact gets returned by the API. diff --git a/contact/contact_test.go b/contact/contact_test.go index a87d7f6..bf2aacc 100644 --- a/contact/contact_test.go +++ b/contact/contact_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" ) func TestMain(m *testing.M) { diff --git a/conversation/api.go b/conversation/api.go index 81b26da..b3e1286 100644 --- a/conversation/api.go +++ b/conversation/api.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) const ( diff --git a/conversation/conversation.go b/conversation/conversation.go index 63276fb..539b4e8 100644 --- a/conversation/conversation.go +++ b/conversation/conversation.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // ListOptions can be used to set pagination options in List(). diff --git a/conversation/conversation_test.go b/conversation/conversation_test.go index 641df0e..6bce29b 100644 --- a/conversation/conversation_test.go +++ b/conversation/conversation_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/conversation/message.go b/conversation/message.go index 68fe650..600c55c 100644 --- a/conversation/message.go +++ b/conversation/message.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) type MessageCreateRequest struct { diff --git a/conversation/message_test.go b/conversation/message_test.go index 4c75a9f..b8f89f5 100644 --- a/conversation/message_test.go +++ b/conversation/message_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/conversation/webhook.go b/conversation/webhook.go index cb34ca5..868a29b 100644 --- a/conversation/webhook.go +++ b/conversation/webhook.go @@ -3,7 +3,7 @@ package conversation import ( "net/http" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) type WebhookCreateRequest struct { diff --git a/conversation/webhook_test.go b/conversation/webhook_test.go index 3e0b4a8..f7241cf 100644 --- a/conversation/webhook_test.go +++ b/conversation/webhook_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/error_test.go b/error_test.go index eb59d98..5148d51 100644 --- a/error_test.go +++ b/error_test.go @@ -37,3 +37,21 @@ func TestError(t *testing.T) { assert.Error(t, errRes) }) } + +func TestErrorWithEmptyErrors(t *testing.T) { + errRes := ErrorResponse{} + assert.Error(t, errRes) + assert.Equal(t, "API errors: ", errRes.Error()) +} + +func TestErrorWithOneEmptyError(t *testing.T) { + errRes := ErrorResponse{Errors: []Error{ + { + Code: 11, + Description: "", + Parameter: "", + }, + }} + assert.Error(t, errRes) + assert.Equal(t, "API errors: ", errRes.Error()) +} diff --git a/go.mod b/go.mod index d33301a..40140cf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/messagebird/go-rest-api/v7 +module github.com/messagebird/go-rest-api/v8 -go 1.14 +go 1.16 require ( github.com/golang-jwt/jwt v3.2.1+incompatible diff --git a/group/group.go b/group/group.go index 45fb5d3..7efc492 100644 --- a/group/group.go +++ b/group/group.go @@ -9,8 +9,8 @@ import ( "strings" "time" - messagebird "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/contact" + messagebird "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/contact" ) // Group gets returned by the API. diff --git a/group/group_test.go b/group/group_test.go index 8f4ed6d..d2f12ec 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/hlr/hlr.go b/hlr/hlr.go index 266caaa..a10c1bc 100644 --- a/hlr/hlr.go +++ b/hlr/hlr.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // HLR stands for Home Location Register. Contains information about the diff --git a/hlr/hlr_test.go b/hlr/hlr_test.go index d5436e5..5a3b0ef 100644 --- a/hlr/hlr_test.go +++ b/hlr/hlr_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/internal/mbtest/test_client.go b/internal/mbtest/test_client.go index 5cb60ef..bad3d58 100644 --- a/internal/mbtest/test_client.go +++ b/internal/mbtest/test_client.go @@ -7,7 +7,7 @@ import ( "net/http" "testing" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // testWriter can be used to have the client write to the tests's error log. diff --git a/internal/mbtest/test_server.go b/internal/mbtest/test_server.go index 19fed8d..9e8c1bf 100644 --- a/internal/mbtest/test_server.go +++ b/internal/mbtest/test_server.go @@ -1,6 +1,7 @@ package mbtest import ( + "context" "crypto/tls" "io/ioutil" "net" @@ -72,6 +73,13 @@ func WillReturn(b []byte, s int) { status = s } +// WillReturnOnlyStatus sets the response status (s) to be returned by the +// server for incoming requests. +func WillReturnOnlyStatus(s int) { + responseBody = []byte{} + status = s +} + // WillReturnTestdata sets the status (s) for the test server to respond with. // Additionally it reads the bytes from the relativePath file and returns that // for requests. It fails the test if the file can not be read. The path is @@ -102,10 +110,11 @@ func HTTPTestTransport(handler http.Handler) (*http.Transport, func()) { s := httptest.NewTLSServer(handler) transport := &http.Transport{ - DialTLS: func(network, _ string) (net.Conn, error) { - return tls.Dial(network, s.Listener.Addr().String(), &tls.Config{ + DialTLSContext: func(ctx context.Context, network, _ string) (net.Conn, error) { + d := &tls.Dialer{Config: &tls.Config{ InsecureSkipVerify: true, - }) + }} + return d.DialContext(ctx, network, s.Listener.Addr().String()) }, } diff --git a/lookup/lookup.go b/lookup/lookup.go index 7178e28..84acf68 100644 --- a/lookup/lookup.go +++ b/lookup/lookup.go @@ -4,8 +4,8 @@ import ( "net/http" "net/url" - messagebird "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/hlr" + messagebird "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/hlr" ) // Formats represents phone number in multiple formats. diff --git a/lookup/lookup_test.go b/lookup/lookup_test.go index 52d1d72..b73a4af 100644 --- a/lookup/lookup_test.go +++ b/lookup/lookup_test.go @@ -5,8 +5,8 @@ import ( "strconv" "testing" - "github.com/messagebird/go-rest-api/v7/hlr" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/hlr" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/mms/message.go b/mms/message.go index be50573..8fee1fb 100644 --- a/mms/message.go +++ b/mms/message.go @@ -7,7 +7,7 @@ import ( "strings" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // Message represents a MMS Message. diff --git a/mms/message_test.go b/mms/message_test.go index 94ef50e..dda8fad 100644 --- a/mms/message_test.go +++ b/mms/message_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - messagebird "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + messagebird "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/number/number.go b/number/number.go index e7381ca..b1afff5 100644 --- a/number/number.go +++ b/number/number.go @@ -6,7 +6,7 @@ import ( "net/url" "strconv" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) const ( diff --git a/number/number_test.go b/number/number_test.go index 82487ed..34b95e8 100644 --- a/number/number_test.go +++ b/number/number_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/recipient.go b/recipient.go index 2803c98..2719f32 100644 --- a/recipient.go +++ b/recipient.go @@ -4,9 +4,25 @@ import "time" // Recipient struct holds information for a single msisdn with status details. type Recipient struct { - Recipient int64 - Status string - StatusDatetime *time.Time + Recipient int64 + Status string + StatusDatetime *time.Time + RecipientCountry *string + RecipientCountryPrefix *int + RecipientOperator *string + MessageLength *int + StatusErrorCode *int + StatusReason *string + Price *Price + Mccmnc *string + Mcc *string + Mnc *string + MessagePartCount int +} + +type Price struct { + Amount int + Currency string } // Recipients holds a collection of Recepient structs along with send stats. diff --git a/signature_jwt/signature_test.go b/signature_jwt/signature_test.go index d821bbc..a573ed4 100644 --- a/signature_jwt/signature_test.go +++ b/signature_jwt/signature_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/sms/message.go b/sms/message.go index f60a535..a63945c 100644 --- a/sms/message.go +++ b/sms/message.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // TypeDetails is a hash with extra information. @@ -46,6 +46,7 @@ type MessageList struct { // Params provide additional message send options and used in URL as params. type Params struct { + GroupIds []string Type string Reference string Validity int @@ -71,6 +72,7 @@ type messageRequest struct { Originator string `json:"originator"` Body string `json:"body"` Recipients []string `json:"recipients"` + GroupIds []string `json:"groupIds"` Type string `json:"type,omitempty"` Reference string `json:"reference,omitempty"` Validity int `json:"validity,omitempty"` @@ -78,9 +80,9 @@ type messageRequest struct { TypeDetails TypeDetails `json:"typeDetails,omitempty"` DataCoding string `json:"datacoding,omitempty"` MClass int `json:"mclass,omitempty"` + ShortenURLs bool `json:"shortenUrls"` ReportURL string `json:"reportUrl,omitempty"` ScheduledDatetime string `json:"scheduledDatetime,omitempty"` - ShortenURLs bool `json:"shortenUrls"` } // path represents the path to the Message resource. @@ -96,14 +98,10 @@ func Read(c *messagebird.Client, id string) (*Message, error) { return message, nil } -// Cancel sending Scheduled Sms. -func Delete(c *messagebird.Client, id string) (*Message, error) { - message := &Message{} - if err := c.Request(message, http.MethodDelete, path+"/"+id, nil); err != nil { - return nil, err - } - - return message, nil +// Delete Cancel sending Scheduled Sms. +// Return true if have been successfully deleted. +func Delete(c *messagebird.Client, id string) error { + return c.Request(&Message{}, http.MethodDelete, path+"/"+id, nil) } // List retrieves all messages of the user represented as a MessageList object. @@ -168,6 +166,7 @@ func requestDataForMessage(originator string, recipients []string, body string, request.ScheduledDatetime = params.ScheduledDatetime.Format(time.RFC3339) } + request.GroupIds = params.GroupIds request.Reference = params.Reference request.Validity = params.Validity request.Gateway = params.Gateway diff --git a/sms/message_test.go b/sms/message_test.go index e0a4d8f..20de072 100644 --- a/sms/message_test.go +++ b/sms/message_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - messagebird "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + messagebird "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) @@ -15,7 +15,7 @@ func TestMain(m *testing.M) { mbtest.EnableServer(m) } -func assertMessageObject(t *testing.T, message *Message) { +func assertMessageObject(t *testing.T, message *Message, expectedStatus string) { assert.Equal(t, "6fe65f90454aa61536e6a88b88972670", message.ID) assert.Equal(t, "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", message.HRef) assert.Equal(t, "mt", message.Direction) @@ -28,17 +28,42 @@ func assertMessageObject(t *testing.T, message *Message) { assert.Len(t, message.TypeDetails, 0) assert.Equal(t, "plain", message.DataCoding) assert.Equal(t, 1, message.MClass) - assert.Nil(t, message.ScheduledDatetime) - if message.CreatedDatetime == nil || message.CreatedDatetime.Format(time.RFC3339) != "2015-01-05T10:02:59Z" { - t.Errorf("Unexpected message created datetime: %s, expected: 2015-01-05T10:02:59Z", message.CreatedDatetime) + assert.Equal(t, expectedStatus, message.Recipients.Items[0].Status) + if expectedStatus == "scheduled" { + assert.NotNil(t, message.ScheduledDatetime) + assert.Equal(t, 0, message.Recipients.TotalSentCount) + assert.Nil(t, message.Recipients.Items[0].StatusDatetime) + } else { + assert.Nil(t, message.ScheduledDatetime) + assert.Equal(t, 1, message.Recipients.TotalSentCount) + assert.Equal(t, "2022-01-05T10:02:59Z", message.Recipients.Items[0].StatusDatetime.Format(time.RFC3339)) + } + + if message.CreatedDatetime == nil || message.CreatedDatetime.Format(time.RFC3339) != "2022-01-05T10:02:59Z" { + t.Errorf("Unexpected message created datetime: %s, expected: 2022-01-05T10:02:59Z", message.CreatedDatetime) } assert.Equal(t, 1, message.Recipients.TotalCount) - assert.Equal(t, 1, message.Recipients.TotalSentCount) assert.Equal(t, int64(31612345678), message.Recipients.Items[0].Recipient) - assert.Equal(t, "sent", message.Recipients.Items[0].Status) + assert.Equal(t, 1, message.Recipients.Items[0].MessagePartCount) +} - assert.Equal(t, "2015-01-05T10:02:59Z", message.Recipients.Items[0].StatusDatetime.Format(time.RFC3339)) +func assertExtendedMessageObject(t *testing.T, message *Message) { + assertMessageObject(t, message, "sent") + + assert.Equal(t, "Ukraine", *message.Recipients.Items[0].RecipientCountry) + assert.Equal(t, 380, *message.Recipients.Items[0].RecipientCountryPrefix) + assert.Equal(t, "life:)", *message.Recipients.Items[0].RecipientOperator) + assert.Equal(t, 22, *message.Recipients.Items[0].MessageLength) + assert.Equal(t, "successfully delivered", *message.Recipients.Items[0].StatusReason) + assert.Equal(t, "25506", *message.Recipients.Items[0].Mccmnc) + assert.Equal(t, "255", *message.Recipients.Items[0].Mcc) + assert.Equal(t, "06", *message.Recipients.Items[0].Mnc) + + assert.Nil(t, message.Recipients.Items[0].StatusErrorCode) + assert.NotNil(t, message.Recipients.Items[0].Price) + assert.Equal(t, 22, message.Recipients.Items[0].Price.Amount) + assert.Equal(t, "UAH", message.Recipients.Items[0].Price.Currency) } func TestCreate(t *testing.T) { @@ -48,7 +73,7 @@ func TestCreate(t *testing.T) { message, err := Create(client, "TestName", []string{"31612345678"}, "Hello World", nil) assert.NoError(t, err) - assertMessageObject(t, message) + assertMessageObject(t, message, "sent") } func TestCreateError(t *testing.T) { @@ -131,10 +156,10 @@ func TestCreateWithFlashType(t *testing.T) { } func TestCreateWithScheduledDatetime(t *testing.T) { - mbtest.WillReturnTestdata(t, "messageObjectWithCreatedDatetime.json", http.StatusOK) + mbtest.WillReturnTestdata(t, "messageObjectWithScheduledDatetime.json", http.StatusOK) client := mbtest.Client(t) - scheduledDatetime, _ := time.Parse(time.RFC3339, "2015-01-05T10:03:59+00:00") + scheduledDatetime, _ := time.Parse(time.RFC3339, "2022-01-05T10:03:59+00:00") params := &Params{ScheduledDatetime: scheduledDatetime} @@ -148,6 +173,35 @@ func TestCreateWithScheduledDatetime(t *testing.T) { assert.Nil(t, message.Recipients.Items[0].StatusDatetime) } +func TestRead(t *testing.T) { + mbtest.WillReturnTestdata(t, "readMessageObject.json", http.StatusOK) + client := mbtest.Client(t) + + message, err := Read(client, "6fe65f90454aa61536e6a88b88972670") + assert.NoError(t, err) + + assertExtendedMessageObject(t, message) +} + +func TestReadScheduled(t *testing.T) { + mbtest.WillReturnTestdata(t, "readScheduledMessageObject.json", http.StatusOK) + client := mbtest.Client(t) + + message, err := Read(client, "6fe65f90454aa61536e6a88b88972670") + assert.NoError(t, err) + + assertMessageObject(t, message, "scheduled") +} + +func TestReadNotFound(t *testing.T) { + mbtest.WillReturnTestdata(t, "messageNotFound.json", http.StatusNotFound) + client := mbtest.Client(t) + + message, err := Read(client, "6fe65f90454aa61536e6a88b88972670") + assert.Nil(t, message) + assert.Errorf(t, err, "API errors: message not found") +} + func TestList(t *testing.T) { mbtest.WillReturnTestdata(t, "messageListObject.json", http.StatusOK) client := mbtest.Client(t) @@ -158,9 +212,10 @@ func TestList(t *testing.T) { assert.Equal(t, 20, messageList.Limit) assert.Equal(t, 2, messageList.Count) assert.Equal(t, 2, messageList.TotalCount) + assert.Equal(t, len(messageList.Items), messageList.Count) for _, message := range messageList.Items { - assertMessageObject(t, &message) + assertMessageObject(t, &message, "sent") } } @@ -181,9 +236,9 @@ func TestListScheduled(t *testing.T) { messageList, err := List(client, &ListParams{Status: "scheduled"}) assert.NoError(t, err) - assert.Equal(t, 1, messageList.Count) - assert.Equal(t, 1, messageList.TotalCount) - assert.Len(t, messageList.Items, 1) + assert.Equal(t, 2, messageList.Count) + assert.Equal(t, 2, messageList.TotalCount) + assert.Equal(t, len(messageList.Items), messageList.Count) } func TestRequestDataForMessage(t *testing.T) { @@ -206,6 +261,7 @@ func TestRequestDataForMessage(t *testing.T) { assert.Equal(t, "MyBody", request.Body) assert.Equal(t, messageParams.Type, request.Type) assert.Equal(t, messageParams.Reference, request.Reference) + assert.Equal(t, messageParams.GroupIds, request.GroupIds) assert.Equal(t, messageParams.Validity, request.Validity) assert.Equal(t, messageParams.Gateway, request.Gateway) assert.Nil(t, request.TypeDetails) @@ -213,3 +269,19 @@ func TestRequestDataForMessage(t *testing.T) { assert.Equal(t, messageParams.ScheduledDatetime.Format(time.RFC3339), request.ScheduledDatetime) assert.True(t, request.ShortenURLs) } + +func TestDelete(t *testing.T) { + mbtest.WillReturnOnlyStatus(http.StatusNoContent) + client := mbtest.Client(t) + + err := Delete(client, "6fe65f90454aa61536e6a88b88972670") + assert.NoError(t, err) +} + +func TestDeleteNotFound(t *testing.T) { + mbtest.WillReturnOnlyStatus(http.StatusNotFound) + client := mbtest.Client(t) + + err := Delete(client, "6fe65f90454aa61536e6a88b88972670") + assert.Errorf(t, err, "API errors: message not found") +} diff --git a/sms/testdata/binaryMessageObject.json b/sms/testdata/binaryMessageObject.json index 0d226b9..d258ea2 100644 --- a/sms/testdata/binaryMessageObject.json +++ b/sms/testdata/binaryMessageObject.json @@ -1,9 +1,9 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "unicode", "direction": "mt", - "gateway": 10, + "gateway": 239, "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", "id": "6fe65f90454aa61536e6a88b88972670", "mclass": 1, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ], "totalCount": 1, diff --git a/sms/testdata/flashMessageObject.json b/sms/testdata/flashMessageObject.json index 4b02bee..90b1f37 100644 --- a/sms/testdata/flashMessageObject.json +++ b/sms/testdata/flashMessageObject.json @@ -1,9 +1,9 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "unicode", "direction": "mt", - "gateway": 10, + "gateway": 239, "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", "id": "6fe65f90454aa61536e6a88b88972670", "mclass": 0, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ], "totalCount": 1, diff --git a/sms/testdata/messageListObject.json b/sms/testdata/messageListObject.json index a7ba23d..2ef3cdd 100644 --- a/sms/testdata/messageListObject.json +++ b/sms/testdata/messageListObject.json @@ -24,7 +24,7 @@ "datacoding": "plain", "mclass": 1, "scheduledDatetime": null, - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "recipients": { "totalCount": 1, "totalSentCount": 1, @@ -34,7 +34,21 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1, + "recipientCountry": "Ukraine", + "recipientCountryPrefix": 380, + "recipientOperator": "life:)", + "messageLength": 22, + "statusErrorCode": null, + "statusReason": "successfully delivered", + "price": { + "amount": 22, + "currency": "UAH" + }, + "mccmnc": "25506", + "mcc": "255", + "mnc": "06" } ] } @@ -53,7 +67,7 @@ "datacoding": "plain", "mclass": 1, "scheduledDatetime": null, - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "recipients": { "totalCount": 1, "totalSentCount": 1, @@ -63,7 +77,21 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1, + "recipientCountry": "Netherlands", + "recipientCountryPrefix": 31, + "recipientOperator": "KPN", + "messageLength": 22, + "statusErrorCode": null, + "statusReason": "successfully delivered", + "price": { + "amount": 22, + "currency": "UAH" + }, + "mccmnc": "20408", + "mcc": "255", + "mnc": "06" } ] } diff --git a/sms/testdata/messageListScheduledObject.json b/sms/testdata/messageListScheduledObject.json index b10b00a..34f4362 100644 --- a/sms/testdata/messageListScheduledObject.json +++ b/sms/testdata/messageListScheduledObject.json @@ -1,13 +1,13 @@ { "offset": 0, "limit": 20, - "count": 1, - "totalCount": 1, + "count": 2, + "totalCount": 2, "links": { - "first": "https://rest.messagebird.com/messages/?offset=0", + "first": "https://rest.messagebird.com/messages/?offset=0&status=scheduled", "previous": null, "next": null, - "last": "https://rest.messagebird.com/messages/?offset=0" + "last": "https://rest.messagebird.com/messages/?offset=0&status=scheduled" }, "items": [ { @@ -23,8 +23,8 @@ "typeDetails": {}, "datacoding": "plain", "mclass": 1, - "scheduledDatetime": null, - "createdDatetime": "2015-01-05T10:02:59+00:00", + "scheduledDatetime": "2022-01-05T10:03:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "recipients": { "totalCount": 1, "totalSentCount": 1, @@ -34,7 +34,38 @@ { "recipient": 31612345678, "status": "scheduled", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 + } + ] + } + }, + { + "id": "6fe65f90454aa61536e6a88b88972670", + "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", + "direction": "mt", + "type": "sms", + "originator": "TestName", + "body": "Hello World", + "reference": null, + "validity": null, + "gateway": 239, + "typeDetails": {}, + "datacoding": "plain", + "mclass": 1, + "scheduledDatetime": "2022-01-05T10:03:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", + "recipients": { + "totalCount": 1, + "totalSentCount": 1, + "totalDeliveredCount": 0, + "totalDeliveryFailedCount": 0, + "items": [ + { + "recipient": 31612345678, + "status": "scheduled", + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ] } diff --git a/sms/testdata/messageNotFound.json b/sms/testdata/messageNotFound.json new file mode 100644 index 0000000..ff3f781 --- /dev/null +++ b/sms/testdata/messageNotFound.json @@ -0,0 +1,9 @@ +{ + "errors": [ + { + "code": 20, + "description": "message not found", + "parameter": null + } + ] +} diff --git a/sms/testdata/messageObject.json b/sms/testdata/messageObject.json index e84134d..a86bdd4 100644 --- a/sms/testdata/messageObject.json +++ b/sms/testdata/messageObject.json @@ -1,6 +1,6 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "plain", "direction": "mt", "gateway": 239, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ], "totalCount": 1, diff --git a/sms/testdata/messageObjectWithCreatedDatetime.json b/sms/testdata/messageObjectWithScheduledDatetime.json similarity index 78% rename from sms/testdata/messageObjectWithCreatedDatetime.json rename to sms/testdata/messageObjectWithScheduledDatetime.json index d147027..1a7da76 100644 --- a/sms/testdata/messageObjectWithCreatedDatetime.json +++ b/sms/testdata/messageObjectWithScheduledDatetime.json @@ -1,6 +1,6 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "plain", "direction": "mt", "gateway": 239, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "scheduled", - "statusDatetime": null + "statusDatetime": null, + "messagePartCount": 1 } ], "totalCount": 1, @@ -22,7 +23,7 @@ "totalSentCount": 0 }, "reference": null, - "scheduledDatetime": "2015-01-05T10:03:59+00:00", + "scheduledDatetime": "2022-01-05T10:03:59+00:00", "type": "sms", "typeDetails": {}, "validity": null diff --git a/sms/testdata/messageWithParamsObject.json b/sms/testdata/messageWithParamsObject.json index d234d59..203fdae 100644 --- a/sms/testdata/messageWithParamsObject.json +++ b/sms/testdata/messageWithParamsObject.json @@ -1,6 +1,6 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "unicode", "direction": "mt", "gateway": 10, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ], "totalCount": 1, diff --git a/sms/testdata/premiumMessageObject.json b/sms/testdata/premiumMessageObject.json index 2432581..d079fc8 100644 --- a/sms/testdata/premiumMessageObject.json +++ b/sms/testdata/premiumMessageObject.json @@ -1,9 +1,9 @@ { "body": "Hello World", - "createdDatetime": "2015-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", "datacoding": "unicode", "direction": "mt", - "gateway": 10, + "gateway": 239, "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", "id": "6fe65f90454aa61536e6a88b88972670", "mclass": 1, @@ -13,7 +13,8 @@ { "recipient": 31612345678, "status": "sent", - "statusDatetime": "2015-01-05T10:02:59+00:00" + "statusDatetime": "2022-01-05T10:02:59+00:00", + "messagePartCount": 1 } ], "totalCount": 1, diff --git a/sms/testdata/readMessageObject.json b/sms/testdata/readMessageObject.json new file mode 100644 index 0000000..5696e2d --- /dev/null +++ b/sms/testdata/readMessageObject.json @@ -0,0 +1,43 @@ +{ + "body": "Hello World", + "createdDatetime": "2022-01-05T10:02:59+00:00", + "datacoding": "plain", + "direction": "mt", + "gateway": 239, + "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", + "id": "6fe65f90454aa61536e6a88b88972670", + "mclass": 1, + "originator": "TestName", + "recipients": { + "items": [ + { + "recipient": 31612345678, + "status": "sent", + "statusDatetime": "2022-01-05T10:02:59+00:00", + "recipientCountry": "Ukraine", + "recipientCountryPrefix": 380, + "recipientOperator": "life:)", + "messageLength": 22, + "statusErrorCode": null, + "statusReason": "successfully delivered", + "price": { + "amount": 22, + "currency": "UAH" + }, + "mccmnc": "25506", + "mcc": "255", + "mnc": "06", + "messagePartCount": 1 + } + ], + "totalCount": 1, + "totalDeliveredCount": 0, + "totalDeliveryFailedCount": 0, + "totalSentCount": 1 + }, + "reference": null, + "scheduledDatetime": null, + "type": "sms", + "typeDetails": {}, + "validity": null +} diff --git a/sms/testdata/readScheduledMessageObject.json b/sms/testdata/readScheduledMessageObject.json new file mode 100644 index 0000000..9d5edad --- /dev/null +++ b/sms/testdata/readScheduledMessageObject.json @@ -0,0 +1,30 @@ +{ + "body": "Hello World", + "datacoding": "plain", + "direction": "mt", + "gateway": 239, + "href": "https://rest.messagebird.com/messages/6fe65f90454aa61536e6a88b88972670", + "id": "6fe65f90454aa61536e6a88b88972670", + "scheduledDatetime": "2022-01-05T10:02:59+00:00", + "createdDatetime": "2022-01-05T10:02:59+00:00", + "mclass": 1, + "originator": "TestName", + "recipients": { + "totalCount": 1, + "totalSentCount": 0, + "totalDeliveredCount": 0, + "totalDeliveryFailedCount": 0, + "items": [ + { + "recipient": 31612345678, + "status": "scheduled", + "statusDatetime": null, + "messagePartCount": 1 + } + ] + }, + "reference": null, + "type": "sms", + "typeDetails": {}, + "validity": null +} diff --git a/verify/verify.go b/verify/verify.go index 1633092..6ef6921 100644 --- a/verify/verify.go +++ b/verify/verify.go @@ -9,7 +9,7 @@ import ( "strconv" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // Verify object represents MessageBird server response. diff --git a/verify/verify_test.go b/verify/verify_test.go index 88462e1..d802040 100644 --- a/verify/verify_test.go +++ b/verify/verify_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/voice/call.go b/voice/call.go index f3b5c4d..b785bbd 100644 --- a/voice/call.go +++ b/voice/call.go @@ -7,7 +7,7 @@ import ( "reflect" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // CallStatus enumerates all valid values for a call status. diff --git a/voice/callflow.go b/voice/callflow.go index 9bce253..47a91a4 100644 --- a/voice/callflow.go +++ b/voice/callflow.go @@ -7,7 +7,7 @@ import ( "reflect" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // A CallFlow describes the flow of operations (steps) to be executed when diff --git a/voice/leg.go b/voice/leg.go index f0d0c24..32d346c 100644 --- a/voice/leg.go +++ b/voice/leg.go @@ -6,7 +6,7 @@ import ( "reflect" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // LegStatus enumerates all valid values for a leg status. diff --git a/voice/main_test.go b/voice/main_test.go index c0b49de..542b0a6 100644 --- a/voice/main_test.go +++ b/voice/main_test.go @@ -9,7 +9,7 @@ import ( "os" "testing" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) func testRequest(status int, body []byte) (*messagebird.Client, func()) { diff --git a/voice/paginator.go b/voice/paginator.go index 80fb85f..989060f 100644 --- a/voice/paginator.go +++ b/voice/paginator.go @@ -6,7 +6,7 @@ import ( "net/http" "reflect" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // A Paginator is used to stream the contents of a collection of some type from diff --git a/voice/recording.go b/voice/recording.go index a9e12f4..d24a8d7 100644 --- a/voice/recording.go +++ b/voice/recording.go @@ -9,7 +9,7 @@ import ( "runtime" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // RecordingStatus enumerates all valid values for the status of a recording. diff --git a/voice/recording_test.go b/voice/recording_test.go index abf40d7..a17f8dc 100644 --- a/voice/recording_test.go +++ b/voice/recording_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/voice/transcription.go b/voice/transcription.go index 5bd2c6f..b373234 100644 --- a/voice/transcription.go +++ b/voice/transcription.go @@ -8,7 +8,7 @@ import ( "runtime" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // A Transcription is a textual representation of a recording as text. diff --git a/voice/transcription_test.go b/voice/transcription_test.go index 4dc9173..202f0c2 100644 --- a/voice/transcription_test.go +++ b/voice/transcription_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/voice/voice.go b/voice/voice.go index 21f6e76..251fd88 100644 --- a/voice/voice.go +++ b/voice/voice.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) const apiRoot = "https://voice.messagebird.com/v1" diff --git a/voice/voice_test.go b/voice/voice_test.go index 56ab9b0..e47ee5e 100644 --- a/voice/voice_test.go +++ b/voice/voice_test.go @@ -3,7 +3,7 @@ package voice import ( "testing" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" ) diff --git a/voice/webhook.go b/voice/webhook.go index b610e4b..a5d6266 100644 --- a/voice/webhook.go +++ b/voice/webhook.go @@ -7,7 +7,7 @@ import ( "reflect" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // A Webhook is an HTTP callback to your platform. They are sent when calls are diff --git a/voicemessage/voice_message.go b/voicemessage/voice_message.go index 1040175..7195c10 100644 --- a/voicemessage/voice_message.go +++ b/voicemessage/voice_message.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - messagebird "github.com/messagebird/go-rest-api/v7" + messagebird "github.com/messagebird/go-rest-api/v8" ) // VoiceMessage wraps data needed to transform text messages into voice messages. diff --git a/voicemessage/voice_message_test.go b/voicemessage/voice_message_test.go index 6fee252..32a5e68 100644 --- a/voicemessage/voice_message_test.go +++ b/voicemessage/voice_message_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/messagebird/go-rest-api/v7" - "github.com/messagebird/go-rest-api/v7/internal/mbtest" + "github.com/messagebird/go-rest-api/v8" + "github.com/messagebird/go-rest-api/v8/internal/mbtest" "github.com/stretchr/testify/assert" )