]> BookStack Code Mirror - bookstack/blob - tests/Api/ApiConfigTest.php
Merge branch 'master' of git://github.com/osmansorkar/BookStack into osmansorkar...
[bookstack] / tests / Api / ApiConfigTest.php
1 <?php namespace Tests\Api;
2
3 use Tests\TestCase;
4
5 class ApiConfigTest extends TestCase
6 {
7     use TestsApi;
8
9     protected $endpoint = '/api/books';
10
11     public function test_default_item_count_reflected_in_listing_requests()
12     {
13         $this->actingAsApiEditor();
14
15         config()->set(['api.default_item_count' => 5]);
16         $resp = $this->get($this->endpoint);
17         $resp->assertJsonCount(5, 'data');
18
19         config()->set(['api.default_item_count' => 1]);
20         $resp = $this->get($this->endpoint);
21         $resp->assertJsonCount(1, 'data');
22     }
23
24     public function test_default_item_count_does_not_limit_count_param()
25     {
26         $this->actingAsApiEditor();
27         config()->set(['api.default_item_count' => 1]);
28         $resp = $this->get($this->endpoint . '?count=5');
29         $resp->assertJsonCount(5, 'data');
30     }
31
32     public function test_max_item_count_limits_listing_requests()
33     {
34         $this->actingAsApiEditor();
35
36         config()->set(['api.max_item_count' => 2]);
37         $resp = $this->get($this->endpoint);
38         $resp->assertJsonCount(2, 'data');
39
40         $resp = $this->get($this->endpoint . '?count=5');
41         $resp->assertJsonCount(2, 'data');
42     }
43
44     public function test_requests_per_min_alters_rate_limit()
45     {
46         $resp = $this->actingAsApiEditor()->get($this->endpoint);
47         $resp->assertHeader('x-ratelimit-limit', 180);
48
49         config()->set(['api.requests_per_minute' => 10]);
50
51         $resp = $this->actingAsApiEditor()->get($this->endpoint);
52         $resp->assertHeader('x-ratelimit-limit', 10);
53     }
54
55 }