github.com/cjdelisle/matterfoss@v5.11.1+incompatible/model/command_webhook_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "testing" 8 ) 9 10 func TestCommandWebhookPreSave(t *testing.T) { 11 h := CommandWebhook{} 12 h.PreSave() 13 if len(h.Id) != 26 { 14 t.Fatal("Id should be generated") 15 } 16 if h.CreateAt == 0 { 17 t.Fatal("CreateAt should be set") 18 } 19 } 20 21 func TestCommandWebhookIsValid(t *testing.T) { 22 h := CommandWebhook{} 23 h.Id = NewId() 24 h.CreateAt = GetMillis() 25 h.CommandId = NewId() 26 h.UserId = NewId() 27 h.ChannelId = NewId() 28 29 for _, test := range []struct { 30 Transform func() 31 ExpectedError string 32 }{ 33 {func() {}, ""}, 34 {func() { h.Id = "asd" }, "model.command_hook.id.app_error"}, 35 {func() { h.CreateAt = 0 }, "model.command_hook.create_at.app_error"}, 36 {func() { h.CommandId = "asd" }, "model.command_hook.command_id.app_error"}, 37 {func() { h.UserId = "asd" }, "model.command_hook.user_id.app_error"}, 38 {func() { h.ChannelId = "asd" }, "model.command_hook.channel_id.app_error"}, 39 {func() { h.RootId = "asd" }, "model.command_hook.root_id.app_error"}, 40 {func() { h.RootId = NewId() }, ""}, 41 {func() { h.ParentId = "asd" }, "model.command_hook.parent_id.app_error"}, 42 {func() { h.ParentId = NewId() }, ""}, 43 } { 44 tmp := h 45 test.Transform() 46 err := h.IsValid() 47 if test.ExpectedError == "" && err != nil { 48 t.Fatal("hook should be valid") 49 } else if test.ExpectedError != "" && test.ExpectedError != err.Id { 50 t.Fatal("expected " + test.ExpectedError + " error") 51 } 52 h = tmp 53 } 54 }