blob: 302b7b24bfcaffb17da3257ceeac1160af98484b (
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 api4
import (
"net/http"
"testing"
)
func TestRequireHookId(t *testing.T) {
c := &Context{}
t.Run("WhenHookIdIsValid", func(t *testing.T) {
c.Params = &ApiParams{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 = &ApiParams{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")
}
})
}
|