MCPcopy Create free account
hub / github.com/driangle/taskmd / TestCorsMiddleware_OptionsRequest

Function TestCorsMiddleware_OptionsRequest

apps/cli/internal/web/server_test.go:47–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestCorsMiddleware_OptionsRequest(t *testing.T) {
48 var innerCalled bool
49 inner := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
50 innerCalled = true
51 })
52
53 handler := corsMiddleware(inner)
54
55 req := httptest.NewRequest(http.MethodOptions, "/api/tasks", nil)
56 rec := httptest.NewRecorder()
57
58 handler.ServeHTTP(rec, req)
59
60 if innerCalled {
61 t.Error("expected inner handler NOT to be called for OPTIONS request")
62 }
63
64 if rec.Code != http.StatusNoContent {
65 t.Errorf("expected 204 for OPTIONS, got %d", rec.Code)
66 }
67
68 origin := rec.Header().Get("Access-Control-Allow-Origin")
69 if origin != "http://localhost:5173" {
70 t.Errorf("expected CORS origin header on OPTIONS response, got %q", origin)
71 }
72}
73
74func TestNewServer_CreatesInstance(t *testing.T) {
75 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 3

corsMiddlewareFunction · 0.85
ServeHTTPMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected