Skip to content

Commit

Permalink
User: add unit test for PrettySimpleString
Browse files Browse the repository at this point in the history
  • Loading branch information
TerraTalpi committed Aug 30, 2021
1 parent 2a48c79 commit 657b0b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions User.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions User_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", 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())
}
}

0 comments on commit 657b0b0

Please sign in to comment.