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] 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()) + } +}