From 47250c6629416b628a19e5571ac89f7b4646418c Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 14 May 2018 10:24:58 -0400 Subject: Refactor context out of API packages (#8755) * Refactor context out of API packages * Update function names per feedback * Move webhook handlers to web and fix web tests * Move more webhook tests out of api package * Fix static handler --- web/context_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 web/context_test.go (limited to 'web/context_test.go') diff --git a/web/context_test.go b/web/context_test.go new file mode 100644 index 000000000..3fa6ebf22 --- /dev/null +++ b/web/context_test.go @@ -0,0 +1,31 @@ +package web + +import ( + "net/http" + "testing" +) + +func TestRequireHookId(t *testing.T) { + c := &Context{} + t.Run("WhenHookIdIsValid", func(t *testing.T) { + c.Params = &Params{HookId: "abcdefghijklmnopqrstuvwxyz"} + c.RequireHookId() + + if c.Err != nil { + t.Fatal("Hook Id is Valid. Should not have set error in context") + } + }) + + t.Run("WhenHookIdIsInvalid", func(t *testing.T) { + c.Params = &Params{HookId: "abc"} + c.RequireHookId() + + if c.Err == nil { + t.Fatal("Should have set Error in context") + } + + if c.Err.StatusCode != http.StatusBadRequest { + t.Fatal("Should have set status as 400") + } + }) +} -- cgit v1.2.3-1-g7c22