Skip to content

Commit

Permalink
add InviteUser with forceSendInvite bool and test (#464)
Browse files Browse the repository at this point in the history
* add InviteUser with forceSendInvite bool and test

* UserInvite mutation takes forceSendInvite input arg

* inviteUser accepts bool arg, not bool pointer

* Update .changes/unreleased/Refactor-20240905-144928.yaml

---------

Co-authored-by: Kyle <[email protected]>
  • Loading branch information
davidbloss and rocktavious authored Sep 30, 2024
1 parent b34ea51 commit a05d27a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240905-144928.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: 'BREAKING CHANGE: new argument sendInvite added to UserInvite() method to force send a user invite e-mail'
time: 2024-09-05T14:49:28.926087-05:00
4 changes: 2 additions & 2 deletions enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion input.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,17 @@ func (user *User) Teams(client *Client, variables *PayloadVariables) (*TeamIdCon
return &q.Account.User.Teams, nil
}

func (client *Client) InviteUser(email string, input UserInput) (*User, error) {
func (client *Client) InviteUser(email string, input UserInput, sendInvite bool) (*User, error) {
var m struct {
Payload struct {
User User
Errors []OpsLevelErrors
} `graphql:"userInvite(email: $email input: $input)"`
} `graphql:"userInvite(email: $email input: $input, forceSendInvite: $forceSendInvite)"`
}
v := PayloadVariables{
"email": email,
"input": input,
"email": email,
"input": input,
"forceSendInvite": RefOf(sendInvite),
}
err := client.Mutate(&m, v, WithName("UserInvite"))
return &m.Payload.User, HandleErrors(err, m.Payload.Errors)
Expand Down
34 changes: 29 additions & 5 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,48 @@ import (
func TestInviteUser(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation UserInvite($email:String!$input:UserInput!){userInvite(email: $email input: $input){user{id,email,htmlUrl,name,role},errors{message,path}}}`,
`{"email": "[email protected]", "input": { "name": "Kyle Rockman", "skipWelcomeEmail": false }}`,
`mutation UserInvite($email:String!$forceSendInvite:Boolean$input:UserInput!){userInvite(email: $email input: $input, forceSendInvite: $forceSendInvite){user{id,email,htmlUrl,name,role},errors{message,path}}}`,
`{"email": "[email protected]", "input": { "name": "Kyle Rockman", "skipWelcomeEmail": false }, "forceSendInvite": true}`,
`{"data": { "userInvite": { "user": {{ template "user_1" }}, "errors": [] }}}`,
)

client := BestTestClient(t, "user/invite", testRequest)
// Act
result, err := client.InviteUser("[email protected]", ol.UserInput{
userInput := ol.UserInput{
Name: ol.RefOf("Kyle Rockman"),
SkipWelcomeEmail: ol.RefOf(false),
})
}
// Act
result, err := client.InviteUser("[email protected]", userInput, true)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Kyle Rockman", result.Name)
autopilot.Equals(t, ol.UserRoleUser, result.Role)
}

func TestInviteUserSkipSendInvite(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation UserInvite($email:String!$forceSendInvite:Boolean$input:UserInput!){userInvite(email: $email input: $input, forceSendInvite: $forceSendInvite){user{id,email,htmlUrl,name,role},errors{message,path}}}`,
`{"email": "[email protected]", "input": { "name": "Kyle Rockman", "role": "team_member", "skipWelcomeEmail": false }, "forceSendInvite": false}`,
`{"data": { "userInvite": { "user": { {{ template "user_id_email_1" }}, "name": "Kyle Rockman", "role": "team_member" }, "errors": [] }}}`,
)

client := BestTestClient(t, "user/invite_skip_send_invite", testRequest)
userInput := ol.UserInput{
Name: ol.RefOf("Kyle Rockman"),
Role: ol.RefOf(ol.UserRoleTeamMember),
SkipWelcomeEmail: ol.RefOf(false),
}
// Act
result, err := client.InviteUser("[email protected]", userInput, false)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Kyle Rockman", result.Name)
autopilot.Equals(t, ol.UserRoleTeamMember, result.Role)
}

func TestGetUser(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
Expand Down

0 comments on commit a05d27a

Please sign in to comment.