feat: rate limiting

This commit is contained in:
2026-05-23 09:34:51 +02:00
parent 6f619a8184
commit cd38d88fe7
3 changed files with 130 additions and 26 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
uses(RefreshDatabase::class);
it('rate limits meal post creation attempts', function () {
Sanctum::actingAs(User::factory()->create());
foreach (range(1, 30) as $_) {
$this
->postJson('/api/meal-posts')
->assertUnprocessable();
}
$this
->postJson('/api/meal-posts')
->assertTooManyRequests();
});
it('rate limits meal image analysis attempts more strictly', function () {
Sanctum::actingAs(User::factory()->create());
foreach (range(1, 5) as $_) {
$this
->postJson('/api/meal-posts/analyze-image')
->assertUnprocessable();
}
$this
->postJson('/api/meal-posts/analyze-image')
->assertTooManyRequests();
});