-
Notifications
You must be signed in to change notification settings - Fork 62
/
message_actions_get_test.go
95 lines (75 loc) · 2.49 KB
/
message_actions_get_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
package pubnub
import (
"fmt"
"strconv"
"testing"
h "github.com/pubnub/go/v7/tests/helpers"
"github.com/stretchr/testify/assert"
)
func AssertGetMessageActions(t *testing.T, checkQueryParam, testContext bool) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
if !checkQueryParam {
queryParam = nil
}
o := newGetMessageActionsBuilder(pn)
if testContext {
o = newGetMessageActionsBuilderWithContext(pn, backgroundContext)
}
channel := "chan"
timetoken := "15698453963258802"
aTimetoken := "15692384791344400"
limit := 10
o.Channel(channel)
o.Start(timetoken)
o.End(aTimetoken)
o.Limit(limit)
o.QueryParam(queryParam)
path, err := o.opts.buildPath()
assert.Nil(err)
h.AssertPathsEqual(t,
fmt.Sprintf(getMessageActionsPath, pn.Config.SubscribeKey, channel),
path, []int{})
body, err := o.opts.buildBody()
assert.Nil(err)
assert.Empty(body)
if checkQueryParam {
u, _ := o.opts.buildQuery()
assert.Equal("v1", u.Get("q1"))
assert.Equal("v2", u.Get("q2"))
assert.Equal(timetoken, u.Get("start"))
assert.Equal(aTimetoken, u.Get("end"))
assert.Equal(strconv.Itoa(limit), u.Get("limit"))
}
}
func TestGetMessageActions(t *testing.T) {
AssertGetMessageActions(t, true, false)
}
func TestGetMessageActionsContext(t *testing.T) {
AssertGetMessageActions(t, true, true)
}
func TestGetMessageActionsResponseValueError(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
opts := newGetMessageActionsOpts(pn, pn.ctx)
jsonBytes := []byte(`s`)
_, _, err := newPNGetMessageActionsResponse(jsonBytes, opts, StatusResponse{})
assert.Equal("pubnub/parsing: Error unmarshalling response: {s}", err.Error())
}
func TestGetMessageActionsResponseValuePass(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
opts := newGetMessageActionsOpts(pn, pn.ctx)
jsonBytes := []byte(`{"status": 200, "data": [{"messageTimetoken": "15698466245557325", "type": "reaction", "uuid": "pn-85463c27-ad24-49d4-8cdf-db93a300855a", "value": "smiley_face", "actionTimetoken": "15698466249528820"}]}`)
r, _, err := newPNGetMessageActionsResponse(jsonBytes, opts, StatusResponse{})
assert.Equal("15698466245557325", r.Data[0].MessageTimetoken)
assert.Equal("reaction", r.Data[0].ActionType)
assert.Equal("smiley_face", r.Data[0].ActionValue)
assert.Equal("15698466249528820", r.Data[0].ActionTimetoken)
assert.Equal("pn-85463c27-ad24-49d4-8cdf-db93a300855a", r.Data[0].UUID)
assert.Nil(err)
}