44 lines
985 B
Go
44 lines
985 B
Go
package httpapi
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
"net/http/httptest"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRouterSupportCSATAuthRequiresSession(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
s := testAPIServer()
|
||
|
|
h := s.Router()
|
||
|
|
|
||
|
|
cases := []struct {
|
||
|
|
method string
|
||
|
|
path string
|
||
|
|
}{
|
||
|
|
{http.MethodPost, "/api/support/tickets/00000000-0000-0000-0000-000000000001/csat"},
|
||
|
|
{http.MethodGet, "/api/admin/support/csat"},
|
||
|
|
}
|
||
|
|
mounted := 0
|
||
|
|
for _, tc := range cases {
|
||
|
|
rec := httptest.NewRecorder()
|
||
|
|
req := httptest.NewRequest(tc.method, tc.path, strings.NewReader(`{"score":5}`))
|
||
|
|
if tc.method == http.MethodPost {
|
||
|
|
req.Header.Set("Content-Type", "application/json")
|
||
|
|
}
|
||
|
|
h.ServeHTTP(rec, req)
|
||
|
|
switch rec.Code {
|
||
|
|
case http.StatusNotFound:
|
||
|
|
continue
|
||
|
|
case http.StatusUnauthorized, http.StatusForbidden:
|
||
|
|
mounted++
|
||
|
|
default:
|
||
|
|
t.Fatalf("%s %s status=%d want 401/403 (body=%s)",
|
||
|
|
tc.method, tc.path, rec.Code, rec.Body.String())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if mounted == 0 {
|
||
|
|
t.Skip("csat routes not mounted yet")
|
||
|
|
}
|
||
|
|
}
|