blob: df9ac19c225d4ad438dc3ec1c587e3005d70e179 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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)
}
}
|