Skip to content

Commit

Permalink
Merge pull request #141 from mailgun/thrawn/develop
Browse files Browse the repository at this point in the history
Fixed MailboxVerification parsing error
  • Loading branch information
thrawn01 authored Oct 4, 2018
2 parents 45b7e2e + 710351f commit 4071f66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion email_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type EmailVerificationParts struct {
// Reason contains error's description.
type EmailVerification struct {
IsValid bool `json:"is_valid"`
MailboxVerification bool `json:"mailbox_verification,string"`
MailboxVerification string `json:"mailbox_verification"`
Parts EmailVerificationParts `json:"parts"`
Address string `json:"address"`
DidYouMean string `json:"did_you_mean"`
Expand Down
34 changes: 33 additions & 1 deletion email_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package mailgun
import (
"testing"

"encoding/json"

"github.com/facebookgo/ensure"
)

Expand All @@ -15,7 +17,7 @@ func TestEmailValidation(t *testing.T) {
ensure.Nil(t, err)

ensure.True(t, ev.IsValid)
ensure.True(t, ev.MailboxVerification)
ensure.DeepEqual(t, ev.MailboxVerification, "")
ensure.False(t, ev.IsDisposableAddress)
ensure.False(t, ev.IsRoleAddress)
ensure.True(t, ev.Parts.DisplayName == "")
Expand Down Expand Up @@ -43,3 +45,33 @@ func TestParseAddresses(t *testing.T) {
}
ensure.True(t, len(unparsableAddresses) == 1)
}

func TestUnmarshallResponse(t *testing.T) {
payload := []byte(`{
"address": "[email protected]",
"did_you_mean": null,
"is_disposable_address": false,
"is_role_address": false,
"is_valid": true,
"mailbox_verification": "unknown",
"parts":
{
"display_name": null,
"domain": "aol.com",
"local_part": "some_email"
},
"reason": null
}`)
var ev EmailVerification
err := json.Unmarshal(payload, &ev)
ensure.Nil(t, err)

ensure.True(t, ev.IsValid)
ensure.DeepEqual(t, ev.MailboxVerification, "unknown")
ensure.False(t, ev.IsDisposableAddress)
ensure.False(t, ev.IsRoleAddress)
ensure.True(t, ev.Parts.DisplayName == "")
ensure.DeepEqual(t, ev.Parts.LocalPart, "some_email")
ensure.DeepEqual(t, ev.Parts.Domain, "aol.com")
ensure.True(t, ev.Reason == "")
}

0 comments on commit 4071f66

Please sign in to comment.