Files
SkinbaseNova/tests/Feature/Moderation/CommentSpamSignatureHitCountTest.php
klevze 586c44ba74 Add comment spam classification and captcha checks.
Score artwork comments with local signatures plus Together AI, and optionally require Turnstile before posting.
2026-09-20 14:48:50 +02:00

49 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\CommentSpamSignature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('increments signature hit_count when a known spam comment is posted', function (): void {
config([
'comment_spam.enabled' => true,
'comment_spam.mode' => 'enforce',
'comment_spam.ai_enabled' => false,
'comment_spam.captcha.enabled' => false,
]);
$user = User::factory()->create();
$artwork = Artwork::factory()->create();
$content = 'copy paste this known spam signature';
$hash = hash('sha256', mb_strtolower((string) preg_replace('/\s+/u', ' ', trim($content))));
$signature = CommentSpamSignature::query()->create([
'content_hash' => $hash,
'source' => 'spam',
'reason' => 'Known promotional spam.',
'confidence' => 100,
'hit_count' => 0,
'created_at' => now(),
]);
$this->actingAs($user)
->postJson("/api/artworks/{$artwork->id}/comments", [
'content' => $content,
])
->assertCreated();
expect((int) $signature->fresh()->hit_count)->toBe(1);
$comment = ArtworkComment::query()->latest('id')->first();
expect($comment)->not->toBeNull()
->and((bool) $comment->is_approved)->toBeFalse()
->and((string) $comment->moderation_source)->toBe('signature');
});