generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* GH-88 Add settings command to toggle daily reminders * settings summary command testcases Co-authored-by: Mattermod <[email protected]>
- Loading branch information
Showing
4 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mattermost/mattermost-server/v5/model" | ||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestSetttingsCommand(t *testing.T) { | ||
api := &plugintest.API{} | ||
api.On("SendEphemeralPost", mock.AnythingOfType("string"), mock.Anything).Return(nil) | ||
api.On("KVSet", mock.AnythingOfType("string"), mock.Anything).Return(nil) | ||
|
||
apiKVSetFailed := &plugintest.API{} | ||
apiKVSetFailed.On("SendEphemeralPost", mock.AnythingOfType("string"), mock.Anything).Return(nil) | ||
apiKVSetFailed.On("KVSet", mock.AnythingOfType("string"), mock.Anything).Return(model.NewAppError("failed", "", nil, "", 400)) | ||
|
||
tests := []struct { | ||
name string | ||
api *plugintest.API | ||
args []string | ||
wantErr bool | ||
want bool | ||
}{ | ||
{ | ||
name: "Setting summary successful", | ||
api: api, | ||
args: []string{"summary", "on"}, | ||
wantErr: false, | ||
want: false, | ||
}, | ||
{ | ||
name: "Setting summary failed due to KVSet failed", | ||
api: apiKVSetFailed, | ||
args: []string{"summary", "on"}, | ||
wantErr: true, | ||
want: false, | ||
}, | ||
{ | ||
name: "Setting summary failed due to invalid number of arguments", | ||
api: api, | ||
args: []string{"summary", "on", "extraValue"}, | ||
wantErr: true, | ||
want: true, | ||
}, | ||
{ | ||
name: "Setting summary failed due to no arguments", | ||
api: api, | ||
args: []string{}, | ||
wantErr: true, | ||
want: true, | ||
}, | ||
{ | ||
name: "Setting summary failed due to invalid argument", | ||
api: api, | ||
args: []string{"summary", "test"}, | ||
wantErr: true, | ||
want: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
plugin := Plugin{} | ||
plugin.SetAPI(tt.api) | ||
|
||
resp, err := plugin.runSettingsCommand(tt.args, &model.CommandArgs{}) | ||
if tt.wantErr != (err != nil) { | ||
t.Errorf("runSettingsCommand wantErr= %v got err= %v", tt.wantErr, err) | ||
return | ||
} | ||
|
||
if tt.want != resp { | ||
t.Errorf("runSettingsCommand got= %v want= %v", resp, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters