[GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)

* 6798 added a new api to get the bulk reactions for posts

* 6798 added the permsission check before getting the reactions

* GH-6798 added a new app function for the new endpoint

* 6798 added a store method to get reactions for multiple posts

* 6798 connected the app function with the new store function

* 6798 fixed the review comments
Этот коммит содержится в:
Pradeep Murugesan
2019-01-03 14:35:08 +01:00
коммит произвёл Joram Wilander
родитель 7b7b89d5ae
Коммит 99160ff0bc
17 изменённых файлов: 342 добавлений и 0 удалений

Просмотреть файл

@@ -567,3 +567,85 @@ func TestDeleteReaction(t *testing.T) {
}
})
}
func TestGetBulkReactions(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
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"}
post2 := &model.Post{UserId: userId, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
post3 := &model.Post{UserId: userId, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
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)
expectedPostIdsReactionsMap := make(map[string][]*model.Reaction)
expectedPostIdsReactionsMap[post1.Id] = []*model.Reaction{}
expectedPostIdsReactionsMap[post2.Id] = []*model.Reaction{}
expectedPostIdsReactionsMap[post3.Id] = []*model.Reaction{}
expectedPostIdsReactionsMap[post5.Id] = []*model.Reaction{}
userReactions := []*model.Reaction{
{
UserId: userId,
PostId: post1.Id,
EmojiName: "happy",
},
{
UserId: userId,
PostId: post1.Id,
EmojiName: "sad",
},
{
UserId: userId,
PostId: post2.Id,
EmojiName: "smile",
},
{
UserId: user2Id,
PostId: post4.Id,
EmojiName: "smile",
},
}
for _, userReaction := range userReactions {
reactions := expectedPostIdsReactionsMap[userReaction.PostId]
if result := <-th.App.Srv.Store.Reaction().Save(userReaction); result.Err != nil {
t.Fatal(result.Err)
} else {
reactions = append(reactions, result.Data.(*model.Reaction))
}
expectedPostIdsReactionsMap[userReaction.PostId] = reactions
}
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)
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post1.Id], postIdsReactionsMap[post1.Id])
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post2.Id], postIdsReactionsMap[post2.Id])
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post3.Id], postIdsReactionsMap[post3.Id])
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post4.Id], postIdsReactionsMap[post4.Id])
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post5.Id], postIdsReactionsMap[post5.Id])
assert.Equal(t, expectedPostIdsReactionsMap, postIdsReactionsMap)
})
t.Run("get-reactions-as-anonymous-user", func(t *testing.T) {
Client.Logout()
_, resp := Client.GetBulkReactions(postIds)
CheckUnauthorizedStatus(t, resp)
})
}