Skip to content

Commit

Permalink
Merge pull request #108 from iivvoo/master
Browse files Browse the repository at this point in the history
Do not send zero-datetime (0001-01-01T00:00:00Z) if not set
  • Loading branch information
rfeiner authored Jul 12, 2022
2 parents bf934da + 1261a4b commit a7c4534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion voicemessage/voice_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func paramsToRequest(recipients []string, body string, params *Params) (*voiceMe
request.Voice = params.Voice
request.Repeat = params.Repeat
request.IfMachine = params.IfMachine
request.ScheduledDatetime = params.ScheduledDatetime.Format(time.RFC3339)
if !params.ScheduledDatetime.IsZero() {
request.ScheduledDatetime = params.ScheduledDatetime.Format(time.RFC3339)
}

return request, nil
}
12 changes: 11 additions & 1 deletion voicemessage/voice_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/messagebird/go-rest-api/v9"
messagebird "github.com/messagebird/go-rest-api/v9"
"github.com/messagebird/go-rest-api/v9/internal/mbtest"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -124,3 +124,13 @@ func TestRequestDataForVoiceMessage(t *testing.T) {
assert.Equal(t, "continue", request.IfMachine)
assert.Equal(t, voiceParams.ScheduledDatetime.Format(time.RFC3339), request.ScheduledDatetime)
}

func TestRequestDataForVoiceMessageZeroScheduledDatetime(t *testing.T) {
voiceParams := &Params{
// ScheduledDatetime will default to zero-time
}

request, err := paramsToRequest([]string{"31612345678"}, "MyBody", voiceParams)
assert.NoError(t, err)
assert.Equal(t, "", request.ScheduledDatetime, "Uninitialized ScheduledDatetime should default to empty string")
}

0 comments on commit a7c4534

Please sign in to comment.