-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MI-3132] Fixed the issue of infinite loop when editing messages and …
…a potential bug related to no. of channel members (#154) * [MI-3132] Fixed the issue of infinite loop when editing messages and fixed a potential bug related to no. of channel members Added the logic to continue the flow if we get PaymentRequired error from Graph API when updating a message Increased the no. of channel members that we are fetching from the Mattermost API Modified the unit tests * [MI-3132] Added a comment
- Loading branch information
1 parent
abd6df6
commit 5b68612
Showing
3 changed files
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package main | |
import ( | ||
"bytes" | ||
"errors" | ||
"math" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -39,15 +40,15 @@ func TestMessageWillBePosted(t *testing.T) { | |
Name: "MessageWillBePosted: Unable to get the channel members", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(nil, testutils.GetInternalServerAppError("unable to get the channel members")).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(nil, testutils.GetInternalServerAppError("unable to get the channel members")).Times(1) | ||
}, | ||
ExpectedPost: testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()), | ||
}, | ||
{ | ||
Name: "MessageWillBePosted: Unable to get the user", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetUser", testutils.GetID()).Return(nil, testutils.GetInternalServerAppError("unable to get the user")).Times(1) | ||
}, | ||
ExpectedPost: testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()), | ||
|
@@ -56,7 +57,7 @@ func TestMessageWillBePosted(t *testing.T) { | |
Name: "MessageWillBePosted: User is ms teams user", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "test@msteamssync"), nil).Times(1) | ||
api.On("GetUser", testutils.GetID()).Return(&model.User{ | ||
Username: "msteams_mockUser", | ||
|
@@ -70,7 +71,7 @@ func TestMessageWillBePosted(t *testing.T) { | |
Name: "MessageWillBePosted: User is not ms teams user", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), nil).Times(2) | ||
}, | ||
ExpectedPost: testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()), | ||
|
@@ -323,7 +324,7 @@ func TestMessageHasBeenUpdated(t *testing.T) { | |
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), nil).Times(1) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: model.NewString("/")}}, nil).Times(2) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
|
@@ -375,7 +376,7 @@ func TestMessageHasBeenUpdated(t *testing.T) { | |
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), nil).Times(1) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(nil, testutils.GetInternalServerAppError("unable to get channel members")).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(nil, testutils.GetInternalServerAppError("unable to get channel members")).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("GetLinkByChannelID", testutils.GetChannelID()).Return(nil, nil).Times(1) | ||
|
@@ -390,7 +391,7 @@ func TestMessageHasBeenUpdated(t *testing.T) { | |
api.On("LogError", "Unable to handle message update", "error", mock.Anything).Times(1) | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), nil).Times(1) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("GetLinkByChannelID", testutils.GetChannelID()).Return(nil, nil).Times(1) | ||
|
@@ -407,7 +408,7 @@ func TestMessageHasBeenUpdated(t *testing.T) { | |
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "[email protected]"), nil).Times(1) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("GetLinkByChannelID", testutils.GetChannelID()).Return(nil, nil).Times(1) | ||
|
@@ -536,7 +537,7 @@ func TestSetChatReaction(t *testing.T) { | |
SetupAPI: func(api *plugintest.API) { | ||
api.On("LogWarn", "Error creating post reaction", "error", mock.Anything) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: model.NewString("/")}}, nil).Times(2) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
|
@@ -553,7 +554,7 @@ func TestSetChatReaction(t *testing.T) { | |
Name: "SetChatReaction: Valid", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: model.NewString("/")}}, nil).Times(2) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
|
@@ -712,7 +713,7 @@ func TestUnsetChatReaction(t *testing.T) { | |
SetupAPI: func(api *plugintest.API) { | ||
api.On("LogWarn", "Error creating post", "error", mock.Anything) | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: model.NewString("/")}}, nil).Times(2) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
|
@@ -729,7 +730,7 @@ func TestUnsetChatReaction(t *testing.T) { | |
Name: "UnsetChatReaction: Valid", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: model.NewString("/")}}, nil).Times(2) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
|
@@ -1604,7 +1605,7 @@ func TestGetChatIDForChannel(t *testing.T) { | |
Name: "GetChatIDForChannel: Unable to get the channel members", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeGroup), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(nil, testutils.GetInternalServerAppError("unable to get the channel members")).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(nil, testutils.GetInternalServerAppError("unable to get the channel members")).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) {}, | ||
SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) {}, | ||
|
@@ -1614,7 +1615,7 @@ func TestGetChatIDForChannel(t *testing.T) { | |
Name: "GetChatIDForChannel: Unable to store users", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeGroup), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("MattermostToTeamsUserID", testutils.GetID()).Return("", errors.New("unable to store the user")).Times(1) | ||
|
@@ -1626,7 +1627,7 @@ func TestGetChatIDForChannel(t *testing.T) { | |
Name: "GetChatIDForChannel: Unable to get the client", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeGroup), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("MattermostToTeamsUserID", testutils.GetID()).Return("mockTeamsUserID", nil).Times(2) | ||
|
@@ -1639,7 +1640,7 @@ func TestGetChatIDForChannel(t *testing.T) { | |
Name: "GetChatIDForChannel: Unable to create or get chat for users", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeGroup), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("MattermostToTeamsUserID", testutils.GetID()).Return("mockTeamsUserID", nil).Times(2) | ||
|
@@ -1654,7 +1655,7 @@ func TestGetChatIDForChannel(t *testing.T) { | |
Name: "GetChatIDForChannel: Valid", | ||
SetupAPI: func(api *plugintest.API) { | ||
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeGroup), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, 10).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1) | ||
}, | ||
SetupStore: func(store *storemocks.Store) { | ||
store.On("MattermostToTeamsUserID", testutils.GetID()).Return("mockTeamsUserID", nil).Times(2) | ||
|