forked from nikoksr/notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_test.go
49 lines (42 loc) · 1.61 KB
/
matrix_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
package matrix
import (
"context"
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
matrix "maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
func TestMatrix_New(t *testing.T) {
t.Parallel()
assert := require.New(t)
service, err := New("fake-user-id", "fake-home-server", "fake-home-server", "fake-access-token")
assert.Nil(err)
assert.NotNil(service)
assert.Equal(id.UserID("fake-user-id"), service.options.userID)
assert.Equal("fake-home-server", service.options.homeServer)
assert.Equal("fake-access-token", service.options.accessToken)
}
func TestService_Send(t *testing.T) {
t.Parallel()
assert := require.New(t)
// Test response
mockClient := newMockMatrixClient(t)
mockClient.
On("SendMessageEvent", id.RoomID("fake-room-id"), event.EventMessage, &Message{Body: "fake-message", Msgtype: event.MsgText}).Return(&matrix.RespSendEvent{}, nil)
service, _ := New("fake-user-id", "fake-room-id", "fake-home-server", "fake-access-token")
service.client = mockClient
err := service.Send(context.Background(), "", "fake-message")
assert.Nil(err)
mockClient.AssertExpectations(t)
// Test error on Send
mockClient = newMockMatrixClient(t)
mockClient.
On("SendMessageEvent", id.RoomID("fake-room-id"), event.EventMessage, &Message{Body: "fake-message", Msgtype: event.MsgText}).Return(nil, errors.New("some-error"))
service, _ = New("fake-user-id", "fake-room-id", "fake-home-server", "fake-access-token")
service.client = mockClient
err = service.Send(context.Background(), "", "fake-message")
assert.NotNil(err)
mockClient.AssertExpectations(t)
}