-
Notifications
You must be signed in to change notification settings - Fork 1
feat(errors): complete refactor Phase 1 with exception filter tests a… #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -238,4 +238,73 @@ string expectedTitle | |||||
| Assert.Equal(statusCode.ToString(), errorResponse.Errors[0].Status); | ||||||
| Assert.Equal(expectedTitle, errorResponse.Errors[0].Title); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public void OnException_WithFullMetadata_SerializesAllFields() | ||||||
| { | ||||||
| var exception = new JsonApiBadRequestException( | ||||||
| "Invalid filter value", | ||||||
| code: "INVALID_FILTER_VALUE", | ||||||
| errorSource: new ErrorSource { Parameter = "filter[age]" }, | ||||||
| meta: new Dictionary<string, object> | ||||||
| { | ||||||
| ["field"] = "age", | ||||||
| ["expectedType"] = "Int32", | ||||||
| ["actualValue"] = "abc", | ||||||
| } | ||||||
| ); | ||||||
| var context = CreateExceptionContext(exception); | ||||||
|
|
||||||
| _filter.OnException(context); | ||||||
|
|
||||||
| var result = Assert.IsType<ObjectResult>(context.Result); | ||||||
| var errorResponse = Assert.IsType<JsonApiErrorResponse>(result.Value); | ||||||
| var error = errorResponse.Errors[0]; | ||||||
|
|
||||||
| Assert.Equal("INVALID_FILTER_VALUE", error.Code); | ||||||
| Assert.NotNull(error.Source); | ||||||
| Assert.Equal("filter[age]", error.Source.Parameter); | ||||||
| Assert.NotNull(error.Meta); | ||||||
| Assert.Equal("age", error.Meta["field"]); | ||||||
| Assert.Equal("Int32", error.Meta["expectedType"]); | ||||||
| Assert.Equal("abc", error.Meta["actualValue"]); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public void OnException_WithFactoryException_SerializesCorrectly() | ||||||
| { | ||||||
| var exception = JsonApiErrors.NotFound("books", 123); | ||||||
| var context = CreateExceptionContext(exception); | ||||||
|
|
||||||
| _filter.OnException(context); | ||||||
|
|
||||||
| var result = Assert.IsType<ObjectResult>(context.Result); | ||||||
| Assert.Equal(404, result.StatusCode); | ||||||
|
|
||||||
| var errorResponse = Assert.IsType<JsonApiErrorResponse>(result.Value); | ||||||
| var error = errorResponse.Errors[0]; | ||||||
|
|
||||||
|
Comment on lines
+279
to
+286
|
||||||
| Assert.Equal("RESOURCE_NOT_FOUND", error.Code); | ||||||
|
||||||
| Assert.Equal("RESOURCE_NOT_FOUND", error.Code); | |
| Assert.Equal(JsonApiErrorCodes.ResourceNotFound, error.Code); |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should assert context.ExceptionHandled and Assert.Single(errorResponse.Errors) before accessing errorResponse.Errors[0], consistent with the earlier tests, so it also verifies the filter doesn’t emit multiple errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn’t assert
context.ExceptionHandledor that exactly one error was produced. AddingAssert.True(context.ExceptionHandled)andAssert.Single(errorResponse.Errors)(and optionally verifying the 400 status) would align with the other tests and ensure regressions in exception handling/multi-error behavior are caught.