Skip to content

Commit f738781

Browse files
committed
Fix the test with the new way
1 parent 6de92fb commit f738781

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

events/event_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package events_test
22

33
import (
4+
"encoding/json"
45
"strings"
56
"testing"
67
"time"
@@ -44,9 +45,14 @@ func TestNewPurchase(t *testing.T) {
4445
t.Errorf("Expecting event id to start with evt_, got %s", ev.ID)
4546
}
4647

48+
var purchaseData data.Purchase
49+
if err := json.Unmarshal(ev.Data, &purchaseData); err != nil {
50+
t.Errorf("Unable to unmarshall the purchase data: %s", err.Error())
51+
}
52+
4753
// Checking if we can unmarshal the event back to the original data
48-
if ev.Data.(data.Purchase).Type != events.PurchaseDataType {
49-
t.Errorf("Expecting event data type %s, got %s", events.PurchaseDataType, ev.Data.(data.Purchase).Type)
54+
if purchaseData.Type != events.PurchaseDataType {
55+
t.Errorf("Expecting event data type %s, got %s", events.PurchaseDataType, purchaseData.Type)
5056
}
5157
}
5258

@@ -93,9 +99,14 @@ func TestNewSubscription(t *testing.T) {
9399
t.Errorf("Expecting event id to start with evt_, got %s", ev.ID)
94100
}
95101

102+
var subscriptionData data.Subscription
103+
if err := json.Unmarshal(ev.Data, &subscriptionData); err != nil {
104+
t.Errorf("Unable to unmarshall the subscription data: %s", err.Error())
105+
}
106+
96107
// Checking if we can unmarshal the event back to the original data
97-
if ev.Data.(data.Subscription).Type != events.SubscriptionDataType {
98-
t.Errorf("Expecting event data type %s, got %s", events.SubscriptionDataType, ev.Data.(data.Subscription).Type)
108+
if subscriptionData.Type != events.SubscriptionDataType {
109+
t.Errorf("Expecting event data type %s, got %s", events.SubscriptionDataType, subscriptionData.Type)
99110
}
100111
}
101112

0 commit comments

Comments
 (0)