|
1 | 1 | package events_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "strings" |
5 | 6 | "testing" |
6 | 7 | "time" |
@@ -44,9 +45,14 @@ func TestNewPurchase(t *testing.T) { |
44 | 45 | t.Errorf("Expecting event id to start with evt_, got %s", ev.ID) |
45 | 46 | } |
46 | 47 |
|
| 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 | + |
47 | 53 | // 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) |
50 | 56 | } |
51 | 57 | } |
52 | 58 |
|
@@ -93,9 +99,14 @@ func TestNewSubscription(t *testing.T) { |
93 | 99 | t.Errorf("Expecting event id to start with evt_, got %s", ev.ID) |
94 | 100 | } |
95 | 101 |
|
| 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 | + |
96 | 107 | // 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) |
99 | 110 | } |
100 | 111 | } |
101 | 112 |
|
|
0 commit comments