This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reaction_test.go
94 lines (72 loc) · 2.25 KB
/
reaction_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
package stream_chat
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChannel_SendReaction(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
defer ch.Delete()
user := randomUser()
msg := &Message{
Text: "test message",
User: user,
}
msg, err := ch.SendMessage(msg, serverUser.ID)
mustNoError(t, err, "send message")
reaction := Reaction{Type: "love"}
msg, err = ch.SendReaction(&reaction, msg.ID, serverUser.ID)
mustNoError(t, err, "send reaction")
assert.Equal(t, 1, msg.ReactionCounts[reaction.Type], "reaction count", reaction)
assert.Condition(t, reactionExistsCondition(msg.LatestReactions, reaction.Type), "latest reaction exists")
}
func reactionExistsCondition(reactions []*Reaction, searchType string) func() bool {
return func() bool {
for _, r := range reactions {
if r.Type == searchType {
return true
}
}
return false
}
}
func TestChannel_DeleteReaction(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
defer ch.Delete()
user := randomUser()
msg := &Message{
Text: "test message",
User: user,
}
msg, err := ch.SendMessage(msg, serverUser.ID)
mustNoError(t, err, "send message")
reaction := Reaction{Type: "love"}
msg, err = ch.SendReaction(&reaction, msg.ID, serverUser.ID)
mustNoError(t, err, "send reaction")
msg, err = ch.DeleteReaction(msg.ID, reaction.Type, serverUser.ID)
mustNoError(t, err, "delete reaction")
assert.Equal(t, 0, msg.ReactionCounts[reaction.Type], "reaction count")
assert.Empty(t, msg.LatestReactions, "latest reactions empty")
}
func TestChannel_GetReactions(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
defer ch.Delete()
user := randomUser()
msg := &Message{
Text: "test message",
User: user,
}
msg, err := ch.SendMessage(msg, serverUser.ID)
mustNoError(t, err, "send message")
reactions, err := ch.GetReactions(msg.ID, nil)
mustNoError(t, err, "get reactions")
assert.Empty(t, reactions, "reactions empty")
reaction := Reaction{Type: "love"}
msg, err = ch.SendReaction(&reaction, msg.ID, serverUser.ID)
mustNoError(t, err, "send reaction")
reactions, err = ch.GetReactions(msg.ID, nil)
mustNoError(t, err, "get reactions")
assert.Condition(t, reactionExistsCondition(reactions, reaction.Type), "reaction exists")
}