APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name (#6117)
* APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name
* updated v3 deleteReaction endpoint
* update parameter of app.DeleteReactionForPost()
* update utils.IsValidAlphaNum, add utils.IsValidAlphaNumHyphenUnderscore, and add related tests
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
e62afeace0
Коммит
ecb10ed62f
@@ -193,3 +193,127 @@ func TestGetReactions(t *testing.T) {
|
||||
_, resp = th.SystemAdminClient.GetReactions(postId)
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestDeleteReaction(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
userId := th.BasicUser.Id
|
||||
user2Id := th.BasicUser2.Id
|
||||
postId := th.BasicPost.Id
|
||||
|
||||
r1 := &model.Reaction{
|
||||
UserId: userId,
|
||||
PostId: postId,
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
app.SaveReactionForPost(r1)
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 1 {
|
||||
t.Fatal("didn't save reaction correctly")
|
||||
}
|
||||
|
||||
ok, resp := Client.DeleteReaction(r1)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("should have returned true")
|
||||
}
|
||||
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
|
||||
t.Fatal("should have deleted reaction")
|
||||
}
|
||||
|
||||
// deleting one reaction when a post has multiple reactions
|
||||
r2 := &model.Reaction{
|
||||
UserId: userId,
|
||||
PostId: postId,
|
||||
EmojiName: "smile-",
|
||||
}
|
||||
|
||||
app.SaveReactionForPost(r1)
|
||||
app.SaveReactionForPost(r2)
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
|
||||
t.Fatal("didn't save reactions correctly")
|
||||
}
|
||||
|
||||
_, resp = Client.DeleteReaction(r2)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 1 || *reactions[0] != *r1 {
|
||||
t.Fatal("should have deleted 1 reaction only")
|
||||
}
|
||||
|
||||
// deleting a reaction made by another user
|
||||
r3 := &model.Reaction{
|
||||
UserId: user2Id,
|
||||
PostId: postId,
|
||||
EmojiName: "smile_",
|
||||
}
|
||||
|
||||
th.LoginBasic2()
|
||||
app.SaveReactionForPost(r3)
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
|
||||
t.Fatal("didn't save reaction correctly")
|
||||
}
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
ok, resp = Client.DeleteReaction(r3)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
if ok {
|
||||
t.Fatal("should have returned false")
|
||||
}
|
||||
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
|
||||
t.Fatal("should have not deleted a reaction")
|
||||
}
|
||||
|
||||
r1.PostId = GenerateTestId()
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
r1.PostId = "junk"
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
r1.PostId = postId
|
||||
r1.UserId = GenerateTestId()
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
r1.UserId = "junk"
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
r1.UserId = userId
|
||||
r1.EmojiName = ""
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
r1.EmojiName = strings.Repeat("a", 65)
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
r1.EmojiName = "smile"
|
||||
|
||||
_, resp = Client.DeleteReaction(r1)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.DeleteReaction(r1)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.DeleteReaction(r3)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
|
||||
t.Fatal("should have deleted both reactions")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user