-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_history_test.go
78 lines (59 loc) · 1.92 KB
/
slack_history_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
package slackactivity_test
import (
"strconv"
"testing"
slackactivity "github.com/nakatanakatana/slack-activity"
"github.com/slack-go/slack"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
type conversationHistoryMock struct {
messages []slack.Message
}
var _ slackactivity.SlackChannelHistoryClient = conversationHistoryMock{}
func (m conversationHistoryMock) GetConversationHistory(
params *slack.GetConversationHistoryParameters,
) (*slack.GetConversationHistoryResponse, error) {
return &slack.GetConversationHistoryResponse{
Messages: m.messages,
}, nil
}
func newConversationHistoryMock(length int) conversationHistoryMock {
m := make([]slack.Message, length)
for i := range m {
m[i] = slack.Message{Msg: slack.Msg{Text: strconv.Itoa(i)}}
}
return conversationHistoryMock{
messages: m,
}
}
func TestGetChannelHistory(t *testing.T) {
t.Parallel()
const mockLen = 1000
mock := newConversationHistoryMock(mockLen)
t.Run("GetConversationsHistoryの結果内のMessagesを返す", func(t *testing.T) {
result, err := slackactivity.GetChannelHistory(mock, "dummy")
assert.NilError(t, err)
assert.Assert(t, is.Len(result, mockLen))
})
}
func TestFilterMessage(t *testing.T) {
t.Parallel()
const mockLen = 1000
m := newConversationHistoryMock(mockLen)
messages := m.messages
t.Run("fnがすべてtrueを返すとき元のメッセージと同じものを返す", func(t *testing.T) {
t.Parallel()
fn := func(slack.Message) bool { return true }
result := slackactivity.FilterMessage(messages, fn)
assert.Assert(t, is.Len(result, mockLen))
assert.DeepEqual(t, result, messages)
})
t.Run("fnがすべてfalseを返すとき空のメッセージを返す", func(t *testing.T) {
t.Parallel()
fn := func(slack.Message) bool { return false }
result := slackactivity.FilterMessage(messages, fn)
assert.Assert(t, is.Len(result, 0))
assert.DeepEqual(t, result, []slack.Message{})
})
}