-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_test.go
executable file
·106 lines (97 loc) · 2.57 KB
/
message_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package fcm
import "testing"
func TestValidate(t *testing.T) {
t.Run("valid with token", func(t *testing.T) {
timeToLive := uint(3600)
msg := &Message{
To: "test",
TimeToLive: &timeToLive,
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("invalid message", func(t *testing.T) {
var msg *Message
err := msg.Validate()
if err == nil {
t.Fatalf("expected <%v> error, but got <nil>", ErrInvalidMessage)
}
})
t.Run("invalid target", func(t *testing.T) {
msg := &Message{
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err == nil {
t.Fatalf("expected <%v> error, but got nil", ErrInvalidTarget)
}
})
t.Run("too many registration ids", func(t *testing.T) {
msg := &Message{
To: "test",
RegistrationIDs: make([]string, 2000),
}
err := msg.Validate()
if err == nil {
t.Fatalf("expected <%v> error, but got <nil>", ErrToManyRegIDs)
}
})
t.Run("invalid TTL", func(t *testing.T) {
timeToLive := uint(2500000)
msg := &Message{
To: "test",
RegistrationIDs: []string{"reg_id"},
TimeToLive: &timeToLive,
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err == nil {
t.Fatalf("expected <%v> error, but got nil", ErrInvalidTimeToLive)
}
})
t.Run("valid with registration ID", func(t *testing.T) {
msg := &Message{
RegistrationIDs: []string{"reg_id"},
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("valid with condition", func(t *testing.T) {
msg := &Message{
Condition: "'dogs' in topics || 'cats' in topics",
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("invalid condition", func(t *testing.T) {
msg := &Message{
Condition: "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics || 'TopicD' in topics )",
Data: map[string]interface{}{
"message": "This is a Firebase Cloud Messaging Topic Message!",
},
}
err := msg.Validate()
if err == nil {
t.Fatalf("expected <%v> error, but got nil", ErrInvalidTarget)
}
})
}