github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/web/context_test.go (about)

     1  package web
     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 = &Params{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 = &Params{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  }