-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3137 from target/slack-usergroup-smoke
feat: add happy path smoke test for slack user groups
- Loading branch information
Showing
6 changed files
with
204 additions
and
7 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
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,61 @@ | ||
package mockslack | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type UserGroupsUsersUpdateOptions struct { | ||
Usergroup string | ||
Users []string | ||
} | ||
|
||
// UserGroupsUsersUpdate updates the list of users within a user group and returns the user group. | ||
func (st *API) UserGroupsUsersUpdate(ctx context.Context, opts UserGroupsUsersUpdateOptions) (*UserGroup, error) { | ||
err := checkPermission(ctx, "bot", "usergroups:write") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
st.mx.Lock() | ||
defer st.mx.Unlock() | ||
|
||
ug := st.usergroups[opts.Usergroup] | ||
if ug == nil { | ||
return nil, &response{Err: "subteam_not_found"} | ||
} | ||
|
||
if len(opts.Users) == 0 { | ||
return nil, &response{Err: "no_users_provided"} | ||
} | ||
|
||
for _, u := range opts.Users { | ||
if st.users[u] == nil { | ||
return nil, &response{Err: "invalid_users"} | ||
} | ||
} | ||
|
||
ug.Users = opts.Users | ||
|
||
return &ug.UserGroup, nil | ||
} | ||
|
||
// ServeUserGroupsUsersUpdate serves a request to the `usergroups.users.update` API call. | ||
// | ||
// https://api.slack.com/methods/usergroups.users.update | ||
func (s *Server) ServeUserGroupsUsersUpdate(w http.ResponseWriter, req *http.Request) { | ||
ug, err := s.API().UserGroupsUsersUpdate(req.Context(), UserGroupsUsersUpdateOptions{Usergroup: req.FormValue("usergroup"), Users: strings.Split(req.FormValue("users"), ",")}) | ||
if respondErr(w, err) { | ||
return | ||
} | ||
|
||
var resp struct { | ||
response | ||
UserGroup *UserGroup `json:"usergroup"` | ||
} | ||
|
||
resp.UserGroup = ug | ||
|
||
respondWith(w, resp) | ||
} |
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
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,52 @@ | ||
package smoke | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/target/goalert/expflag" | ||
"github.com/target/goalert/test/smoke/harness" | ||
) | ||
|
||
// TestSlackUserGroups tests that the configured notification rule sends the intended notification to the slack user group. | ||
func TestSlackUserGroups(t *testing.T) { | ||
t.Parallel() | ||
|
||
sql := ` | ||
insert into users (id, name, email) | ||
values | ||
({{uuid "uid"}}, 'bob', 'bob@example.com'); | ||
insert into user_contact_methods (id, user_id, name, type, value, pending) | ||
values | ||
({{uuid "cm1"}}, {{uuid "uid"}}, 'personal', 'SLACK_DM', {{slackUserID "bob"}}, false); | ||
insert into schedules (id, name, time_zone) | ||
values | ||
({{uuid "sid"}}, 'testschedule', 'UTC'); | ||
insert into schedule_rules (id, schedule_id, sunday, monday, tuesday, wednesday, thursday, friday, saturday, start_time, end_time, tgt_user_id) | ||
values | ||
({{uuid "ruleID"}}, {{uuid "sid"}}, true, true, true, true, true, true, true, '00:00:00', '00:00:00', {{uuid "uid"}}); | ||
insert into notification_channels (id, type, name, value) | ||
values | ||
({{uuid "ug"}}, 'SLACK_USER_GROUP', '@testug (#test1)', {{slackUserGroupID "test2"}}); | ||
insert into schedule_data (schedule_id, data) | ||
values | ||
({{uuid "sid"}}, '{"V1":{"OnCallNotificationRules": [{"ChannelID": {{uuidJSON "ug"}}, "Time": "00:00" }]}}'); | ||
` | ||
h := harness.NewHarnessWithFlags(t, sql, "slack-ug", expflag.FlagSet{expflag.SlackUserGroups}) | ||
|
||
defer h.Close() | ||
|
||
h.Trigger() | ||
|
||
// Passing in no arguments to assert empty | ||
h.Slack().UserGroup("test2").ExpectUsers() | ||
|
||
h.FastForward(24 * time.Hour) | ||
|
||
h.Slack().UserGroup("test2").ExpectUsers("bob") | ||
} |