-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
212 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,6 +591,22 @@ userReqInvite.Tenants = []*descope.AssociatedTenant{ | |
options := &descope.InviteOptions{InviteURL: "https://sub.domain.com"} | ||
err := descopeClient.Management.User().Invite("[email protected]", userReqInvite, options) | ||
|
||
// batch invite | ||
options := &descope.InviteOptions{InviteURL: "https://sub.domain.com"} | ||
batchUsers := []*descope.BatchUser{} | ||
u1 := &descope.BatchUser{} | ||
u1.LoginID = "one" | ||
u1.Email = "[email protected]" | ||
u1.Roles = []string{"one"} | ||
|
||
u2 := &descope.BatchUser{} | ||
u2.LoginID = "two" | ||
u2.Email = "[email protected]" | ||
u2.Roles = []string{"two"} | ||
|
||
batchUsers = append(batchUsers, u1, u2) | ||
err := descopeClient.Management.User().InviteBatch(batchUsers, options) | ||
|
||
// Update will override all fields as is. Use carefully. | ||
userReqUpdate := &descope.UserRequest{} | ||
userReqUpdate.Email = "[email protected]" | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ func TestUserCreateSuccess(t *testing.T) { | |
"email": "[email protected]", | ||
}} | ||
ca := map[string]any{"ak": "av"} | ||
i := 0 | ||
m := newTestMgmt(nil, helpers.DoOkWithBody(func(r *http.Request) { | ||
require.Equal(t, r.Header.Get("Authorization"), "Bearer a:key") | ||
req := map[string]any{} | ||
|
@@ -27,6 +28,15 @@ func TestUserCreateSuccess(t *testing.T) { | |
require.Equal(t, "foo", roleNames[0]) | ||
require.Nil(t, req["test"]) | ||
assert.EqualValues(t, ca, req["customAttributes"]) | ||
|
||
if i == 2 { | ||
assert.True(t, true, req["sendSMS"]) | ||
assert.EqualValues(t, false, req["sendMail"]) | ||
} else { | ||
assert.Nil(t, req["sendSMS"]) | ||
assert.Nil(t, req["sendMail"]) | ||
} | ||
i++ | ||
}, response)) | ||
user := &descope.UserRequest{} | ||
user.Email = "[email protected]" | ||
|
@@ -42,7 +52,9 @@ func TestUserCreateSuccess(t *testing.T) { | |
require.NotNil(t, res) | ||
require.Equal(t, "[email protected]", res.Email) | ||
|
||
res, err = m.User().Invite("abc", user, &descope.InviteOptions{InviteURL: "https://some.domain.com"}) | ||
sendSMS := true | ||
sendMail := false | ||
res, err = m.User().Invite("abc", user, &descope.InviteOptions{InviteURL: "https://some.domain.com", SendSMS: &sendSMS, SendMail: &sendMail}) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
require.Equal(t, "[email protected]", res.Email) | ||
|
@@ -66,6 +78,8 @@ func TestUserCreateSuccessWithOptions(t *testing.T) { | |
require.Nil(t, req["test"]) | ||
assert.EqualValues(t, ca, req["customAttributes"]) | ||
assert.EqualValues(t, "https://some.domain.com", req["inviteUrl"]) | ||
assert.Nil(t, req["sendMail"]) | ||
assert.Nil(t, req["sendSMS"]) | ||
}, response)) | ||
user := &descope.UserRequest{} | ||
user.Email = "[email protected]" | ||
|
@@ -78,6 +92,81 @@ func TestUserCreateSuccessWithOptions(t *testing.T) { | |
require.Equal(t, "[email protected]", res.Email) | ||
} | ||
|
||
func TestUsersInviteBatchSuccess(t *testing.T) { | ||
response := map[string]any{ | ||
"createdUsers": []map[string]any{ | ||
{"email": "[email protected]"}, | ||
}, | ||
"failedUsers": []map[string]any{ | ||
{ | ||
"user": map[string]any{ | ||
"email": "[email protected]", | ||
}, | ||
"failure": "some failure", | ||
}, | ||
}, | ||
} | ||
ca := map[string]any{"ak": "av"} | ||
|
||
users := []*descope.BatchUser{} | ||
|
||
u1 := &descope.BatchUser{} | ||
u1.LoginID = "one" | ||
u1.Email = "[email protected]" | ||
u1.Roles = []string{"one"} | ||
u1.CustomAttributes = ca | ||
|
||
u2 := &descope.BatchUser{} | ||
u2.LoginID = "two" | ||
u2.Email = "[email protected]" | ||
u2.Roles = []string{"two"} | ||
|
||
users = append(users, u1, u2) | ||
|
||
sendSMS := true | ||
|
||
called := false | ||
m := newTestMgmt(nil, helpers.DoOkWithBody(func(r *http.Request) { | ||
called = true | ||
require.Equal(t, r.Header.Get("Authorization"), "Bearer a:key") | ||
req := map[string]any{} | ||
require.NoError(t, helpers.ReadBody(r, &req)) | ||
assert.EqualValues(t, true, req["invite"]) | ||
assert.EqualValues(t, "https://some.domain.com", req["inviteUrl"]) | ||
assert.Nil(t, req["sendMail"]) | ||
assert.EqualValues(t, true, req["sendSMS"]) | ||
usersRes := req["users"].([]any) | ||
userRes1 := usersRes[0].(map[string]any) | ||
userRes2 := usersRes[1].(map[string]any) | ||
require.Equal(t, u1.LoginID, userRes1["loginId"]) | ||
require.Equal(t, u1.Email, userRes1["email"]) | ||
assert.EqualValues(t, ca, userRes1["customAttributes"]) | ||
roleNames := userRes1["roleNames"].([]any) | ||
require.Len(t, roleNames, 1) | ||
require.Equal(t, u1.Roles[0], roleNames[0]) | ||
|
||
require.Equal(t, u2.LoginID, userRes2["loginId"]) | ||
require.Equal(t, u2.Email, userRes2["email"]) | ||
assert.Nil(t, userRes2["customAttributes"]) | ||
roleNames = userRes2["roleNames"].([]any) | ||
require.Len(t, roleNames, 1) | ||
require.Equal(t, u2.Roles[0], roleNames[0]) | ||
}, response)) | ||
|
||
res, err := m.User().InviteBatch(users, &descope.InviteOptions{ | ||
InviteURL: "https://some.domain.com", | ||
SendSMS: &sendSMS, | ||
}) | ||
require.True(t, called) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
require.Len(t, res.CreatedUsers, 1) | ||
require.Len(t, res.FailedUsers, 1) | ||
assert.EqualValues(t, u1.Email, res.CreatedUsers[0].Email) | ||
assert.EqualValues(t, u2.Email, res.FailedUsers[0].User.Email) | ||
assert.EqualValues(t, "some failure", res.FailedUsers[0].Failure) | ||
} | ||
|
||
func TestUserCreateTestUserSuccess(t *testing.T) { | ||
response := map[string]any{ | ||
"user": map[string]any{ | ||
|
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