forked from moussetc/mattermost-plugin-giphy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_test.go
53 lines (42 loc) · 1.32 KB
/
plugin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/plugin/plugintest"
"github.com/mattermost/mattermost-server/plugin/plugintest/mock"
)
func TestGetGifUrl(t *testing.T) {
p := &GiphyPlugin{}
p.configuration.Store(&GiphyPluginConfiguration{Language: "fr", Rating: "", Rendition: "fixed_height_small"})
text, err := p.getGifURL("cat")
if err != nil {
t.Errorf("Error while retrieving gif %v", err)
}
if text == "" {
t.Errorf("Text is empty, it should be a GIF URL")
}
}
func TestPlugin(t *testing.T) {
configuration := GiphyPluginConfiguration{
Language: "fr",
Rating: "",
Rendition: "fixed_height_small",
}
api := &plugintest.API{}
api.On("LoadPluginConfiguration", mock.AnythingOfType("*main.GiphyPluginConfiguration")).Return(func(dest interface{}) error {
*dest.(*GiphyPluginConfiguration) = configuration
return nil
})
api.On("RegisterCommand", mock.Anything).Return(nil)
api.On("UnregisterCommand", mock.Anything, mock.Anything).Return(nil)
p := GiphyPlugin{}
assert.Nil(t, p.OnActivate(api))
command := &model.CommandArgs{
Command: "/gif cute doggo",
}
response, err := p.ExecuteCommand(command)
assert.Nil(t, err)
assert.NotNil(t, response)
assert.Nil(t, p.OnDeactivate())
}