Skip to content

Commit

Permalink
User_test: add unit test for UpdateUser
Browse files Browse the repository at this point in the history
  • Loading branch information
TerraTalpi committed Aug 30, 2021
1 parent 03542fe commit f305692
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions GraphClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ func randomString(n int) string {
return string(b)
}

func createUnitTestUser(t *testing.T) User {
t.Helper()
rndstring := randomString(32)
user, err := graphClient.CreateUser(User{
AccountEnabled: true,
DisplayName: "go-msgraph unit-test generated user " + time.Now().Format("2006-01-02") + " - random " + rndstring,
MailNickname: "go-msgraph.unit-test.generated." + rndstring,
UserPrincipalName: "go-msgraph.unit-test.generated." + rndstring + "@" + msGraphDomainNameForCreateTests,
PasswordProfile: PasswordProfile{Password: randomString(32)},
})
if err != nil {
t.Errorf("Cannot create a new User for unit tests: %v", err)
}
return user
}

func TestNewGraphClient(t *testing.T) {
if msGraphAzureADAuthEndpoint != AzureADAuthEndpointGlobal || msGraphServiceRootEndpoint != ServiceRootEndpointGlobal {
t.Skip("Skipping TestNewGraphClient because the endpoint is not the default - global - endpoint")
Expand Down
20 changes: 20 additions & 0 deletions User_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,23 @@ func TestUser_String(t *testing.T) {
}
})
}

func TestUser_UpdateUser(t *testing.T) {
testuser := createUnitTestUser(t)

targetedCompanyName := "go-msgraph unit test suite UpdateUser" + randomString(25)
testuser.UpdateUser(User{CompanyName: targetedCompanyName})
getUser, err := graphClient.GetUser(testuser.ID, GetWithSelect("id,userPrincipalName,displayName,givenName,companyName"))
if err != nil {
testuser.DeleteUser()
t.Errorf("Cannot perform User.UpdateUser, error: %v", err)
}
if getUser.CompanyName != targetedCompanyName {
testuser.DeleteUser()
t.Errorf("Performed User.UpdateUser, but CompanyName is still \"%v\" instead of wanted \"%v\"", getUser.CompanyName, targetedCompanyName)
}
err = testuser.DeleteUser()
if err != nil {
t.Errorf("Could not User.DeleteUser() (for %v) after User.UpdateUser tests: %v", testuser, err)
}
}

0 comments on commit f305692

Please sign in to comment.