]> BookStack Code Mirror - bookstack/blob - tests/Api/ApiConfigTest.php
Fix Crowdin name in the language_request issue template
[bookstack] / tests / Api / ApiConfigTest.php
1 <?php
2
3 namespace Tests\Api;
4
5 use Tests\TestCase;
6
7 class ApiConfigTest extends TestCase
8 {
9     use TestsApi;
10
11     protected $endpoint = '/api/books';
12
13     public function test_default_item_count_reflected_in_listing_requests()
14     {
15         $this->actingAsApiEditor();
16
17         config()->set(['api.default_item_count' => 5]);
18         $resp = $this->get($this->endpoint);
19         $resp->assertJsonCount(5, 'data');
20
21         config()->set(['api.default_item_count' => 1]);
22         $resp = $this->get($this->endpoint);
23         $resp->assertJsonCount(1, 'data');
24     }
25
26     public function test_default_item_count_does_not_limit_count_param()
27     {
28         $this->actingAsApiEditor();
29         config()->set(['api.default_item_count' => 1]);
30         $resp = $this->get($this->endpoint . '?count=5');
31         $resp->assertJsonCount(5, 'data');
32     }
33
34     public function test_max_item_count_limits_listing_requests()
35     {
36         $this->actingAsApiEditor();
37
38         config()->set(['api.max_item_count' => 2]);
39         $resp = $this->get($this->endpoint);
40         $resp->assertJsonCount(2, 'data');
41
42         $resp = $this->get($this->endpoint . '?count=5');
43         $resp->assertJsonCount(2, 'data');
44     }
45
46     public function test_requests_per_min_alters_rate_limit()
47     {
48         $resp = $this->actingAsApiEditor()->get($this->endpoint);
49         $resp->assertHeader('x-ratelimit-limit', 180);
50
51         config()->set(['api.requests_per_minute' => 10]);
52
53         $resp = $this->actingAsApiEditor()->get($this->endpoint);
54         $resp->assertHeader('x-ratelimit-limit', 10);
55     }
56 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.