From 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 14 Jun 2015 23:53:32 -0800 Subject: first commit --- model/post_test.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 model/post_test.go (limited to 'model/post_test.go') 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() +} -- cgit v1.2.3-1-g7c22