Skip to content

Commit

Permalink
add withValidationErrors test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Sarvarov committed Jul 18, 2024
1 parent 9925544 commit 46a6673
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func withReferer(r *http.Request, referer string) {
r.Header.Set("Referer", referer)
}

func withValidationErrors(r *http.Request, errors ValidationErrors) {
*r = *r.WithContext(WithValidationErrors(r.Context(), errors))
}

func assertResponseStatusCode(t *testing.T, w *httptest.ResponseRecorder, want int) {
t.Helper()

Expand Down
8 changes: 4 additions & 4 deletions response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestInertia_Location(t *testing.T) {
"baz": "quz",
}

r = r.WithContext(WithValidationErrors(r.Context(), errors))
withValidationErrors(r, errors)
i.Location(w, r, "/foo")

if !reflect.DeepEqual(flashProvider.errors, errors) {
Expand All @@ -522,7 +522,7 @@ func TestInertia_Location(t *testing.T) {
"baz": "quz",
}

r = r.WithContext(WithValidationErrors(r.Context(), errors))
withValidationErrors(r, errors)
i.Location(w, r, "/foo", http.StatusMovedPermanently)

if !reflect.DeepEqual(flashProvider.errors, errors) {
Expand Down Expand Up @@ -597,7 +597,7 @@ func TestInertia_Redirect(t *testing.T) {
"baz": "quz",
}

r = r.WithContext(WithValidationErrors(r.Context(), errors))
withValidationErrors(r, errors)
i.Redirect(w, r, "https://example.com/foo")

if !reflect.DeepEqual(flashProvider.errors, errors) {
Expand Down Expand Up @@ -675,7 +675,7 @@ func TestInertia_Back(t *testing.T) {
"baz": "quz",
}

r = r.WithContext(WithValidationErrors(r.Context(), errors))
withValidationErrors(r, errors)
i.Back(w, r)

if !reflect.DeepEqual(flashProvider.errors, errors) {
Expand Down

0 comments on commit 46a6673

Please sign in to comment.