-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgocoin_test.go
66 lines (50 loc) · 1.77 KB
/
gocoin_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
package main
import (
"github.com/JosiahWI/gocoin/mocks"
"github.com/golang/mock/gomock"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"testing"
)
const exampleRoomID = id.RoomID("!qporfwt:matrix.org")
const exampleSenderID = id.UserID("@tester:matrix.org")
var validBalanceCheckEvent event.Event = event.Event{
Sender: exampleSenderID,
RoomID: exampleRoomID,
Content: event.Content{
Parsed: &event.MessageEventContent{
Body: "g!bal",
},
},
}
func TestGocoin(t *testing.T) {
t.Run("sends to correct room", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
mockSender := mocks.NewMockSender(mockCtrl)
mockSender.EXPECT().SendText(exampleRoomID, gomock.Any())
bot := GocoinBot{}
bot.HandleMessage(mockSender, validBalanceCheckEvent)
})
t.Run("bot does not reply to own message", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
mockSender := mocks.NewMockSender(mockCtrl)
mockSender.EXPECT().SendText(gomock.Any(), gomock.Any()).Times(0)
bot := GocoinBot{ID: exampleSenderID}
bot.HandleMessage(mockSender, validBalanceCheckEvent)
})
t.Run("sends correct balance", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
mockSender := mocks.NewMockSender(mockCtrl)
mockSender.EXPECT().SendText(gomock.Any(), "0")
bot := GocoinBot{}
bot.HandleMessage(mockSender, validBalanceCheckEvent)
})
t.Run("does not reply to message not starting with g!bal", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
mockSender := mocks.NewMockSender(mockCtrl)
mockSender.EXPECT().SendText(gomock.Any(), gomock.Any()).Times(0)
bot := GocoinBot{}
content := event.Content{Parsed: &event.MessageEventContent{Body: "hello world"}}
bot.HandleMessage(mockSender, event.Event{Sender: "tester", Content: content})
})
}