-
Notifications
You must be signed in to change notification settings - Fork 0
Fix and refine feature test for updating a post via API #361
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
Fix and refine feature test for updating a post via API #361
Conversation
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.
Self Review
- Confirmed that
PostVisibility
enum requires anint
, notstring
, for casting - Test request now passes the proper
visibility
value viaPostVisibility::PRIVATE->value
or similar - Response assertions adjusted to match actual return format (
string
orint
, depending on API design) - Verified test passes and updates are reflected correctly
- Ensured that the test fails properly when invalid data is submitted (edge case ready)
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.
Pull Request Overview
This PR aligns the feature test for the post-update API endpoint with the actual behavior by standardizing visibility handling via PostVisibilityEnum
, adjusting variable naming, and correcting route/controller parameters.
- Standardize
visibility
request and response usingPostVisibilityEnum
- Rename test variables to camelCase and import the enum in creation tests
- Refine edit route signature and visibility mapping in the domain/entity layer
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/routes/api.php | Simplified the PUT route to /{postId} and updated route name |
src/app/Post/Tests/Post_EditTest.php | Renamed vars, switched visibility to enum ->value , updated URL |
src/app/Post/Tests/Post_CreateTest.php | Imported PostVisibilityEnum and switched visibility to ->value |
src/app/Post/Presentation/Controller/PostController.php | Updated edit signature to camelCase params |
src/app/Post/Infrastructure/Repository/PostRepository.php | Added user_id fill on edit |
src/app/Post/Domain/Entity/PostEntity.php | Fixed visibility mapping in build() |
src/app/Common/Domain/Enum/PostVisibility.php | Lowercased enum toLabel() outputs |
src/app/Post/Application/UseCase/EditUseCase.php | Formatting adjustment |
Comments suppressed due to low confidence (2)
src/routes/api.php:23
- The edit route no longer includes the {userId} segment, but tests and the controller still expect it. Either restore the '{userId}/posts/{postId}' path or update tests and controller to match the new '/api/users/{postId}' pattern.
Route::put('{postId}', [PostController::class, 'edit'])->name('edit');
src/app/Post/Infrastructure/Repository/PostRepository.php:42
- Including 'user_id' in the update payload will overwrite the post's original owner on edits. Remove this field from editById to preserve post ownership.
'user_id' => $entity->getUserId()->getValue(),
int $userId, | ||
int $postId, | ||
EditUseCase $useCase | ||
): JsonResponse { | ||
DB::connection('mysql')->beginTransaction(); | ||
try { |
Copilot
AI
Jul 8, 2025
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.
The controller's edit method expects both $userId and $postId parameters, but the route only supplies {postId}. Update the signature to accept just $postId or adjust the route to provide both parameters.
int $userId, | |
int $postId, | |
EditUseCase $useCase | |
): JsonResponse { | |
DB::connection('mysql')->beginTransaction(); | |
try { | |
int $postId, | |
EditUseCase $useCase | |
): JsonResponse { | |
DB::connection('mysql')->beginTransaction(); | |
try { | |
$userId = auth()->id(); // Retrieve the authenticated user's ID |
Copilot uses AI. Check for mistakes.
Description
This PR corrects and improves the feature test for the post update endpoint (
PUT /api/users/{userId}/posts/{postId}
).The previous implementation failed due to a mismatch between the expected response structure and the actual API behaviour, particularly concerning the
visibility
field.