GH-15624: Added plugin hooks for ReationHasBeenAdded and ReactionHasBeenRemoved (#15765)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
71c371509b
Коммит
3515b4d6c9
@@ -1131,3 +1131,89 @@ func TestHookMetrics(t *testing.T) {
|
||||
metricsMock.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestHookReactionHasBeenAdded(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
var mockAPI plugintest.API
|
||||
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
|
||||
mockAPI.On("LogDebug", "smile").Return(nil)
|
||||
|
||||
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
|
||||
[]string{
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *MyPlugin) ReactionHasBeenAdded(c *plugin.Context, reaction *model.Reaction) {
|
||||
p.API.LogDebug(reaction.EmojiName)
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
reaction := &model.Reaction{
|
||||
UserId: th.BasicUser.Id,
|
||||
PostId: th.BasicPost.Id,
|
||||
EmojiName: "smile",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.SaveReactionForPost(reaction)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestHookReactionHasBeenRemoved(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
var mockAPI plugintest.API
|
||||
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
|
||||
mockAPI.On("LogDebug", "star").Return(nil)
|
||||
|
||||
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
|
||||
[]string{
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *MyPlugin) ReactionHasBeenRemoved(c *plugin.Context, reaction *model.Reaction) {
|
||||
p.API.LogDebug(reaction.EmojiName)
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
reaction := &model.Reaction{
|
||||
UserId: th.BasicUser.Id,
|
||||
PostId: th.BasicPost.Id,
|
||||
EmojiName: "star",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
|
||||
err := th.App.DeleteReactionForPost(reaction)
|
||||
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user