From 602f85d2efe6b9127c0cd79618757c3ff2b0ef5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Mon, 14 Nov 2016 13:36:59 +0100 Subject: Increase unit test coverage of api/user.go (#4541) * Add test to CheckUserDomain * Add unit test to IsUsernameTaken --- api/user_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'api/user_test.go') diff --git a/api/user_test.go b/api/user_test.go index 1ffb2140c..f91d71177 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -80,6 +80,51 @@ func TestCreateUser(t *testing.T) { } } +func TestCheckUserDomain(t *testing.T) { + th := Setup().InitBasic() + user := th.BasicUser + + cases := []struct { + domains string + matched bool + }{ + {"simulator.amazonses.com", true}, + {"gmail.com", false}, + {"", true}, + {"gmail.com simulator.amazonses.com", true}, + } + for _, c := range cases { + matched := CheckUserDomain(user, c.domains) + if matched != c.matched { + if c.matched { + t.Logf("'%v' should have matched '%v'", user.Email, c.domains) + } else { + t.Logf("'%v' should not have matched '%v'", user.Email, c.domains) + } + t.FailNow() + } + } +} + +func TestIsUsernameTaken(t *testing.T) { + th := Setup().InitBasic() + user := th.BasicUser + taken := IsUsernameTaken(user.Username) + + if !taken { + t.Logf("the username '%v' should be taken", user.Username) + t.FailNow() + } + + newUsername := "randomUsername" + taken = IsUsernameTaken(newUsername) + + if taken { + t.Logf("the username '%v' should not be taken", newUsername) + t.FailNow() + } +} + func TestLogin(t *testing.T) { th := Setup() Client := th.CreateClient() -- cgit v1.2.3-1-g7c22