forked from tomMoulard/sendbird-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
45 lines (36 loc) · 1.18 KB
/
message_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
package message_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tomMoulard/sendbird-go/pkg/message"
)
// iencli wraps the message.Message interface.
type iencli struct {
message message.Message
}
// SendMessage wraps the sends message method.
func (c *iencli) SendMessage(ctx context.Context, channelType message.ChannelType, channelURL string, sendMessageRequest message.SendMessageRequest) (*message.SendMessageResponse, error) {
got, err := c.message.SendMessage(ctx, channelType, channelURL, sendMessageRequest)
if err != nil {
return nil, fmt.Errorf("failed to send message: %w", err)
}
return got, nil
}
func TestSendMessage(t *testing.T) {
t.Parallel()
req := message.SendMessageRequest{
Message: "hello",
}
messageMock := message.NewMessageMock(t).
OnSendMessage(message.ChannelTypeGroup, "channelURL", req).TypedReturns(&message.SendMessageResponse{MessageID: 42}, nil).Once().
Parent
c := &iencli{
message: messageMock,
}
got, err := c.SendMessage(context.Background(), message.ChannelTypeGroup, "channelURL", req)
require.NoError(t, err)
assert.Equal(t, 42, got.MessageID)
}