diff --git a/pkg/channel/create_test.go b/pkg/channel/create_test.go index cce601d..632a6bd 100644 --- a/pkg/channel/create_test.go +++ b/pkg/channel/create_test.go @@ -12,9 +12,6 @@ import ( func TestCreateGroupChannel(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - channel := NewChannel(client) - createChannelRequest := CreateGroupChannelRequest{ UserIDs: []string{"42", "43"}, Name: "name", @@ -37,7 +34,10 @@ func TestCreateGroupChannel(t *testing.T) { Name: "name", } - client.OnPost("/group_channels", createChannelRequest, &CreateGroupChannelResponse{}).Return(createChannelResponse, nil) + client := client.NewClientMock(t). + OnPost("/group_channels", createChannelRequest, &CreateGroupChannelResponse{}).TypedReturns(createChannelResponse, nil).Once(). + Parent + channel := NewChannel(client) cur, err := channel.CreateGroupChannel(context.Background(), createChannelRequest) require.NoError(t, err) diff --git a/pkg/channel/list_test.go b/pkg/channel/list_test.go index e405bfa..d108ec3 100644 --- a/pkg/channel/list_test.go +++ b/pkg/channel/list_test.go @@ -25,9 +25,6 @@ func TestPtr(t *testing.T) { func TestListGroupChannels(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - channel := NewChannel(client) - url := "/group_channels" url += "?channel_urls=channel-url1%2Cchannel-url2" url += "&created_after=43" @@ -111,7 +108,10 @@ func TestListGroupChannels(t *testing.T) { }}, } - client.OnGet(url, nil, &ListGroupChannelResponse{}).Return(listChannelsResponse, nil) + client := client.NewClientMock(t). + OnGet(url, nil, &ListGroupChannelResponse{}).TypedReturns(listChannelsResponse, nil).Once(). + Parent + channel := NewChannel(client) cur, err := channel.ListGroupChannels(context.Background(), listChannelsRequest) require.NoError(t, err) diff --git a/pkg/channel/mark_all_messages_read_test.go b/pkg/channel/mark_all_messages_read_test.go index ad5a9b3..91c4b37 100644 --- a/pkg/channel/mark_all_messages_read_test.go +++ b/pkg/channel/mark_all_messages_read_test.go @@ -11,11 +11,11 @@ import ( func TestMarkAsRead(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) + client := client.NewClientMock(t). + OnPut("/group_channels/channel-url/messages/mark_as_read", markAsReadRequest{UserID: "user-id"}, nil).TypedReturns(nil, nil).Once(). + Parent channel := NewChannel(client) - client.OnPut("/group_channels/channel-url/messages/mark_as_read", markAsReadRequest{UserID: "user-id"}, nil).Return(nil, nil) - err := channel.MarkAsRead(context.Background(), "channel-url", "user-id") require.NoError(t, err) } diff --git a/pkg/channel/typing_test.go b/pkg/channel/typing_test.go index 0201296..afd5ad2 100644 --- a/pkg/channel/typing_test.go +++ b/pkg/channel/typing_test.go @@ -11,11 +11,11 @@ import ( func TestStartTyping(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) + client := client.NewClientMock(t). + OnPost("/group_channels/channel-url/typing", typingRequest{UserIDs: []string{"user-id"}}, nil).TypedReturns(nil, nil).Once(). + Parent channel := NewChannel(client) - client.OnPost("/group_channels/channel-url/typing", typingRequest{UserIDs: []string{"user-id"}}, nil).Return(nil, nil) - err := channel.StartTyping(context.Background(), "channel-url", []string{"user-id"}) require.NoError(t, err) } @@ -23,11 +23,11 @@ func TestStartTyping(t *testing.T) { func TestStopTyping(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) + client := client.NewClientMock(t). + OnDelete("/group_channels/channel-url/typing", typingRequest{UserIDs: []string{"user-id"}}, nil).TypedReturns(nil, nil).Once(). + Parent channel := NewChannel(client) - client.OnDelete("/group_channels/channel-url/typing", typingRequest{UserIDs: []string{"user-id"}}, nil).Return(nil, nil) - err := channel.StopTyping(context.Background(), "channel-url", []string{"user-id"}) require.NoError(t, err) } diff --git a/pkg/channel/update_test.go b/pkg/channel/update_test.go index 2d9427f..0f5527d 100644 --- a/pkg/channel/update_test.go +++ b/pkg/channel/update_test.go @@ -12,9 +12,6 @@ import ( func TestUpdateGroupChannel(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - channel := NewChannel(client) - updateChannelRequest := UpdateGroupChannelRequest{ Name: "channel-name", CoverURL: "cover-url", @@ -31,7 +28,10 @@ func TestUpdateGroupChannel(t *testing.T) { Name: "channel-name", } - client.OnPut("/group_channels/channel-url", updateChannelRequest, &UpdateGroupChannelResponse{}).Return(updateChannelResponse, nil) + client := client.NewClientMock(t). + OnPut("/group_channels/channel-url", updateChannelRequest, &UpdateGroupChannelResponse{}).TypedReturns(updateChannelResponse, nil).Once(). + Parent + channel := NewChannel(client) cur, err := channel.UpdateGroupChannel(context.Background(), "channel-url", updateChannelRequest) require.NoError(t, err) diff --git a/pkg/message/list_messages_test.go b/pkg/message/list_messages_test.go index c997473..c0a6c1d 100644 --- a/pkg/message/list_messages_test.go +++ b/pkg/message/list_messages_test.go @@ -12,9 +12,6 @@ import ( func TestListMessages(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - message := NewMessage(client) - url := "/group_channels/url/messages" url += "?custom_types=%2A" url += "&include=true" @@ -66,7 +63,10 @@ func TestListMessages(t *testing.T) { }}, } - client.OnGet(url, nil, &ListMessagesResponse{}).Return(listMessagesResponse, nil) + client := client.NewClientMock(t). + OnGet(url, nil, &ListMessagesResponse{}).TypedReturns(listMessagesResponse, nil).Once(). + Parent + message := NewMessage(client) cur, err := message.ListMessages(context.Background(), ChannelTypeGroup, "url", listMessagesRequest) require.NoError(t, err) diff --git a/pkg/message/send_message_test.go b/pkg/message/send_message_test.go index 1edcbdb..758bf55 100644 --- a/pkg/message/send_message_test.go +++ b/pkg/message/send_message_test.go @@ -167,9 +167,10 @@ func TestSendMessage(t *testing.T) { t.Run(test.name, func(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) + client := client.NewClientMock(t). + OnPost("/group_channels/url/messages", test.smrq, &SendMessageResponse{}).TypedReturns(&test.smrp, nil).Once(). + Parent message := NewMessage(client) - client.OnPost("/group_channels/url/messages", test.smrq, &SendMessageResponse{}).Return(&test.smrp, nil) cur, err := message.SendMessage(context.Background(), ChannelTypeGroup, "url", test.smrq) require.NoError(t, err) diff --git a/pkg/user/create_user_test.go b/pkg/user/create_user_test.go index c192ffd..a743928 100644 --- a/pkg/user/create_user_test.go +++ b/pkg/user/create_user_test.go @@ -12,9 +12,6 @@ import ( func TestCreateUser(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - user := NewUser(client) - createUserRequest := CreateUserRequest{ UserID: "user-id", Nickname: "nickname", @@ -45,7 +42,10 @@ func TestCreateUser(t *testing.T) { }, } - client.OnPost("/users", createUserRequest, &CreateUserResponse{}).Return(createUserResponse, nil) + client := client.NewClientMock(t). + OnPost("/users", createUserRequest, &CreateUserResponse{}).TypedReturns(createUserResponse, nil).Once(). + Parent + user := NewUser(client) cur, err := user.CreateUser(context.Background(), createUserRequest) require.NoError(t, err) diff --git a/pkg/user/joined_channel_test.go b/pkg/user/joined_channel_test.go index 64f3cc4..d3e39e0 100644 --- a/pkg/user/joined_channel_test.go +++ b/pkg/user/joined_channel_test.go @@ -12,9 +12,6 @@ import ( func TestGetGroupChannelCount(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - user := NewUser(client) - getGroupChannelCountRequest := GetGroupChannelCountRequest{ CustomTypes: []string{"custom-type"}, HiddenMode: ModeAll, @@ -26,7 +23,10 @@ func TestGetGroupChannelCount(t *testing.T) { GroupChannelCount: 42, } - client.OnGet("/users/42/group_channel_count", getGroupChannelCountRequest, &GetGroupChannelCountResponse{}).Return(getGroupChannelCountResponse, nil) + client := client.NewClientMock(t). + OnGet("/users/42/group_channel_count", getGroupChannelCountRequest, &GetGroupChannelCountResponse{}).TypedReturns(getGroupChannelCountResponse, nil).Once(). + Parent + user := NewUser(client) cur, err := user.GetGroupChannelCount(context.Background(), "42", getGroupChannelCountRequest) require.NoError(t, err) diff --git a/pkg/user/session_token_test.go b/pkg/user/session_token_test.go index a8e45d6..d8e8df9 100644 --- a/pkg/user/session_token_test.go +++ b/pkg/user/session_token_test.go @@ -12,9 +12,6 @@ import ( func TestGetSessionToken(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - user := NewUser(client) - getSessionTokenRequest := GetSessionTokenRequest{ ExpiresAt: 0, } @@ -24,7 +21,10 @@ func TestGetSessionToken(t *testing.T) { ExpiresAt: 0, } - client.OnPost("/users/42/token", getSessionTokenRequest, &GetSessionTokenResponse{}).Return(getSessionTokenResponse, nil) + client := client.NewClientMock(t). + OnPost("/users/42/token", getSessionTokenRequest, &GetSessionTokenResponse{}).TypedReturns(getSessionTokenResponse, nil).Once(). + Parent + user := NewUser(client) cur, err := user.GetSessionToken(context.Background(), "42", getSessionTokenRequest) require.NoError(t, err) diff --git a/pkg/user/unread_messages_test.go b/pkg/user/unread_messages_test.go index 1b7b119..6a22e24 100644 --- a/pkg/user/unread_messages_test.go +++ b/pkg/user/unread_messages_test.go @@ -12,9 +12,6 @@ import ( func TestGetUnreadMessagesCount(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - user := NewUser(client) - getUnreadMessagesCountRequest := GetUnreadMessagesCountRequest{ CustomTypes: []string{"custom-type"}, SuperMode: SuperModeSuper, @@ -24,7 +21,10 @@ func TestGetUnreadMessagesCount(t *testing.T) { UnreadCount: 42, } - client.OnGet("/users/42/unread_message_count", getUnreadMessagesCountRequest, &GetUnreadMessagesCountResponse{}).Return(getUnreadMessagesCountResponse, nil) + client := client.NewClientMock(t). + OnGet("/users/42/unread_message_count", getUnreadMessagesCountRequest, &GetUnreadMessagesCountResponse{}).TypedReturns(getUnreadMessagesCountResponse, nil).Once(). + Parent + user := NewUser(client) cur, err := user.GetUnreadMessagesCount(context.Background(), "42", getUnreadMessagesCountRequest) require.NoError(t, err) diff --git a/pkg/user/update_user_test.go b/pkg/user/update_user_test.go index fe26ea1..8056eba 100644 --- a/pkg/user/update_user_test.go +++ b/pkg/user/update_user_test.go @@ -12,9 +12,6 @@ import ( func TestUpdateUser(t *testing.T) { t.Parallel() - client := client.NewClientMock(t) - user := NewUser(client) - updateUserRequest := UpdateUserRequest{ Nickname: "nickname", ProfileURL: "profile-url", @@ -45,7 +42,10 @@ func TestUpdateUser(t *testing.T) { }, } - client.OnPut("/users/42", updateUserRequest, &UpdateUserResponse{}).Return(updateUserResponse, nil) + client := client.NewClientMock(t). + OnPut("/users/42", updateUserRequest, &UpdateUserResponse{}).TypedReturns(updateUserResponse, nil).Once(). + Parent + user := NewUser(client) cur, err := user.UpdateUser(context.Background(), "42", updateUserRequest) require.NoError(t, err)