diff options
Diffstat (limited to 'app/controllers/dashboard')
| -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") + }) + }) + }) + } |
