2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Api;
|
2019-12-30 15:48:23 -05:00
|
|
|
|
2020-04-03 20:16:05 -04:00
|
|
|
use Tests\TestCase;
|
2019-12-30 15:48:23 -05:00
|
|
|
|
2020-01-01 12:01:36 -05:00
|
|
|
class ApiConfigTest extends TestCase
|
2019-12-30 15:48:23 -05:00
|
|
|
{
|
|
|
|
use TestsApi;
|
|
|
|
|
|
|
|
protected $endpoint = '/api/books';
|
|
|
|
|
|
|
|
public function test_default_item_count_reflected_in_listing_requests()
|
|
|
|
{
|
|
|
|
$this->actingAsApiEditor();
|
|
|
|
|
|
|
|
config()->set(['api.default_item_count' => 5]);
|
|
|
|
$resp = $this->get($this->endpoint);
|
|
|
|
$resp->assertJsonCount(5, 'data');
|
|
|
|
|
|
|
|
config()->set(['api.default_item_count' => 1]);
|
|
|
|
$resp = $this->get($this->endpoint);
|
|
|
|
$resp->assertJsonCount(1, 'data');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_default_item_count_does_not_limit_count_param()
|
|
|
|
{
|
|
|
|
$this->actingAsApiEditor();
|
|
|
|
config()->set(['api.default_item_count' => 1]);
|
|
|
|
$resp = $this->get($this->endpoint . '?count=5');
|
|
|
|
$resp->assertJsonCount(5, 'data');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_max_item_count_limits_listing_requests()
|
|
|
|
{
|
|
|
|
$this->actingAsApiEditor();
|
|
|
|
|
|
|
|
config()->set(['api.max_item_count' => 2]);
|
|
|
|
$resp = $this->get($this->endpoint);
|
|
|
|
$resp->assertJsonCount(2, 'data');
|
|
|
|
|
|
|
|
$resp = $this->get($this->endpoint . '?count=5');
|
|
|
|
$resp->assertJsonCount(2, 'data');
|
|
|
|
}
|
|
|
|
|
2020-01-18 10:03:28 -05:00
|
|
|
public function test_requests_per_min_alters_rate_limit()
|
|
|
|
{
|
|
|
|
$resp = $this->actingAsApiEditor()->get($this->endpoint);
|
|
|
|
$resp->assertHeader('x-ratelimit-limit', 180);
|
|
|
|
|
|
|
|
config()->set(['api.requests_per_minute' => 10]);
|
|
|
|
|
|
|
|
$resp = $this->actingAsApiEditor()->get($this->endpoint);
|
|
|
|
$resp->assertHeader('x-ratelimit-limit', 10);
|
|
|
|
}
|
2021-06-26 11:23:15 -04:00
|
|
|
}
|