diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-30 18:20:28 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-30 18:20:28 -0600 |
| commit | d3cb17f8032d95f0f8805a0ce74fe5fc41714bb8 (patch) | |
| tree | b3a3dc15aeb344cd727e95cef28d80802f819887 /app/controllers/dashboard/controller_test.go | |
| parent | a372feb94ba1dfe119f2b350b77302a243ab17f2 (diff) | |
fix: strict same site mode breaks redirects
Diffstat (limited to 'app/controllers/dashboard/controller_test.go')
| -rw-r--r-- | app/controllers/dashboard/controller_test.go | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go index f6b2f43..30a9acc 100644 --- a/app/controllers/dashboard/controller_test.go +++ b/app/controllers/dashboard/controller_test.go @@ -18,26 +18,54 @@ func TestController(t *testing.T) { t.Run("GET /dashboard", func(t *testing.T) { t.Run("when unauthenticated", func(t *testing.T) { - t.Run("redirects to the home page", func(t *testing.T) { - r, w := test.RequestResponse("GET", "/dashboard") + r, w := test.RequestResponse("GET", "/dashboard") - mux.ServeHTTP(w, r) + mux.ServeHTTP(w, r) - require.Equal(t, http.StatusFound, w.Code) - assert.Equal(t, "/", w.Header().Get("Location")) + t.Run("redirects to the home page", func(t *testing.T) { + require.Equal(t, http.StatusNotFound, w.Code) }) }) t.Run("when authenticated", func(t *testing.T) { - t.Run("renders a dashboard page", func(t *testing.T) { - ctx := cfg.CurrentUser.With(t.Context(), &domain.User{}) - r, w := test.RequestResponse("GET", "/dashboard", test.WithContext(ctx)) + ctx := cfg.CurrentUser.With(t.Context(), &domain.User{}) + r, w := test.RequestResponse("GET", "/dashboard", test.WithContext(ctx)) + mux.ServeHTTP(w, r) - mux.ServeHTTP(w, r) + t.Run("renders a dashboard page", func(t *testing.T) { assert.Equal(t, http.StatusOK, w.Code) assert.Equal(t, "text/html", w.Header().Get("Content-Type")) assert.Contains(t, w.Body.String(), "<html") }) }) }) + + t.Run("GET /dashboard/nav", func(t *testing.T) { + t.Run("when unauthenticated", func(t *testing.T) { + r, w := test.RequestResponse("GET", "/dashboard/nav") + + mux.ServeHTTP(w, r) + + t.Run("renders the site header", func(t *testing.T) { + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "text/html", w.Header().Get("Content-Type")) + assert.Contains(t, w.Body.String(), "Login") + }) + }) + + t.Run("when authenticated", func(t *testing.T) { + ctx := cfg.CurrentUser.With(t.Context(), &domain.User{ + Username: "root", + }) + r, w := test.RequestResponse("GET", "/dashboard/nav", test.WithContext(ctx)) + mux.ServeHTTP(w, r) + + t.Run("renders the site header", func(t *testing.T) { + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "text/html", w.Header().Get("Content-Type")) + assert.Contains(t, w.Body.String(), "root") + }) + }) + }) + } |
