feat: rate limiting
This commit is contained in:
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user