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 | 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 (patch) | |
tree | 044da29848cf0f5c8607eac34de69065171669cf /model/post_test.go | |
download | chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.gz chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.bz2 chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.zip |
first commit
Diffstat (limited to 'model/post_test.go')
-rw-r--r-- | model/post_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/model/post_test.go b/model/post_test.go new file mode 100644 index 000000000..38f4b4c98 --- /dev/null +++ b/model/post_test.go @@ -0,0 +1,87 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestPostJson(t *testing.T) { + o := Post{Id: NewId(), Message: NewId()} + json := o.ToJson() + ro := PostFromJson(strings.NewReader(json)) + + if o.Id != ro.Id { + t.Fatal("Ids do not match") + } +} + +func TestPostIsValid(t *testing.T) { + o := Post{} + + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Id = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.UpdateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.UserId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ChannelId = NewId() + o.RootId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.RootId = "" + o.ParentId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ParentId = NewId() + o.RootId = "" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ParentId = "" + o.Message = strings.Repeat("0", 4001) + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Message = strings.Repeat("0", 4000) + if err := o.IsValid(); err != nil { + t.Fatal(err) + } + + o.Message = "test" + if err := o.IsValid(); err != nil { + t.Fatal(err) + } +} + +func TestPostPreSave(t *testing.T) { + o := Post{Message: "test"} + o.PreSave() + o.Etag() +} |