forked from timehop/apns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge_number_test.go
83 lines (73 loc) · 1.89 KB
/
badge_number_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package apns_test
import (
"encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/timehop/apns"
)
var _ = Describe("BadgeNumber", func() {
Describe("Defaults", func() {
It("Should have the proper default values", func() {
b := apns.BadgeNumber{}
Expect(b.Number).To(Equal(uint(0)))
Expect(b.IsSet).To(BeFalse())
})
})
Describe("NewBadgeNumber", func() {
var b apns.BadgeNumber
Context("with an argument", func() {
It("should have values set properly", func() {
b.Set(5)
Expect(b.IsSet).To(BeTrue())
Expect(b.Number).To(Equal(uint(5)))
})
})
Context("when unset", func() {
It("should reset its values", func() {
b.Unset()
Expect(b.IsSet).To(BeFalse())
Expect(b.Number).To(Equal(uint(0)))
})
})
})
Describe("JSON handling", func() {
type BadgeNumbers struct {
A apns.BadgeNumber `json:"a"`
B apns.BadgeNumber `json:"b"`
}
Context("when marshalling", func() {
It("should not error", func() {
bn := apns.BadgeNumber{}
bn.Set(10)
_, err := json.Marshal(BadgeNumbers{
A: bn,
})
Expect(err).To(BeNil())
})
It("should create the proper values", func() {
bn := apns.BadgeNumber{}
bn.Set(10)
bns := BadgeNumbers{
A: bn,
}
b, _ := json.Marshal(bns)
expected := "{\"a\":10,\"b\":0}"
Expect(string(b)).To(Equal(expected))
})
})
Context("when unmarshalled", func() {
var bnumbers BadgeNumbers
It("should unmarshal without errors", func() {
err := json.Unmarshal([]byte("{\"a\":10,\"b\":0}"), &bnumbers)
Expect(err).To(BeNil())
})
It("should populate the struct properly", func() {
json.Unmarshal([]byte("{\"a\":10,\"b\":0}"), &bnumbers)
Expect(bnumbers.A.IsSet).To(BeTrue())
Expect(bnumbers.B.IsSet).To(BeTrue())
Expect(bnumbers.A.Number).To(Equal(uint(10)))
Expect(bnumbers.B.Number).To(Equal(uint(0)))
})
})
})
})