diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-02-04 11:38:27 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2016-02-04 11:38:27 -0500 |
commit | 4f1dbb8ca9a6cce09c9a20e91e074feaadd755a8 (patch) | |
tree | d5811b516ef8b826e6ccd80efdf72c6fe52157a2 /model/command_test.go | |
parent | 852acf1bb2818316e40012a385a5e8bec287eb05 (diff) | |
parent | dffc5323ecd9c7bc1af0ea06ef4827078f9bcd52 (diff) | |
download | chat-4f1dbb8ca9a6cce09c9a20e91e074feaadd755a8.tar.gz chat-4f1dbb8ca9a6cce09c9a20e91e074feaadd755a8.tar.bz2 chat-4f1dbb8ca9a6cce09c9a20e91e074feaadd755a8.zip |
Merge pull request #2052 from mattermost/PLT-1429
PLT-1429 adding user created slash commands
Diffstat (limited to 'model/command_test.go')
-rw-r--r-- | model/command_test.go | 90 |
1 files changed, 81 insertions, 9 deletions
diff --git a/model/command_test.go b/model/command_test.go index 61302ea10..0581625d9 100644 --- a/model/command_test.go +++ b/model/command_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package model @@ -9,17 +9,89 @@ import ( ) func TestCommandJson(t *testing.T) { + o := Command{Id: NewId()} + json := o.ToJson() + ro := CommandFromJson(strings.NewReader(json)) - command := &Command{Command: NewId(), Suggest: true} - command.AddSuggestion(&SuggestCommand{Suggestion: NewId()}) - json := command.ToJson() - result := CommandFromJson(strings.NewReader(json)) - - if command.Command != result.Command { + if o.Id != ro.Id { t.Fatal("Ids do not match") } +} - if command.Suggestions[0].Suggestion != result.Suggestions[0].Suggestion { - t.Fatal("Ids do not match") +func TestCommandIsValid(t *testing.T) { + o := Command{} + + 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.CreatorId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreatorId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Token = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") } + + o.Token = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.URL = "nowhere.com/" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.URL = "http://nowhere.com/" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Method = COMMAND_METHOD_GET + if err := o.IsValid(); err != nil { + t.Fatal(err) + } +} + +func TestCommandPreSave(t *testing.T) { + o := Command{} + o.PreSave() +} + +func TestCommandPreUpdate(t *testing.T) { + o := Command{} + o.PreUpdate() } |