diff options
author | Raphaƫl Bournhonesque <raphael0202@users.noreply.github.com> | 2016-11-14 13:36:59 +0100 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2016-11-14 09:36:59 -0300 |
commit | 602f85d2efe6b9127c0cd79618757c3ff2b0ef5b (patch) | |
tree | 99376615f5054f65be461130415858d838fbca2a /api/user_test.go | |
parent | ef080a0a10e58e46a1f65e3dd352234e7ccd5aa9 (diff) | |
download | chat-602f85d2efe6b9127c0cd79618757c3ff2b0ef5b.tar.gz chat-602f85d2efe6b9127c0cd79618757c3ff2b0ef5b.tar.bz2 chat-602f85d2efe6b9127c0cd79618757c3ff2b0ef5b.zip |
Increase unit test coverage of api/user.go (#4541)
* Add test to CheckUserDomain
* Add unit test to IsUsernameTaken
Diffstat (limited to 'api/user_test.go')
-rw-r--r-- | api/user_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
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() |