summaryrefslogtreecommitdiffstats
path: root/web/context_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/context_test.go')
-rw-r--r--web/context_test.go31
1 files changed, 31 insertions, 0 deletions
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")
+ }
+ })
+}