Skip to content

Commit

Permalink
Add tests for user addition or invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
WilfredDube committed Dec 31, 2024
1 parent cc9bc41 commit 3caa2d5
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7270,3 +7270,78 @@ func Test_UpdateOrganization(t *testing.T) {
require.NoError(t, err, "UpdateOrganization failed")
t.Log(organization)
}

func Test_InviteUserToOrganizationByID(t *testing.T) {
t.Parallel()
cfg := GetConfig(t)
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)

td, userID := CreateUser(t, client)
defer td()

tearDown, orgID := CreateOrganization(t, client, "Test Inc", "test-inc", "test.com")
defer tearDown()

err := client.InviteUserToOrganizationByID(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
orgID,
userID)
require.NoError(t, err, "InviteUserToOrganizationByID failed")
}

func Test_InviteUserToOrganizationByEmail(t *testing.T) {
t.Parallel()
cfg := GetConfig(t)
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)

td, userID := CreateUser(t, client)
defer td()

tearDown, orgID := CreateOrganization(t, client, "Test Inc", "test-inc", "test.com")
defer tearDown()

ctx := context.Background()
user, err := client.GetUserByID(
ctx,
token.AccessToken,
cfg.GoCloak.Realm,
userID)
require.NoError(t, err, "GetUserByID failed")

err = client.InviteUserToOrganizationByEmail(
ctx,
token.AccessToken,
cfg.GoCloak.Realm,
orgID,
gocloak.InviteeFormParams{
Email: user.Email,
FirstName: GetRandomNameP("FirstName"),
LastName: GetRandomNameP("LastName"),
})
require.NoError(t, err, "InviteUserToOrganizationByEmail failed")
}

func Test_AddUserToOrganization(t *testing.T) {
t.Parallel()
cfg := GetConfig(t)
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)

td, userID := CreateUser(t, client)
defer td()

tearDown, orgID := CreateOrganization(t, client, "Test Inc", "test-inc", "test.com")
defer tearDown()

err := client.AddUserToOrganization(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
orgID,
userID)
require.NoError(t, err, "AddUserToOrganization failed")
}

0 comments on commit 3caa2d5

Please sign in to comment.