From eb0111f6bbe2b0bf160a674dfe1b4d089f905cb9 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 2 Sep 2016 12:24:20 -0400 Subject: Fixing SanitizeProfile (#3930) --- api/user_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'api/user_test.go') diff --git a/api/user_test.go b/api/user_test.go index 1b6662269..5e8d6d54f 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -434,6 +434,13 @@ func TestGetDirectProfiles(t *testing.T) { th.BasicClient.Must(th.BasicClient.CreateDirectChannel(th.BasicUser2.Id)) + prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress + defer func() { + utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail + }() + + utils.Cfg.PrivacySettings.ShowEmailAddress = true + if result, err := th.BasicClient.GetDirectProfiles(""); err != nil { t.Fatal(err) } else { @@ -446,6 +453,34 @@ func TestGetDirectProfiles(t *testing.T) { if users[th.BasicUser2.Id] == nil { t.Fatal("missing expected user") } + + for _, user := range users { + if user.Email == "" { + t.Fatal("problem with show email") + } + } + } + + utils.Cfg.PrivacySettings.ShowEmailAddress = false + + if result, err := th.BasicClient.GetDirectProfiles(""); err != nil { + t.Fatal(err) + } else { + users := result.Data.(map[string]*model.User) + + if len(users) != 1 { + t.Fatal("map was wrong length") + } + + if users[th.BasicUser2.Id] == nil { + t.Fatal("missing expected user") + } + + for _, user := range users { + if user.Email != "" { + t.Fatal("problem with show email") + } + } } } @@ -454,6 +489,13 @@ func TestGetProfilesForDirectMessageList(t *testing.T) { th.BasicClient.Must(th.BasicClient.CreateDirectChannel(th.BasicUser2.Id)) + prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress + defer func() { + utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail + }() + + utils.Cfg.PrivacySettings.ShowEmailAddress = true + if result, err := th.BasicClient.GetProfilesForDirectMessageList(th.BasicTeam.Id); err != nil { t.Fatal(err) } else { @@ -462,6 +504,30 @@ func TestGetProfilesForDirectMessageList(t *testing.T) { if len(users) < 1 { t.Fatal("map was wrong length") } + + for _, user := range users { + if user.Email == "" { + t.Fatal("problem with show email") + } + } + } + + utils.Cfg.PrivacySettings.ShowEmailAddress = false + + if result, err := th.BasicClient.GetProfilesForDirectMessageList(th.BasicTeam.Id); err != nil { + t.Fatal(err) + } else { + users := result.Data.(map[string]*model.User) + + if len(users) < 1 { + t.Fatal("map was wrong length") + } + + for _, user := range users { + if user.Email != "" { + t.Fatal("problem with show email") + } + } } } -- cgit v1.2.3-1-g7c22