[MM-37557] Move error out of client4 response (#18101)
* Return an error seperately from Response * Remove BuildErrorResponse * Drop Response.Error from model/client4.go * Migrate require.Nil checks * Migrate require.NotNil checks * More manual fixes * Move error check out of CheckOKStatus and CheckCreatedStatus * Move error check out of CheckForbiddenStatus * Move error check out of CheckUnauthorizedStatus * Move error check out of CheckNotFoundStatus * Move error check out of CheckBadRequestStatus * Move error check out of CheckNotImplementedStatus and CheckRequestEntityTooLargeStatus * Move error check out of CheckInternalErrorStatus * Move error check out of CheckServiceUnavailableStatus * Remove error check from checkHTTPStatus * Remove remaining references to Response.Error * Check previously unchecked errors * Manually fix compile and linter errors * Return error in CreateWebSocket methods * Return error instead of *AppError in DoApi methods * Manually fix bad replacments * Conistently return Response and error * Use err instead of seperate bool return value to indicate success * Reduce ussage of model.AppError in web/oauth_test.go * Remove client4.Must * Check error in buf.ReadFrom * Fix failing tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
96593580ae
Коммит
a8ca5c423f
@@ -16,7 +16,7 @@ import (
|
||||
func TestSaveReaction(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
userId := th.BasicUser.Id
|
||||
postId := th.BasicPost.Id
|
||||
|
||||
@@ -33,61 +33,63 @@ func TestSaveReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("successful-reaction", func(t *testing.T) {
|
||||
rr, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, reaction.UserId, rr.UserId, "UserId did not match")
|
||||
require.Equal(t, reaction.PostId, rr.PostId, "PostId did not match")
|
||||
require.Equal(t, reaction.EmojiName, rr.EmojiName, "EmojiName did not match")
|
||||
require.NotEqual(t, 0, rr.CreateAt, "CreateAt should exist")
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "didn't save reaction correctly")
|
||||
})
|
||||
|
||||
t.Run("duplicated-reaction", func(t *testing.T) {
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
_, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have not save duplicated reaction")
|
||||
})
|
||||
|
||||
t.Run("save-second-reaction", func(t *testing.T) {
|
||||
reaction.EmojiName = "sad"
|
||||
|
||||
rr, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, rr.EmojiName, reaction.EmojiName, "EmojiName did not match")
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err, "error saving multiple reactions")
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr, "error saving multiple reactions")
|
||||
require.Equal(t, len(reactions), 2, "should have save multiple reactions")
|
||||
})
|
||||
|
||||
t.Run("saving-special-case", func(t *testing.T) {
|
||||
reaction.EmojiName = "+1"
|
||||
|
||||
rr, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, reaction.EmojiName, rr.EmojiName, "EmojiName did not match")
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 3, len(reactions), "should have save multiple reactions")
|
||||
})
|
||||
|
||||
t.Run("react-to-not-existing-post-id", func(t *testing.T) {
|
||||
reaction.PostId = GenerateTestId()
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-to-not-valid-post-id", func(t *testing.T) {
|
||||
reaction.PostId = "junk"
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -95,14 +97,16 @@ func TestSaveReaction(t *testing.T) {
|
||||
reaction.PostId = postId
|
||||
reaction.UserId = GenerateTestId()
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-as-not-valid-user-id", func(t *testing.T) {
|
||||
reaction.UserId = "junk"
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -110,35 +114,40 @@ func TestSaveReaction(t *testing.T) {
|
||||
reaction.UserId = userId
|
||||
reaction.EmojiName = ""
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-as-not-valid-emoji-name", func(t *testing.T) {
|
||||
reaction.EmojiName = strings.Repeat("a", 65)
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-as-other-user", func(t *testing.T) {
|
||||
reaction.EmojiName = "smile"
|
||||
otherUser := th.CreateUser()
|
||||
Client.Logout()
|
||||
Client.Login(otherUser.Email, otherUser.Password)
|
||||
client.Logout()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-being-not-logged-in", func(t *testing.T) {
|
||||
Client.Logout()
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
client.Logout()
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-as-other-user-being-system-admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.SaveReaction(reaction)
|
||||
_, resp, err := th.SystemAdminClient.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -146,11 +155,12 @@ func TestSaveReaction(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionAddReaction.Id, model.ChannelUserRoleId)
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 3, len(reactions), "should have not created a reactions")
|
||||
th.AddPermissionToRole(model.PermissionAddReaction.Id, model.ChannelUserRoleId)
|
||||
})
|
||||
@@ -158,8 +168,8 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("unable-to-react-in-read-only-town-square", func(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
|
||||
channel, err := th.App.GetChannelByName("town-square", th.BasicTeam.Id, true)
|
||||
assert.Nil(t, err)
|
||||
channel, appErr := th.App.GetChannelByName("town-square", th.BasicTeam.Id, true)
|
||||
assert.Nil(t, appErr)
|
||||
post := th.CreatePostWithClient(th.Client, channel)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
@@ -171,11 +181,12 @@ func TestSaveReaction(t *testing.T) {
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 0, len(reactions), "should have not created a reaction")
|
||||
|
||||
th.App.Srv().RemoveLicense()
|
||||
@@ -194,14 +205,15 @@ func TestSaveReaction(t *testing.T) {
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
err := th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, err)
|
||||
appErr := th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
_, resp := Client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 0, len(reactions), "should have not created a reaction")
|
||||
})
|
||||
}
|
||||
@@ -209,7 +221,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
func TestGetReactions(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
userId := th.BasicUser.Id
|
||||
user2Id := th.BasicUser2.Id
|
||||
postId := th.BasicPost.Id
|
||||
@@ -251,8 +263,8 @@ func TestGetReactions(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("get-reactions", func(t *testing.T) {
|
||||
rr, resp := Client.GetReactions(postId)
|
||||
CheckNoError(t, resp)
|
||||
rr, _, err := client.GetReactions(postId)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, rr, 5)
|
||||
for _, r := range reactions {
|
||||
@@ -261,34 +273,37 @@ func TestGetReactions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-reactions-of-invalid-post-id", func(t *testing.T) {
|
||||
rr, resp := Client.GetReactions("junk")
|
||||
rr, resp, err := client.GetReactions("junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
assert.Empty(t, rr)
|
||||
})
|
||||
|
||||
t.Run("get-reactions-of-not-existing-post-id", func(t *testing.T) {
|
||||
_, resp := Client.GetReactions(GenerateTestId())
|
||||
_, resp, err := client.GetReactions(GenerateTestId())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-anonymous-user", func(t *testing.T) {
|
||||
Client.Logout()
|
||||
client.Logout()
|
||||
|
||||
_, resp := Client.GetReactions(postId)
|
||||
_, resp, err := client.GetReactions(postId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-system-admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.GetReactions(postId)
|
||||
CheckNoError(t, resp)
|
||||
_, _, err := th.SystemAdminClient.GetReactions(postId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeleteReaction(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
userId := th.BasicUser.Id
|
||||
user2Id := th.BasicUser2.Id
|
||||
postId := th.BasicPost.Id
|
||||
@@ -325,47 +340,45 @@ func TestDeleteReaction(t *testing.T) {
|
||||
|
||||
t.Run("delete-reaction", func(t *testing.T) {
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "didn't save reaction correctly")
|
||||
|
||||
ok, resp := Client.DeleteReaction(r1)
|
||||
CheckNoError(t, resp)
|
||||
_, err := client.DeleteReaction(r1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, ok, "should have returned true")
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 0, len(reactions), "should have deleted reaction")
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-when-post-has-multiple-reactions", func(t *testing.T) {
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
th.App.SaveReactionForPost(th.Context, r2)
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, len(reactions), 2, "didn't save reactions correctly")
|
||||
|
||||
_, resp := Client.DeleteReaction(r2)
|
||||
CheckNoError(t, resp)
|
||||
_, err := client.DeleteReaction(r2)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have deleted only 1 reaction")
|
||||
require.Equal(t, *r1, *reactions[0], "should have deleted 1 reaction only")
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-when-plus-one-reaction-name", func(t *testing.T) {
|
||||
th.App.SaveReactionForPost(th.Context, r3)
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 2, len(reactions), "didn't save reactions correctly")
|
||||
|
||||
_, resp := Client.DeleteReaction(r3)
|
||||
CheckNoError(t, resp)
|
||||
_, err := client.DeleteReaction(r3)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have deleted 1 reaction only")
|
||||
require.Equal(t, *r1, *reactions[0], "should have deleted 1 reaction only")
|
||||
})
|
||||
@@ -373,32 +386,33 @@ func TestDeleteReaction(t *testing.T) {
|
||||
t.Run("delete-reaction-made-by-another-user", func(t *testing.T) {
|
||||
th.LoginBasic2()
|
||||
th.App.SaveReactionForPost(th.Context, r4)
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 2, len(reactions), "didn't save reaction correctly")
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
ok, resp := Client.DeleteReaction(r4)
|
||||
resp, err := client.DeleteReaction(r4)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
require.False(t, ok, "should have returned false")
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 2, len(reactions), "should have not deleted a reaction")
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-from-not-existing-post-id", func(t *testing.T) {
|
||||
r1.PostId = GenerateTestId()
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-from-not-valid-post-id", func(t *testing.T) {
|
||||
r1.PostId = "junk"
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -406,14 +420,16 @@ func TestDeleteReaction(t *testing.T) {
|
||||
r1.PostId = postId
|
||||
r1.UserId = GenerateTestId()
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-from-not-valid-user-id", func(t *testing.T) {
|
||||
r1.UserId = "junk"
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -421,34 +437,37 @@ func TestDeleteReaction(t *testing.T) {
|
||||
r1.UserId = userId
|
||||
r1.EmojiName = ""
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-with-not-existing-name", func(t *testing.T) {
|
||||
r1.EmojiName = strings.Repeat("a", 65)
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-as-anonymous-user", func(t *testing.T) {
|
||||
Client.Logout()
|
||||
client.Logout()
|
||||
r1.EmojiName = "smile"
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-as-system-admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.DeleteReaction(r1)
|
||||
CheckNoError(t, resp)
|
||||
_, err := th.SystemAdminClient.DeleteReaction(r1)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.DeleteReaction(r4)
|
||||
CheckNoError(t, resp)
|
||||
_, err = th.SystemAdminClient.DeleteReaction(r4)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 0, len(reactions), "should have deleted both reactions")
|
||||
})
|
||||
|
||||
@@ -458,11 +477,12 @@ func TestDeleteReaction(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PermissionRemoveReaction.Id, model.ChannelUserRoleId)
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
|
||||
_, resp := Client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have not deleted a reactions")
|
||||
th.AddPermissionToRole(model.PermissionRemoveReaction.Id, model.ChannelUserRoleId)
|
||||
})
|
||||
@@ -471,11 +491,12 @@ func TestDeleteReaction(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PermissionRemoveOthersReactions.Id, model.SystemAdminRoleId)
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
|
||||
_, resp := th.SystemAdminClient.DeleteReaction(r1)
|
||||
resp, err := th.SystemAdminClient.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have not deleted a reactions")
|
||||
th.AddPermissionToRole(model.PermissionRemoveOthersReactions.Id, model.SystemAdminRoleId)
|
||||
})
|
||||
@@ -483,8 +504,8 @@ func TestDeleteReaction(t *testing.T) {
|
||||
t.Run("unable-to-delete-reactions-in-read-only-town-square", func(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
|
||||
channel, err := th.App.GetChannelByName("town-square", th.BasicTeam.Id, true)
|
||||
assert.Nil(t, err)
|
||||
channel, appErr := th.App.GetChannelByName("town-square", th.BasicTeam.Id, true)
|
||||
assert.Nil(t, appErr)
|
||||
post := th.CreatePostWithClient(th.Client, channel)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
@@ -495,20 +516,21 @@ func TestDeleteReaction(t *testing.T) {
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
r1, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
r1, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have created a reaction")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
||||
|
||||
_, resp = th.SystemAdminClient.DeleteReaction(r1)
|
||||
resp, err := th.SystemAdminClient.DeleteReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have not deleted a reaction")
|
||||
|
||||
th.App.Srv().RemoveLicense()
|
||||
@@ -527,21 +549,22 @@ func TestDeleteReaction(t *testing.T) {
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
r1, resp := Client.SaveReaction(reaction)
|
||||
CheckNoError(t, resp)
|
||||
r1, _, err := client.SaveReaction(reaction)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, err := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have created a reaction")
|
||||
|
||||
err = th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, err)
|
||||
appErr = th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
_, resp = Client.SaveReaction(r1)
|
||||
_, resp, err := client.SaveReaction(r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
reactions, err = th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, err)
|
||||
reactions, appErr = th.App.GetReactionsForPost(post.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "should have not deleted a reaction")
|
||||
})
|
||||
}
|
||||
@@ -549,7 +572,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
func TestGetBulkReactions(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
userId := th.BasicUser.Id
|
||||
user2Id := th.BasicUser2.Id
|
||||
post1 := &model.Post{UserId: userId, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
@@ -559,11 +582,11 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
post4 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
post5 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
|
||||
post1, _ = Client.CreatePost(post1)
|
||||
post2, _ = Client.CreatePost(post2)
|
||||
post3, _ = Client.CreatePost(post3)
|
||||
post4, _ = Client.CreatePost(post4)
|
||||
post5, _ = Client.CreatePost(post5)
|
||||
post1, _, _ = client.CreatePost(post1)
|
||||
post2, _, _ = client.CreatePost(post2)
|
||||
post3, _, _ = client.CreatePost(post3)
|
||||
post4, _, _ = client.CreatePost(post4)
|
||||
post5, _, _ = client.CreatePost(post5)
|
||||
|
||||
expectedPostIdsReactionsMap := make(map[string][]*model.Reaction)
|
||||
expectedPostIdsReactionsMap[post1.Id] = []*model.Reaction{}
|
||||
@@ -605,8 +628,8 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
postIds := []string{post1.Id, post2.Id, post3.Id, post4.Id, post5.Id}
|
||||
|
||||
t.Run("get-reactions", func(t *testing.T) {
|
||||
postIdsReactionsMap, resp := Client.GetBulkReactions(postIds)
|
||||
CheckNoError(t, resp)
|
||||
postIdsReactionsMap, _, err := client.GetBulkReactions(postIds)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post1.Id], postIdsReactionsMap[post1.Id])
|
||||
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post2.Id], postIdsReactionsMap[post2.Id])
|
||||
@@ -618,9 +641,10 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-anonymous-user", func(t *testing.T) {
|
||||
Client.Logout()
|
||||
client.Logout()
|
||||
|
||||
_, resp := Client.GetBulkReactions(postIds)
|
||||
_, resp, err := client.GetBulkReactions(postIds)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user