Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-507,699] Add Support for DM subscriptions for watchers and reporter #872

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ endif
## Ensures NPM dependencies are installed without having to run this all the time.
webapp/.npminstall:
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) install
cd webapp && $(NPM) install --verbose
touch $@
endif

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mattermost/mattermost-plugin-jira
go 1.13

require (
github.com/andygrunwald/go-jira v1.10.0
github.com/andygrunwald/go-jira v1.15.1
github.com/dghubble/oauth1 v0.5.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gorilla/mux v1.8.0
Expand Down
21 changes: 12 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/andygrunwald/go-jira v1.10.0 h1:+HPPK7++6/hW8ygtr2Yc0wd+Qu139NrWiTD/r1cYxO0=
github.com/andygrunwald/go-jira v1.10.0/go.mod h1:KEsrADP1cEXRxVWTaDtpLyyZN1LM9p6Jn8W5+sDzxhc=
github.com/andygrunwald/go-jira v1.15.1 h1:6J9aYKb9sW8bxv3pBLYBrs0wdsFrmGI5IeTgWSKWKc8=
github.com/andygrunwald/go-jira v1.15.1/go.mod h1:GIYN1sHOIsENWUZ7B4pDeT/nxEtrZpE8l0987O67ZR8=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/arrow/go/arrow v0.0.0-20200601151325-b2287a20f230/go.mod h1:QNYViu/X0HXDHw7m3KXzWSVXIbfUvJqBFe6Gj8/pYA0=
Expand Down Expand Up @@ -524,7 +524,6 @@ github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/fatih/structs v1.0.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fcjr/aia-transport-go v1.2.2/go.mod h1:onSqSq3tGkM14WusDx7q9FTheS9R1KBtD+QBWI6zG/w=
Expand Down Expand Up @@ -653,7 +652,10 @@ github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5
github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog=
github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-migrate/migrate/v4 v4.14.1/go.mod h1:l7Ks0Au6fYHuUIxUhQ0rcVX1uLlJg54C/VvW7tvxSz0=
github.com/golang-migrate/migrate/v4 v4.15.1/go.mod h1:/CrBenUbcDqsW29jGTR/XFqCfVi/Y6mHXlooCcSOJMQ=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
Expand Down Expand Up @@ -719,13 +721,14 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-github/v35 v35.2.0/go.mod h1:s0515YVTI+IMrDoy9Y4pHt9ShGpzHvHO8rZ7L7acgvs=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down Expand Up @@ -1569,8 +1572,8 @@ github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/trivago/tgo v1.0.1 h1:bxatjJIXNIpV18bucU4Uk/LaoxvxuOlp/oowRHyncLQ=
github.com/trivago/tgo v1.0.1/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM=
github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/tylerb/graceful v1.2.15/go.mod h1:LPYTbOYmUTdabwRt0TGhLllQ0MUNbs0Y5q1WXJOI9II=
Expand Down Expand Up @@ -1721,7 +1724,6 @@ golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -2057,6 +2059,7 @@ golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBan
golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
34 changes: 32 additions & 2 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type UserService interface {
// ProjectService is the interface for project-related APIs.
type ProjectService interface {
GetProject(key string) (*jira.Project, error)
ListProjects(query string, limit int) (jira.ProjectList, error)
GetAllProjectKeys() ([]string, error)
}

// SearchService is the interface for search-related APIs.
Expand All @@ -78,6 +78,7 @@ type IssueService interface {
GetTransitions(issueKey string) ([]jira.Transition, error)
UpdateAssignee(issueKey string, user *jira.User) error
UpdateComment(issueKey string, comment *jira.Comment) (*jira.Comment, error)
GetWatchers(instanceID, issueKey string, connection *Connection) (*jira.Watches, error)
}

// JiraClient is the common implementation of most Jira APIs, except those that are
Expand Down Expand Up @@ -168,6 +169,20 @@ func (client JiraClient) RESTPostAttachment(issueID string, data []byte, name st
return attachments[0], nil
}

func (client JiraClient) GetAllProjectKeys() ([]string, error) {
projectList, resp, err := client.Jira.Project.GetList()
if err != nil {
return nil, userFriendlyJiraError(resp, err)
}

keys := make([]string, len(*projectList))
for index, project := range *projectList {
keys[index] = project.Key
}

return keys, nil
}

// GetProject returns a Project by key.
func (client JiraClient) GetProject(key string) (*jira.Project, error) {
project, resp, err := client.Jira.Project.Get(key)
Expand All @@ -186,6 +201,21 @@ func (client JiraClient) GetIssue(key string, options *jira.GetQueryOptions) (*j
return issue, nil
}

// GetWatchers returns an array of Jira users watching a given issue.
func (client JiraClient) GetWatchers(instanceID, issueKey string, connection *Connection) (*jira.Watches, error) {
var watchers jira.Watches
params := map[string]string{
"accountId": connection.AccountID,
}

endpoint := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers", instanceID, issueKey)

if err := client.RESTGet(endpoint, params, &watchers); err != nil {
return nil, err
}
return &watchers, nil
}

// GetTransitions returns transitions for an issue with issueKey.
func (client JiraClient) GetTransitions(issueKey string) ([]jira.Transition, error) {
transitions, resp, err := client.Jira.Issue.GetTransitions(issueKey)
Expand Down Expand Up @@ -391,7 +421,7 @@ func endpointURL(endpoint string) (string, error) {
return "", err
}
if parsedURL.Scheme == "" {
// relative path
// Relative path
endpoint = path.Join("/rest/api", endpoint)
}
return endpoint, nil
Expand Down
48 changes: 0 additions & 48 deletions server/client_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"encoding/json"
"strconv"

jira "github.com/andygrunwald/go-jira"
"github.com/pkg/errors"
Expand Down Expand Up @@ -67,50 +66,3 @@ func (client jiraCloudClient) GetUserGroups(connection *Connection) ([]*jira.Use
}
return groups, nil
}

func (client jiraCloudClient) ListProjects(query string, limit int) (jira.ProjectList, error) {
type searchResult struct {
Values jira.ProjectList `json:"values"`
StartAt int `json:"startAt"`
MaxResults int `json:"maxResults"`
Total int `json:"total"`
IsLast bool `json:"isLast"`
}

remaining := 50
fetchAll := false
if limit > 0 {
remaining = limit
}
if limit < 0 {
fetchAll = true
}

var out jira.ProjectList
for {
opts := map[string]string{
"startAt": strconv.Itoa(len(out)),
"maxResults": strconv.Itoa(remaining),
"expand": "issueTypes",
}
var result searchResult
err := client.RESTGet("/3/project/search", opts, &result)
if err != nil {
return nil, err
}
if len(result.Values) > remaining {
result.Values = result.Values[:remaining]
}
out = append(out, result.Values...)
remaining -= len(result.Values)

if !fetchAll && remaining == 0 {
// Got enough.
return out, nil
}
if len(result.Values) == 0 || result.IsLast {
// Ran out of results.
return out, nil
}
}
}
15 changes: 0 additions & 15 deletions server/client_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,3 @@ func (client jiraServerClient) GetUserGroups(connection *Connection) ([]*jira.Us
}
return result.Groups.Items, nil
}

func (client jiraServerClient) ListProjects(query string, limit int) (jira.ProjectList, error) {
plist, resp, err := client.Jira.Project.GetList()
if err != nil {
return nil, userFriendlyJiraError(resp, err)
}
if plist == nil {
return jira.ProjectList{}, nil
}
result := *plist
if limit > 0 && len(result) > limit {
result = result[:limit]
}
return result, nil
}
32 changes: 27 additions & 5 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,29 @@ func createSettingsCommand(optInstance bool) *model.AutocompleteData {
"list", "", "View your current settings")
settings.AddCommand(list)

notifications := model.NewAutocompleteData(
"notifications", "[on|off]", "Update your user notifications settings")
notifications.AddStaticListArgument("value", true, []model.AutocompleteListItem{
setting := []model.AutocompleteListItem{
{HelpText: "Turn notifications on", Item: "on"},
{HelpText: "Turn notifications off", Item: "off"},
})
}

notifications := model.NewAutocompleteData(
"notifications", "[assignee|mention|reporter|watching]", "manage notifications")

assigneeNotifications := model.NewAutocompleteData(subCommandAssignee, "", "manage assignee notifications")
assigneeNotifications.AddStaticListArgument("value", true, setting)

mentionNotifications := model.NewAutocompleteData(subCommandMention, "", "manage mention notifications")
mentionNotifications.AddStaticListArgument("value", true, setting)

reporterNotifications := model.NewAutocompleteData(subCommandReporter, "", "manage reporter notifications")
reporterNotifications.AddStaticListArgument("value", true, setting)

watchingNotifications := model.NewAutocompleteData(subCommandWatching, "", "manage watching notifications")
reporterNotifications.AddStaticListArgument("value", true, setting)
notifications.AddCommand(assigneeNotifications)
notifications.AddCommand(mentionNotifications)
notifications.AddCommand(reporterNotifications)
notifications.AddCommand(watchingNotifications)
withFlagInstance(notifications, optInstance, routeAutocompleteInstalledInstanceWithAlias)
settings.AddCommand(notifications)

Expand Down Expand Up @@ -367,10 +384,12 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, commandArgs *model.CommandArg
if err != nil {
return p.responsef(commandArgs, err.Error()), nil
}

args := strings.Fields(commandArgs.Command)
if len(args) == 0 || args[0] != "/jira" {
return p.help(commandArgs), nil
}

return jiraCommandHandler.Handle(p, c, commandArgs, args[1:]...), nil
}

Expand Down Expand Up @@ -583,7 +602,10 @@ func executeSettings(p *Plugin, c *plugin.Context, header *model.CommandArgs, ar

switch args[0] {
case "list":
return p.responsef(header, "Current settings:\n%s", conn.Settings.String())
if conn.Settings != nil {
return p.responsef(header, "Current settings:\n%s", conn.Settings.String())
}
return p.responsef(header, "Please connect to Jira account using the command `/jira connect`")
case "notifications":
return p.settingsNotifications(header, instance.GetID(), user.MattermostUserID, conn, args)
default:
Expand Down
59 changes: 48 additions & 11 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ func getMockUserStoreKV() mockUserStoreKV {
},
}

trueValue := true
withNotifications := connection // copy
withNotifications.Settings = &ConnectionSettings{Notifications: true}
withNotifications.Settings = &ConnectionSettings{
Notifications: trueValue,
SendNotificationsForMention: &trueValue,
SendNotificationsForAssignee: &trueValue,
SendNotificationsForReporter: &trueValue,
SendNotificationsForWatching: &trueValue,
}

return mockUserStoreKV{
users: map[types.ID]*User{
Expand Down Expand Up @@ -165,12 +172,12 @@ func TestPlugin_ExecuteCommand_Settings(t *testing.T) {
"no params, with notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings", UserId: mockUserIDWithNotifications},
numInstances: 1,
expectedMsg: "Current settings:\n\tNotifications: on",
expectedMsg: "Current settings:\n\t- Notifications for assignee: on \n\t- Notifications for mention: on \n\t- Notifications for reporter: on \n\t- Notifications for watching: on",
},
"no params, without notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "Current settings:\n\tNotifications: off",
expectedMsg: "Current settings:\n\t- Notifications for assignee: off \n\t- Notifications for mention: off \n\t- Notifications for reporter: off \n\t- Notifications for watching: off",
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
},
"unknown setting": {
commandArgs: &model.CommandArgs{Command: "/jira settings" + " test", UserId: mockUserIDWithoutNotifications},
Expand All @@ -180,22 +187,52 @@ func TestPlugin_ExecuteCommand_Settings(t *testing.T) {
"set notifications without value": {
commandArgs: &model.CommandArgs{Command: "/jira settings" + " notifications", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "`/jira settings notifications [value]`\n* Invalid value. Accepted values are: `on` or `off`.",
expectedMsg: "`/jira settings notifications [assignee|mention|reporter|watching] [value]`\n* Invalid value. Accepted values are: `on` or `off`.",
},
"set notification with unknown value": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications test", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "`/jira settings notifications [value]`\n* Invalid value. Accepted values are: `on` or `off`.",
expectedMsg: "`/jira settings notifications [assignee|mention|reporter|watching] [value]`\n* Invalid value. Accepted values are: `on` or `off`.",
},
"enable assignee notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications assignee on", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tAssignee notifications on.",
},
"disable assignee notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications assignee off", UserId: mockUserIDWithNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tAssignee notifications off.",
},
"enable reporter notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications reporter on", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tReporter notifications on.",
},
"disable reporter notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications reporter off", UserId: mockUserIDWithNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tReporter notifications off.",
},
"enable mention notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications mention on", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tMention notifications on.",
},
"disable mention notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications mention off", UserId: mockUserIDWithNotifications},
numInstances: 1,
expectedMsg: "Settings updated.\n\tMention notifications off.",
},
"enable notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications on", UserId: mockUserIDWithoutNotifications},
"enable watching notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications watching on", UserId: mockUserIDWithoutNotifications},
numInstances: 1,
expectedMsg: "Settings updated. Notifications on.",
expectedMsg: "Settings updated.\n\tWatching notifications on.",
},
"disable notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications off", UserId: mockUserIDWithNotifications},
"disable watching notifications": {
commandArgs: &model.CommandArgs{Command: "/jira settings notifications watching off", UserId: mockUserIDWithNotifications},
numInstances: 1,
expectedMsg: "Settings updated. Notifications off.",
expectedMsg: "Settings updated.\n\tWatching notifications off.",
},
}
for name, tt := range tests {
Expand Down
Loading