api/tests/Feature/RateLimitingTest.php

36 lines
849 B
PHP

<?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();
});