-
Notifications
You must be signed in to change notification settings - Fork 76
/
events_test.go
39 lines (34 loc) · 927 Bytes
/
events_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gochimp3
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestEventsJson(t *testing.T) {
unix := time.Unix(0, 0)
eventRequest := &EventRequest{
Name: "huge_deal",
Properties: map[string]string{
"R2": "D2",
},
IsSyncing: false,
OccurredAt: &unix,
}
bytes, err := json.Marshal(eventRequest)
assert.NoError(t, err)
backFromJson := &EventRequest{}
assert.NoError(t, json.Unmarshal(bytes, backFromJson))
assert.Equal(t, eventRequest, backFromJson)
missingFields := &EventRequest{
Name: "big_deal",
}
bytes, err = json.Marshal(missingFields)
assert.NoError(t, err)
assert.Equal(t, "{\"name\":\"big_deal\"}", string(bytes))
backFromJson = &EventRequest{}
assert.NoError(t, json.Unmarshal(bytes, backFromJson))
assert.Equal(t, missingFields, backFromJson)
assert.Nil(t, backFromJson.Properties)
assert.Nil(t, backFromJson.OccurredAt)
}