-
Notifications
You must be signed in to change notification settings - Fork 6
/
event_type_value_test.go
58 lines (51 loc) · 1.37 KB
/
event_type_value_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package revcatgo
import (
"encoding/json"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewEventType(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{"INITIAL_PURCHASE", "INITIAL_PURCHASE", nil},
{"CANCELLATION", "CANCELLATION", nil},
{"INVALID", "", errors.New("eventType value should be one of the following: TEST, INITIAL_PURCHASE, NON_RENEWING_PURCHASE, RENEWAL, PRODUCT_CHANGE, CANCELLATION, UNCANCELLATION, BILLING_ISSUE, SUBSCRIBER_ALIAS, SUBSCRIPTION_PAUSED, TRANSFER, EXPIRATION, SUBSCRIPTION_EXTENDED, TEMPORARY_ENTITLEMENT_GRANT, got INVALID")},
}
for _, c := range cases {
actual, err := newEventType(c.in)
assert.Equal(t, c.expected, actual.String())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.EqualError(t, err, c.err.Error())
}
}
}
func TestEventTypeUnMarshal(t *testing.T) {
cases := []struct {
in string
expected string
err error
}{
{`"INITIAL_PURCHASE"`, "INITIAL_PURCHASE", nil},
{`"CANCELLATION"`, "CANCELLATION", nil},
{`"INVALID"`, "", errors.New("")},
{`1`, "", errors.New("")},
{`null`, "", errors.New("")},
}
for _, c := range cases {
var e eventType
b := []byte(c.in)
err := json.Unmarshal(b, &e)
assert.Equal(t, c.expected, e.String())
if c.err == nil {
assert.Nil(t, err)
} else {
assert.Error(t, err)
}
}
}