From 07aee6b381b83137f7fb4d01c894d06d8f878fd9 Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:04:43 +0000 Subject: [PATCH 1/7] docs: add user.DeleteUser() to documentation --- docs/example_User.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/example_User.md b/docs/example_User.md index 86a33d5..8a90457 100644 --- a/docs/example_User.md +++ b/docs/example_User.md @@ -45,4 +45,6 @@ err := user.UpdateUser(msgraph.User{DisplayName: "Rabbit 2.0"}, msgraph.UpdateWi // disable acccount err := user.DisableAccount() +// delete a user, use with caution! +err := user.DeleteUser() ```` \ No newline at end of file From 80c7018e50a540e5c979f09fed263eccc81a1351 Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:21:45 +0000 Subject: [PATCH 2/7] docs: add enabling an user account --- docs/example_User.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/example_User.md b/docs/example_User.md index 8a90457..a2f42e2 100644 --- a/docs/example_User.md +++ b/docs/example_User.md @@ -45,6 +45,8 @@ err := user.UpdateUser(msgraph.User{DisplayName: "Rabbit 2.0"}, msgraph.UpdateWi // disable acccount err := user.DisableAccount() +// enable user account again +err := user.UpdateUser(User{AccountEnabled: true}) // delete a user, use with caution! err := user.DeleteUser() ```` \ No newline at end of file From 405ecf0f306ec7fe99a92696a744726ede0970f0 Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:22:27 +0000 Subject: [PATCH 3/7] User: add 2x unit test for notGraphCilentSourced --- User_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/User_test.go b/User_test.go index 73c2f19..0ae1884 100644 --- a/User_test.go +++ b/User_test.go @@ -53,6 +53,13 @@ func TestUser_ListCalendars(t *testing.T) { if skipCalendarTests { t.Skip("Skipping due to missing 'MSGraphExistingCalendarsOfUser' value") } + // testing for ErrNotGraphClientSourced + notGraphClientSourcedUser := User{ID: "none"} + _, err := notGraphClientSourcedUser.ListCalendars() + if err != ErrNotGraphClientSourced { + t.Errorf("Expected error \"ErrNotGraphClientSourced\", but got: %v", err) + } + // continue with normal tests userToTest := GetTestUser(t) var wantedCalendars []Calendar @@ -160,6 +167,14 @@ func TestUser_String(t *testing.T) { } func TestUser_UpdateUser(t *testing.T) { + // testing for ErrNotGraphClientSourced + notGraphClientSourcedUser := User{ID: "none"} + err := notGraphClientSourcedUser.UpdateUser(User{}) + if err != ErrNotGraphClientSourced { + t.Errorf("Expected error \"ErrNotGraphClientSourced\", but got: %v", err) + } + + // continue with normal tests testuser := createUnitTestUser(t) targetedCompanyName := "go-msgraph unit test suite UpdateUser" + randomString(25) From d6600ba75eb42f51469e225f2e0e40d88118582d Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:23:06 +0000 Subject: [PATCH 4/7] User: add unit test for GetFullName --- User_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/User_test.go b/User_test.go index 0ae1884..1dd5400 100644 --- a/User_test.go +++ b/User_test.go @@ -193,3 +193,11 @@ func TestUser_UpdateUser(t *testing.T) { t.Errorf("Could not User.DeleteUser() (for %v) after User.UpdateUser tests: %v", testuser, err) } } + +func TestUser_GetFullName(t *testing.T) { + testuser := User{GivenName: "Bob", Surname: "Rabbit"} + wanted := fmt.Sprintf("%v %v", testuser.GivenName, testuser.Surname) + if testuser.GetFullName() != wanted { + t.Errorf("user.GetFullName() should return \"%v\", but returns: \"%v\"", wanted, testuser.GetShortName()) + } +} From 19da1715dd0d22c6171c85bc769b6836d11b8adb Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:23:35 +0000 Subject: [PATCH 5/7] User: add unit test for GetShortName - do not convert to upper case --- User.go | 2 +- User_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/User.go b/User.go index e7d3603..b3ef5a2 100644 --- a/User.go +++ b/User.go @@ -137,7 +137,7 @@ func (u User) GetShortName() string { if len(supn) != 2 { return u.UserPrincipalName } - return strings.ToUpper(supn[0]) + return supn[0] } // GetFullName returns the full name in that format: diff --git a/User_test.go b/User_test.go index 1dd5400..e82d6a8 100644 --- a/User_test.go +++ b/User_test.go @@ -194,6 +194,19 @@ func TestUser_UpdateUser(t *testing.T) { } } +func TestUser_GetShortName(t *testing.T) { + // test a normal case + testuser := User{UserPrincipalName: "dumpty@contoso.com"} + if testuser.GetShortName() != "dumpty" { + t.Errorf("user.GetShortName() should return \"dumpty\", but returns: %v", testuser.GetShortName()) + } + // test a case that actually should never happen... but we all know murphy + testuser = User{UserPrincipalName: "alice"} + if testuser.GetShortName() != "alice" { + t.Errorf("user.GetShortName() should return \"alice\", but returns: %v", testuser.GetShortName()) + } +} + func TestUser_GetFullName(t *testing.T) { testuser := User{GivenName: "Bob", Surname: "Rabbit"} wanted := fmt.Sprintf("%v %v", testuser.GivenName, testuser.Surname) From 2a48c79eb83756d83f80eaf68775fa7615a41846 Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:29:29 +0000 Subject: [PATCH 6/7] User: fix unit test GetFullName error msg --- User_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/User_test.go b/User_test.go index e82d6a8..d666075 100644 --- a/User_test.go +++ b/User_test.go @@ -211,6 +211,6 @@ func TestUser_GetFullName(t *testing.T) { testuser := User{GivenName: "Bob", Surname: "Rabbit"} wanted := fmt.Sprintf("%v %v", testuser.GivenName, testuser.Surname) if testuser.GetFullName() != wanted { - t.Errorf("user.GetFullName() should return \"%v\", but returns: \"%v\"", wanted, testuser.GetShortName()) + t.Errorf("user.GetFullName() should return \"%v\", but returns: \"%v\"", wanted, testuser.GetFullName()) } } From 657b0b0512bc6378d5debc0683e3445762f57a11 Mon Sep 17 00:00:00 2001 From: Felix Hartung <7132415+TerraTalpi@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:30:07 +0000 Subject: [PATCH 7/7] User: add unit test for PrettySimpleString --- User.go | 10 +++++----- User_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/User.go b/User.go index b3ef5a2..a23b92c 100644 --- a/User.go +++ b/User.go @@ -145,6 +145,11 @@ func (u User) GetFullName() string { return fmt.Sprintf("%v %v", u.GivenName, u.Surname) } +// PrettySimpleString returns the User-instance simply formatted for logging purposes: {FullName (email) (activePhone)} +func (u User) PrettySimpleString() string { + return fmt.Sprintf("{ %v (%v) (%v) }", u.GetFullName(), u.Mail, u.GetActivePhone()) +} + // UpdateUser patches this user object. Note, only set the fields that should be changed. // // IMPORTANT: the user cannot be disabled (field AccountEnabled) this way, because the @@ -208,11 +213,6 @@ func (u User) DeleteUser(opts ...DeleteQueryOption) error { return err } -// PrettySimpleString returns the User-instance simply formatted for logging purposes: {FullName (email) (activePhone)} -func (u User) PrettySimpleString() string { - return fmt.Sprintf("{ %v (%v) (%v) }", u.GetFullName(), u.Mail, u.GetActivePhone()) -} - // Equal returns wether the user equals the other User by comparing every property // of the user including the ID func (u User) Equal(other User) bool { diff --git a/User_test.go b/User_test.go index d666075..e13b1fb 100644 --- a/User_test.go +++ b/User_test.go @@ -214,3 +214,11 @@ func TestUser_GetFullName(t *testing.T) { t.Errorf("user.GetFullName() should return \"%v\", but returns: \"%v\"", wanted, testuser.GetFullName()) } } + +func TestUser_PrettySimpleString(t *testing.T) { + testuser := User{GivenName: "Bob", Surname: "Rabbit", Mail: "bob.rabbit@contoso.com", MobilePhone: "+1 23456789"} + wanted := fmt.Sprintf("{ %v (%v) (%v) }", testuser.GetFullName(), testuser.Mail, testuser.GetActivePhone()) + if testuser.PrettySimpleString() != wanted { + t.Errorf("user.GetFullName() should return \"%v\", but returns: \"%v\"", wanted, testuser.PrettySimpleString()) + } +}