1
0
mirror of https://github.com/nikoksr/notify.git synced 2025-01-10 00:28:36 +02:00
notify/service/matrix/matrix_test.go
Arno Cornette d2dfd10850
feat(service): add matrix service (#410)
* feat(service): implemented matrix service

* docs(readme): add matrix service

* chore(format) Reformatted with gofumpt

* docs(readme): updated readme and added doc

* chore(rename): Rename functions to be compliant with project style

* chore(formatting): Reformatted docs

* docs(changes): Modified the service and path to it in the documentation.

* chore(format): Reformated with Gofump
2022-10-04 18:01:09 +03:00

50 lines
1.6 KiB
Go

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)
}