From 8b60283eeb18cb5daf84af7de0a535e046fb7755 Mon Sep 17 00:00:00 2001 From: Leon Morival Date: Fri, 14 Aug 2026 12:46:29 +0200 Subject: [PATCH] feat: translation codes --- app/Actions/ReviewIdentityVerification.php | 2 +- app/Actions/SubmitIdentityVerification.php | 2 +- app/Http/Controllers/DeviceTokenController.php | 8 ++++---- app/Http/Controllers/FollowController.php | 10 +++++----- app/Http/Controllers/LegalDocumentController.php | 2 +- app/Http/Controllers/MealImageAnalysisController.php | 4 ++-- app/Http/Controllers/NotificationController.php | 2 +- .../Controllers/NotificationPreferenceController.php | 2 +- app/Http/Controllers/PostReviewsController.php | 2 +- app/Http/Controllers/ReportController.php | 6 +++--- app/Http/Controllers/StravaController.php | 12 ++++++------ app/Http/Controllers/UserBlockController.php | 4 ++-- app/Http/Middleware/EnsureAccountIsNotSuspended.php | 2 +- app/Http/Middleware/EnsureEmailIsVerified.php | 2 +- app/Http/Resources/LegalDocumentResource.php | 1 - app/Http/Resources/ReportResource.php | 2 -- app/Services/ContentModerationService.php | 8 ++++---- app/Services/ModerationReportService.php | 10 +++++----- tests/Feature/AccountDeletionTest.php | 2 +- tests/Feature/CertificationTest.php | 2 +- tests/Feature/ContentModerationTest.php | 2 +- tests/Feature/MealImageAnalysisTest.php | 4 ++-- tests/Feature/ModerationReportsTest.php | 10 +++++----- tests/Feature/PasswordResetTest.php | 8 ++++---- tests/Feature/PostReviewsControllerTest.php | 2 +- tests/Feature/StravaConnectionTest.php | 4 ++-- tests/Feature/UpdatePasswordTest.php | 2 +- tests/Feature/UserBlockingTest.php | 4 ++-- 28 files changed, 59 insertions(+), 62 deletions(-) diff --git a/app/Actions/ReviewIdentityVerification.php b/app/Actions/ReviewIdentityVerification.php index f0f8299..3e8928d 100644 --- a/app/Actions/ReviewIdentityVerification.php +++ b/app/Actions/ReviewIdentityVerification.php @@ -25,7 +25,7 @@ class ReviewIdentityVerification abort_if( $status === IdentityVerificationStatus::REJECTED && blank($rejectionReason), 422, - __('api.certification.rejection_reason_required'), + 'CERTIFICATION_REJECTION_REASON_REQUIRED', ); $reviewedRequest = DB::transaction(function () use ( diff --git a/app/Actions/SubmitIdentityVerification.php b/app/Actions/SubmitIdentityVerification.php index 4587cb0..5819ad9 100644 --- a/app/Actions/SubmitIdentityVerification.php +++ b/app/Actions/SubmitIdentityVerification.php @@ -25,7 +25,7 @@ class SubmitIdentityVerification $existingRequest = $user->identityVerificationRequest()->first(); if ($existingRequest?->status === IdentityVerificationStatus::PENDING) { - throw new ConflictHttpException(__('api.certification.already_pending')); + throw new ConflictHttpException('CERTIFICATION_ALREADY_PENDING'); } $disk = (string) config('billing.identity_verification.disk', 'identity_documents'); diff --git a/app/Http/Controllers/DeviceTokenController.php b/app/Http/Controllers/DeviceTokenController.php index 35b5194..da77c3b 100644 --- a/app/Http/Controllers/DeviceTokenController.php +++ b/app/Http/Controllers/DeviceTokenController.php @@ -24,9 +24,9 @@ class DeviceTokenController extends Controller ); return response()->json([ - 'message' => $deviceToken->wasRecentlyCreated - ? __('api.device_tokens.created') - : __('api.device_tokens.updated'), + 'code' => $deviceToken->wasRecentlyCreated + ? 'DEVICE_TOKEN_CREATED' + : 'DEVICE_TOKEN_UPDATED', 'deviceToken' => [ 'id' => $deviceToken->id, 'expoPushToken' => $deviceToken->expo_push_token, @@ -40,7 +40,7 @@ class DeviceTokenController extends Controller auth()->user()->notify(new TestNotification); return response()->json([ - 'message' => __('api.device_tokens.notification_sent'), + 'code' => 'TEST_NOTIFICATION_SENT', ]); } diff --git a/app/Http/Controllers/FollowController.php b/app/Http/Controllers/FollowController.php index 32bd944..453ddf3 100644 --- a/app/Http/Controllers/FollowController.php +++ b/app/Http/Controllers/FollowController.php @@ -19,7 +19,7 @@ class FollowController extends Controller if ($authUser->id === $user->id) { return response()->json([ - 'message' => __('api.follows.cannot_follow_self'), + 'code' => 'CANNOT_FOLLOW_SELF', ], 422); } @@ -38,7 +38,7 @@ class FollowController extends Controller } return response()->json([ - 'message' => __('api.follows.followed'), + 'code' => 'USER_FOLLOWED', 'status' => $status, ]); } @@ -48,7 +48,7 @@ class FollowController extends Controller $request->user()->following()->detach($user->id); return response()->json([ - 'message' => __('api.follows.unfollowed'), + 'code' => 'USER_UNFOLLOWED', ]); } @@ -61,7 +61,7 @@ class FollowController extends Controller ]); return response()->json([ - 'message' => $updated ? __('api.follows.accepted') : __('api.follows.not_found'), + 'code' => $updated ? 'FOLLOW_REQUEST_ACCEPTED' : 'FOLLOW_REQUEST_NOT_FOUND', ]); } @@ -72,7 +72,7 @@ class FollowController extends Controller $detached = $request->user()->followers()->detach($user->id); return response()->json([ - 'message' => $detached ? __('api.follows.rejected') : __('api.follows.not_found'), + 'code' => $detached ? 'FOLLOW_REQUEST_REJECTED' : 'FOLLOW_REQUEST_NOT_FOUND', ]); } diff --git a/app/Http/Controllers/LegalDocumentController.php b/app/Http/Controllers/LegalDocumentController.php index 9c9eca1..e2d296c 100644 --- a/app/Http/Controllers/LegalDocumentController.php +++ b/app/Http/Controllers/LegalDocumentController.php @@ -27,7 +27,7 @@ class LegalDocumentController extends Controller { $document = LegalDocument::publicForSlug($slug); - abort_if(! $document, 404, __('api.legal_documents.not_found')); + abort_if(! $document, 404, 'LEGAL_DOCUMENT_NOT_FOUND'); return new LegalDocumentResource($document); } diff --git a/app/Http/Controllers/MealImageAnalysisController.php b/app/Http/Controllers/MealImageAnalysisController.php index 365c7c0..7298e4b 100644 --- a/app/Http/Controllers/MealImageAnalysisController.php +++ b/app/Http/Controllers/MealImageAnalysisController.php @@ -27,7 +27,7 @@ class MealImageAnalysisController extends Controller if (! $user->canAnalyzeMeals()) { return response()->json([ - 'message' => __('api.meal_image_analysis.subscription_required'), + 'code' => 'MEAL_ANALYSIS_SUBSCRIPTION_REQUIRED', ], 402); } @@ -48,7 +48,7 @@ class MealImageAnalysisController extends Controller ); return response()->json([ - 'message' => __('api.meal_image_analysis.failed'), + 'code' => 'MEAL_ANALYSIS_FAILED', ], 502); } diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index c54a8e3..5beb606 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -56,7 +56,7 @@ class NotificationController extends Controller 'data' => [ 'updated' => $updated, ], - 'message' => __('api.notifications.all_read'), + 'code' => 'NOTIFICATIONS_MARKED_AS_READ', ]); } diff --git a/app/Http/Controllers/NotificationPreferenceController.php b/app/Http/Controllers/NotificationPreferenceController.php index 24604fc..103d94e 100644 --- a/app/Http/Controllers/NotificationPreferenceController.php +++ b/app/Http/Controllers/NotificationPreferenceController.php @@ -29,7 +29,7 @@ class NotificationPreferenceController extends Controller return response()->json([ 'data' => $this->preferences($request), - 'message' => __('api.notifications.preferences_updated'), + 'code' => 'NOTIFICATION_PREFERENCES_UPDATED', ]); } diff --git a/app/Http/Controllers/PostReviewsController.php b/app/Http/Controllers/PostReviewsController.php index d5a7045..51faa1a 100644 --- a/app/Http/Controllers/PostReviewsController.php +++ b/app/Http/Controllers/PostReviewsController.php @@ -46,7 +46,7 @@ class PostReviewsController extends Controller ->where('user_id', $userId) ->exists(), 409, - __('api.post_reviews.already_exists') + 'MEAL_REVIEW_ALREADY_EXISTS' ); $postReview = PostReviews::create([ diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 6720d70..7ecee73 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -26,7 +26,7 @@ class ReportController extends Controller ); return (new ReportResource($report)) - ->additional(['message' => __('api.reports.created')]) + ->additional(['code' => 'REPORT_CREATED']) ->response() ->setStatusCode(201); } @@ -44,7 +44,7 @@ class ReportController extends Controller ); return (new ReportResource($report)) - ->additional(['message' => __('api.reports.created')]) + ->additional(['code' => 'REPORT_CREATED']) ->response() ->setStatusCode(201); } @@ -62,7 +62,7 @@ class ReportController extends Controller ); return (new ReportResource($report)) - ->additional(['message' => __('api.reports.created')]) + ->additional(['code' => 'REPORT_CREATED']) ->response() ->setStatusCode(201); } diff --git a/app/Http/Controllers/StravaController.php b/app/Http/Controllers/StravaController.php index e9c63d4..704460c 100644 --- a/app/Http/Controllers/StravaController.php +++ b/app/Http/Controllers/StravaController.php @@ -51,13 +51,13 @@ class StravaController extends Controller if (! is_array($state) || $state['user_id'] !== $request->user()->getKey()) { return response()->json([ - 'message' => __('api.strava.state_expired'), + 'code' => 'STRAVA_STATE_EXPIRED', ], 422); } if (isset($data['error'])) { return response()->json([ - 'message' => __('api.strava.refused'), + 'code' => 'STRAVA_AUTHORIZATION_REFUSED', ], 422); } @@ -115,14 +115,14 @@ class StravaController extends Controller report($exception); return response()->json([ - 'message' => __('api.strava.disconnect_failed'), + 'code' => 'STRAVA_DISCONNECT_FAILED', ], 502); } } catch (ConnectionException $exception) { report($exception); return response()->json([ - 'message' => __('api.strava.disconnect_failed'), + 'code' => 'STRAVA_DISCONNECT_FAILED', ], 502); } @@ -137,13 +137,13 @@ class StravaController extends Controller if (! $connection) { return response()->json([ - 'message' => __('api.strava.missing_connection'), + 'code' => 'STRAVA_CONNECTION_MISSING', ], 422); } if (! $this->canReadActivities($connection->scopes ?? [])) { return response()->json([ - 'message' => __('api.strava.missing_activity_scope'), + 'code' => 'STRAVA_ACTIVITY_SCOPE_MISSING', ], 422); } diff --git a/app/Http/Controllers/UserBlockController.php b/app/Http/Controllers/UserBlockController.php index a943684..87246c0 100644 --- a/app/Http/Controllers/UserBlockController.php +++ b/app/Http/Controllers/UserBlockController.php @@ -27,12 +27,12 @@ class UserBlockController extends Controller public function store(Request $request, User $user, BlockUser $blockUser): JsonResponse { - abort_if($request->user()->is($user), 422, __('api.blocks.cannot_block_self')); + abort_if($request->user()->is($user), 422, 'CANNOT_BLOCK_SELF'); $blockUser->execute($request->user(), $user); return response()->json([ - 'message' => __('api.blocks.blocked'), + 'code' => 'USER_BLOCKED', ]); } diff --git a/app/Http/Middleware/EnsureAccountIsNotSuspended.php b/app/Http/Middleware/EnsureAccountIsNotSuspended.php index 4626272..656b10d 100644 --- a/app/Http/Middleware/EnsureAccountIsNotSuspended.php +++ b/app/Http/Middleware/EnsureAccountIsNotSuspended.php @@ -17,7 +17,7 @@ class EnsureAccountIsNotSuspended { if ($request->user()?->isSuspended()) { return response()->json([ - 'message' => __('api.auth.suspended'), + 'code' => 'ACCOUNT_SUSPENDED', ], 403); } diff --git a/app/Http/Middleware/EnsureEmailIsVerified.php b/app/Http/Middleware/EnsureEmailIsVerified.php index 8376595..917dd40 100644 --- a/app/Http/Middleware/EnsureEmailIsVerified.php +++ b/app/Http/Middleware/EnsureEmailIsVerified.php @@ -22,7 +22,7 @@ class EnsureEmailIsVerified ($request->user() instanceof MustVerifyEmail && ! $request->user()->hasVerifiedEmail())) { return $request->expectsJson() - ? abort(403, __('api.auth.email_not_verified')) + ? abort(403, 'EMAIL_NOT_VERIFIED') : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice')); } diff --git a/app/Http/Resources/LegalDocumentResource.php b/app/Http/Resources/LegalDocumentResource.php index 07f9cdb..b33bc55 100644 --- a/app/Http/Resources/LegalDocumentResource.php +++ b/app/Http/Resources/LegalDocumentResource.php @@ -15,7 +15,6 @@ class LegalDocumentResource extends JsonResource 'id' => $this->id, 'slug' => $this->slug, 'type' => $this->type?->value, - 'typeLabel' => $this->type?->getLabel(), 'version' => $this->version, 'title' => $this->title, 'content' => $this->content, diff --git a/app/Http/Resources/ReportResource.php b/app/Http/Resources/ReportResource.php index 7a8a770..de2de5d 100644 --- a/app/Http/Resources/ReportResource.php +++ b/app/Http/Resources/ReportResource.php @@ -17,10 +17,8 @@ class ReportResource extends JsonResource return [ 'id' => $this->id, 'reason' => $this->reason, - 'reasonLabel' => $this->reason?->getLabel(), 'details' => $this->details, 'status' => $this->status, - 'statusLabel' => $this->status?->getLabel(), 'reportableType' => $this->reportableType(), 'reportableId' => $this->reportable_id, 'moderationCaseId' => $this->moderation_case_id, diff --git a/app/Services/ContentModerationService.php b/app/Services/ContentModerationService.php index 1a4d48c..6207ee1 100644 --- a/app/Services/ContentModerationService.php +++ b/app/Services/ContentModerationService.php @@ -43,7 +43,7 @@ class ContentModerationService $apiKey = trim((string) config('moderation.content.openai_key')); if ($apiKey === '') { - throw new HttpException(503, __('api.moderation.unavailable')); + throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE'); } $input = []; @@ -80,7 +80,7 @@ class ContentModerationService } catch (Throwable $exception) { report($exception); - throw new HttpException(503, __('api.moderation.unavailable'), $exception); + throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE', $exception); } if (collect($response->json('results', []))->contains( @@ -107,7 +107,7 @@ class ContentModerationService $contents = file_get_contents($image->getRealPath()); if ($contents === false) { - throw new HttpException(503, __('api.moderation.unavailable')); + throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE'); } return sprintf( @@ -126,7 +126,7 @@ class ContentModerationService private function rejectContent(): never { throw ValidationException::withMessages([ - 'content' => [__('api.moderation.rejected')], + 'content' => ['CONTENT_MODERATION_REJECTED'], ]); } } diff --git a/app/Services/ModerationReportService.php b/app/Services/ModerationReportService.php index 865abd9..0f4eefa 100644 --- a/app/Services/ModerationReportService.php +++ b/app/Services/ModerationReportService.php @@ -35,7 +35,7 @@ class ModerationReportService ->where('reportable_id', $reportable->getKey()) ->exists(), 409, - __('api.reports.already_exists'), + 'REPORT_ALREADY_EXISTS', ); $report = Report::create([ @@ -62,7 +62,7 @@ class ModerationReportService }); } catch (QueryException $exception) { if ($this->isDuplicateReportException($exception)) { - abort(409, __('api.reports.already_exists')); + abort(409, 'REPORT_ALREADY_EXISTS'); } throw $exception; @@ -128,19 +128,19 @@ class ModerationReportService abort_if( $reportable instanceof User && $reportable->is($reporter), 422, - __('api.reports.cannot_report_self'), + 'CANNOT_REPORT_SELF', ); abort_if( $reportable instanceof MealPosts && $reportable->user_id === $reporter->getKey(), 422, - __('api.reports.cannot_report_own_meal'), + 'CANNOT_REPORT_OWN_MEAL', ); abort_if( $reportable instanceof PostReviews && $reportable->user_id === $reporter->getKey(), 422, - __('api.reports.cannot_report_own_review'), + 'CANNOT_REPORT_OWN_REVIEW', ); } diff --git a/tests/Feature/AccountDeletionTest.php b/tests/Feature/AccountDeletionTest.php index 37e0b0a..2e5c875 100644 --- a/tests/Feature/AccountDeletionTest.php +++ b/tests/Feature/AccountDeletionTest.php @@ -62,7 +62,7 @@ it('deletes the authenticated account and related data', function () { $this->deleteJson('/api/auth/me') ->assertOk() - ->assertJsonPath('message', __('api.auth.deleted')); + ->assertJsonPath('code', 'ACCOUNT_DELETED'); $this->assertDatabaseMissing('users', ['id' => $user->getKey()]); $this->assertDatabaseMissing('meal_posts', ['id' => $localMealPost->getKey()]); diff --git a/tests/Feature/CertificationTest.php b/tests/Feature/CertificationTest.php index 9fcc901..8710e1f 100644 --- a/tests/Feature/CertificationTest.php +++ b/tests/Feature/CertificationTest.php @@ -70,7 +70,7 @@ it('prevents replacing a document while it is under review', function () { 'document' => UploadedFile::fake()->image('identity.jpg'), ]) ->assertConflict() - ->assertJsonPath('message', __('api.certification.already_pending')); + ->assertJsonPath('code', 'CERTIFICATION_ALREADY_PENDING'); }); it('approves a certification and removes the reviewed identity document', function () { diff --git a/tests/Feature/ContentModerationTest.php b/tests/Feature/ContentModerationTest.php index 510e336..b4babbc 100644 --- a/tests/Feature/ContentModerationTest.php +++ b/tests/Feature/ContentModerationTest.php @@ -131,7 +131,7 @@ it('fails closed when production moderation cannot be reached', function () { 'comment' => 'Très bon repas.', ]) ->assertServiceUnavailable() - ->assertJsonPath('message', __('api.moderation.unavailable')); + ->assertJsonPath('code', 'CONTENT_MODERATION_UNAVAILABLE'); $this->assertDatabaseCount('post_reviews', 0); }); diff --git a/tests/Feature/MealImageAnalysisTest.php b/tests/Feature/MealImageAnalysisTest.php index 36d1e74..6378d9e 100644 --- a/tests/Feature/MealImageAnalysisTest.php +++ b/tests/Feature/MealImageAnalysisTest.php @@ -133,7 +133,7 @@ it('records a failed meal image analysis attempt', function () { 'image' => fakeMealAnalysisImage(), ]) ->assertStatus(502) - ->assertJsonPath('message', __('api.meal_image_analysis.failed')); + ->assertJsonPath('code', 'MEAL_ANALYSIS_FAILED'); Exceptions::assertReported(\RuntimeException::class); @@ -172,7 +172,7 @@ it('requires an active subscription to analyze a meal image', function () { 'image' => fakeMealAnalysisImage(), ]) ->assertStatus(402) - ->assertJsonPath('message', __('api.meal_image_analysis.subscription_required')); + ->assertJsonPath('code', 'MEAL_ANALYSIS_SUBSCRIPTION_REQUIRED'); expect(AiUsage::query()->count())->toBe(0); }); diff --git a/tests/Feature/ModerationReportsTest.php b/tests/Feature/ModerationReportsTest.php index a464475..5bd1068 100644 --- a/tests/Feature/ModerationReportsTest.php +++ b/tests/Feature/ModerationReportsTest.php @@ -23,7 +23,7 @@ it('creates a report and a moderation case for a meal post', function () { 'details' => 'Même image publiée en boucle.', ]) ->assertCreated() - ->assertJsonPath('message', __('api.reports.created')) + ->assertJsonPath('code', 'REPORT_CREATED') ->assertJsonPath('data.reason', ReportReason::SPAM->value) ->assertJsonPath('data.reportableType', 'meal_post') ->assertJsonPath('data.reportableId', $mealPost->id); @@ -58,7 +58,7 @@ it('prevents duplicate reports and reports on own content', function () { $this->postJson("/api/meal-posts/{$mealPost->id}/reports", $payload) ->assertConflict() - ->assertJsonPath('message', __('api.reports.already_exists')); + ->assertJsonPath('code', 'REPORT_ALREADY_EXISTS'); expect(Report::query()->count())->toBe(1); @@ -66,7 +66,7 @@ it('prevents duplicate reports and reports on own content', function () { $this->postJson("/api/meal-posts/{$mealPost->id}/reports", $payload) ->assertUnprocessable() - ->assertJsonPath('message', __('api.reports.cannot_report_own_meal')); + ->assertJsonPath('code', 'CANNOT_REPORT_OWN_MEAL'); }); it('reports users and prevents reporting own profile', function () { @@ -94,7 +94,7 @@ it('reports users and prevents reporting own profile', function () { 'reason' => ReportReason::OTHER->value, ]) ->assertUnprocessable() - ->assertJsonPath('message', __('api.reports.cannot_report_self')); + ->assertJsonPath('code', 'CANNOT_REPORT_SELF'); }); it('reports post reviews and prevents reporting own review', function () { @@ -128,7 +128,7 @@ it('reports post reviews and prevents reporting own review', function () { 'reason' => ReportReason::OTHER->value, ]) ->assertUnprocessable() - ->assertJsonPath('message', __('api.reports.cannot_report_own_review')); + ->assertJsonPath('code', 'CANNOT_REPORT_OWN_REVIEW'); }); it('notifies moderators once when a report threshold is reached', function () { diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php index 0e2f69f..7f862b1 100644 --- a/tests/Feature/PasswordResetTest.php +++ b/tests/Feature/PasswordResetTest.php @@ -30,7 +30,7 @@ it('sends a password reset email with a clickable api web url', function () { 'email' => 'LEON@example.com', ]) ->assertOk() - ->assertJsonPath('message', __('api.auth.password_reset_link_sent')); + ->assertJsonPath('code', 'PASSWORD_RESET_LINK_SENT'); Notification::assertSentTo( $user, @@ -99,7 +99,7 @@ it('does not reveal whether a reset email can be sent', function () { 'email' => 'missing@example.com', ]) ->assertOk() - ->assertJsonPath('message', __('api.auth.password_reset_link_sent')); + ->assertJsonPath('code', 'PASSWORD_RESET_LINK_SENT'); Notification::assertNothingSent(); }); @@ -121,7 +121,7 @@ it('resets the password and invalidates existing api tokens', function () { 'token' => $token, ]) ->assertOk() - ->assertJsonPath('message', __('api.auth.password_reset')); + ->assertJsonPath('code', 'PASSWORD_RESET'); expect(Hash::check('new-password', $user->fresh()->password))->toBeTrue(); @@ -208,7 +208,7 @@ it('rejects an invalid password reset token', function () { 'token' => 'invalid-token', ]) ->assertUnprocessable() - ->assertJsonPath('message', __('passwords.token')); + ->assertJsonPath('code', 'PASSWORD_RESET_FAILED'); expect(Hash::check('new-password', $user->fresh()->password))->toBeFalse(); }); diff --git a/tests/Feature/PostReviewsControllerTest.php b/tests/Feature/PostReviewsControllerTest.php index 99cb17d..274fe90 100644 --- a/tests/Feature/PostReviewsControllerTest.php +++ b/tests/Feature/PostReviewsControllerTest.php @@ -37,7 +37,7 @@ it('creates one review per user for a meal post', function () { 'rating' => 4, ]) ->assertConflict() - ->assertJsonPath('message', __('api.post_reviews.already_exists')); + ->assertJsonPath('code', 'MEAL_REVIEW_ALREADY_EXISTS'); expect(PostReviews::query()->count())->toBe(1); }); diff --git a/tests/Feature/StravaConnectionTest.php b/tests/Feature/StravaConnectionTest.php index bc589c4..2652a33 100644 --- a/tests/Feature/StravaConnectionTest.php +++ b/tests/Feature/StravaConnectionTest.php @@ -174,7 +174,7 @@ it('keeps the local strava connection when strava revocation fails temporarily', $this ->deleteJson('/api/strava/connection') ->assertStatus(502) - ->assertJsonPath('message', __('api.strava.disconnect_failed')); + ->assertJsonPath('code', 'STRAVA_DISCONNECT_FAILED'); expect($user->fresh()->stravaConnection)->not->toBeNull(); }); @@ -295,5 +295,5 @@ it('requires an activity read scope before syncing strava activities', function $this ->postJson('/api/strava/sync') ->assertUnprocessable() - ->assertJsonPath('message', __('api.strava.missing_activity_scope')); + ->assertJsonPath('code', 'STRAVA_ACTIVITY_SCOPE_MISSING'); }); diff --git a/tests/Feature/UpdatePasswordTest.php b/tests/Feature/UpdatePasswordTest.php index fd1c4aa..c50067a 100644 --- a/tests/Feature/UpdatePasswordTest.php +++ b/tests/Feature/UpdatePasswordTest.php @@ -21,7 +21,7 @@ it('updates the authenticated user password and keeps the current api token', fu 'passwordConfirmation' => 'NewPassword123!', ]) ->assertOk() - ->assertJsonPath('message', __('api.auth.password_updated')); + ->assertJsonPath('code', 'PASSWORD_UPDATED'); expect(Hash::check('NewPassword123!', $user->fresh()->password))->toBeTrue(); diff --git a/tests/Feature/UserBlockingTest.php b/tests/Feature/UserBlockingTest.php index 55fad52..a4cb828 100644 --- a/tests/Feature/UserBlockingTest.php +++ b/tests/Feature/UserBlockingTest.php @@ -21,7 +21,7 @@ it('blocks a user idempotently, removes follows, lists the block, and unblocks', $this->postJson("/api/users/{$blocked->id}/block") ->assertOk() - ->assertJsonPath('message', __('api.blocks.blocked')); + ->assertJsonPath('code', 'USER_BLOCKED'); $this->postJson("/api/users/{$blocked->id}/block")->assertOk(); @@ -46,7 +46,7 @@ it('does not allow a user to block themselves', function () { $this->postJson("/api/users/{$user->id}/block") ->assertUnprocessable() - ->assertJsonPath('message', __('api.blocks.cannot_block_self')); + ->assertJsonPath('code', 'CANNOT_BLOCK_SELF'); }); it('requires authentication to manage blocks', function () {