summaryrefslogtreecommitdiffstats
path: root/web/context_test.go
blob: 3fa6ebf22d88a55fdd3bcd20f4647cf4ae5ab55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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")
		}
	})
}