diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | cf7a05f80f68b5b1c8bcc0089679dd497cec2506 (patch) | |
tree | 70007378570a6962d7c175ca96af732b71aeb6da /model/user_test.go | |
download | chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.gz chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.bz2 chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.zip |
first commit
Diffstat (limited to 'model/user_test.go')
-rw-r--r-- | model/user_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/model/user_test.go b/model/user_test.go new file mode 100644 index 000000000..df9ac19c2 --- /dev/null +++ b/model/user_test.go @@ -0,0 +1,92 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestPasswordHash(t *testing.T) { + hash := HashPassword("Test") + + if !ComparePassword(hash, "Test") { + t.Fatal("Passwords don't match") + } + + if ComparePassword(hash, "Test2") { + t.Fatal("Passwords should not have matched") + } +} + +func TestUserJson(t *testing.T) { + user := User{Id: NewId(), Username: NewId()} + json := user.ToJson() + ruser := UserFromJson(strings.NewReader(json)) + + if user.Id != ruser.Id { + t.Fatal("Ids do not match") + } +} + +func TestUserPreSave(t *testing.T) { + user := User{Password: "test"} + user.PreSave() + user.Etag() +} + +func TestUserPreUpdate(t *testing.T) { + user := User{Password: "test"} + user.PreUpdate() +} + +func TestUserIsValid(t *testing.T) { + user := User{} + + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.Id = NewId() + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.CreateAt = GetMillis() + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.UpdateAt = GetMillis() + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.TeamId = NewId() + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.Username = NewId() + "^hello#" + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.Username = NewId() + user.Email = strings.Repeat("01234567890", 20) + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.Email = "test@nowhere.com" + user.FullName = strings.Repeat("01234567890", 20) + if err := user.IsValid(); err == nil { + t.Fatal() + } + + user.FullName = "" + if err := user.IsValid(); err != nil { + t.Fatal(err) + } +} |