Skip to content
Closed
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
6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ type PushToken struct {

// MGCustomer type.
type MGCustomer struct {
ID int `json:"id,omitempty"`
ExternalID StringOrNumber `json:"externalId,omitempty"`
MGChannel *MGChannel `json:"mgChannel,omitempty"`
ID int `json:"id,omitempty"`
ExternalID int `json:"externalId,omitempty"`
MGChannel *MGChannel `json:"mgChannel,omitempty"`
}

// CustomerSubscription type.
Expand Down
31 changes: 5 additions & 26 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ func TestCustomer_IsContactJSON(t *testing.T) {
}

func TestCustomer_MGCustomersExternalIDJSON(t *testing.T) {
var fromString Customer
if err := json.Unmarshal([]byte(`{"mgCustomers":[{"id":1,"externalId":"123"}]}`), &fromString); err != nil {
t.Fatalf("unmarshal customer with string mgCustomers externalId: %v", err)
}

if len(fromString.MgCustomers) != 1 {
t.Fatalf("expected one mgCustomer from string payload, got %d", len(fromString.MgCustomers))
}

if fromString.MgCustomers[0].ExternalID != "123" {
t.Fatalf("expected mgCustomers[0].ExternalID=123 from string, got %q", fromString.MgCustomers[0].ExternalID)
}

var fromNumber Customer
if err := json.Unmarshal([]byte(`{"mgCustomers":[{"id":1,"externalId":123}]}`), &fromNumber); err != nil {
t.Fatalf("unmarshal customer with numeric mgCustomers externalId: %v", err)
Expand All @@ -104,21 +91,13 @@ func TestCustomer_MGCustomersExternalIDJSON(t *testing.T) {
t.Fatalf("expected one mgCustomer from numeric payload, got %d", len(fromNumber.MgCustomers))
}

if fromNumber.MgCustomers[0].ExternalID != "123" {
t.Fatalf("expected mgCustomers[0].ExternalID=123 from number, got %q", fromNumber.MgCustomers[0].ExternalID)
}

var fromNull Customer
if err := json.Unmarshal([]byte(`{"mgCustomers":[{"id":1,"externalId":null}]}`), &fromNull); err != nil {
t.Fatalf("unmarshal customer with null mgCustomers externalId: %v", err)
if fromNumber.MgCustomers[0].ExternalID != 123 {
t.Fatalf("expected mgCustomers[0].ExternalID=123, got %d", fromNumber.MgCustomers[0].ExternalID)
}

if len(fromNull.MgCustomers) != 1 {
t.Fatalf("expected one mgCustomer from null payload, got %d", len(fromNull.MgCustomers))
}

if fromNull.MgCustomers[0].ExternalID != "" {
t.Fatalf("expected empty mgCustomers[0].ExternalID from null, got %q", fromNull.MgCustomers[0].ExternalID)
var fromString Customer
if err := json.Unmarshal([]byte(`{"mgCustomers":[{"id":1,"externalId":"123"}]}`), &fromString); err == nil {
t.Fatal("expected string mgCustomers externalId to be rejected")
}
}

Expand Down
Loading