feat: report reviews etc ...
This commit is contained in:
@@ -4,6 +4,7 @@ use App\Enums\ReportReason;
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\MealPosts;
|
||||
use App\Models\ModerationCase;
|
||||
use App\Models\PostReviews;
|
||||
use App\Models\Report;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -96,6 +97,40 @@ it('reports users and prevents reporting own profile', function () {
|
||||
->assertJsonPath('message', __('api.reports.cannot_report_self'));
|
||||
});
|
||||
|
||||
it('reports post reviews and prevents reporting own review', function () {
|
||||
$reviewAuthor = User::factory()->create();
|
||||
$reporter = User::factory()->create();
|
||||
$review = PostReviews::query()->create([
|
||||
'meal_post_id' => MealPosts::factory()->create()->id,
|
||||
'user_id' => $reviewAuthor->id,
|
||||
'rating' => 2,
|
||||
'comment' => 'Commentaire problématique.',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($reporter);
|
||||
|
||||
$this->postJson("/api/post-reviews/{$review->id}/reports", [
|
||||
'reason' => ReportReason::INAPPROPRIATE->value,
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.reportableType', 'post_review')
|
||||
->assertJsonPath('data.reportableId', $review->id);
|
||||
|
||||
$this->assertDatabaseHas('moderation_cases', [
|
||||
'caseable_type' => PostReviews::class,
|
||||
'caseable_id' => $review->id,
|
||||
'threshold' => 3,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($reviewAuthor);
|
||||
|
||||
$this->postJson("/api/post-reviews/{$review->id}/reports", [
|
||||
'reason' => ReportReason::OTHER->value,
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonPath('message', __('api.reports.cannot_report_own_review'));
|
||||
});
|
||||
|
||||
it('notifies moderators once when a report threshold is reached', function () {
|
||||
$admin = User::factory()->create(['role' => UserRole::ADMIN]);
|
||||
$moderator = User::factory()->create(['role' => UserRole::MODERATOR]);
|
||||
|
||||
Reference in New Issue
Block a user