github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/api4/context_test.go (about) 1 package api4 2 3 import ( 4 "net/http" 5 "testing" 6 ) 7 8 func TestRequireHookId(t *testing.T) { 9 c := &Context{} 10 t.Run("WhenHookIdIsValid", func(t *testing.T) { 11 c.Params = &ApiParams{HookId: "abcdefghijklmnopqrstuvwxyz"} 12 c.RequireHookId() 13 14 if c.Err != nil { 15 t.Fatal("Hook Id is Valid. Should not have set error in context") 16 } 17 }) 18 19 t.Run("WhenHookIdIsInvalid", func(t *testing.T) { 20 c.Params = &ApiParams{HookId: "abc"} 21 c.RequireHookId() 22 23 if c.Err == nil { 24 t.Fatal("Should have set Error in context") 25 } 26 27 if c.Err.StatusCode != http.StatusBadRequest { 28 t.Fatal("Should have set status as 400") 29 } 30 }) 31 }