|
52 | 52 | '$ref' => '#/components/links/Foo', |
53 | 53 | ]); |
54 | 54 | }); |
| 55 | + |
| 56 | +it('inserts requestBody after parameters when parameters are present', function (): void { |
| 57 | + $link = Link::create() |
| 58 | + ->operationId('users.create') |
| 59 | + ->parameters(['id' => '$response.body#/id']) |
| 60 | + ->requestBody(['key' => 'value']); |
| 61 | + |
| 62 | + $array = $link->toArray(); |
| 63 | + |
| 64 | + expect($array)->toHaveKey('requestBody'); |
| 65 | + expect($array['requestBody'])->toBe(['key' => 'value']); |
| 66 | + $keys = array_keys($array); |
| 67 | + expect(array_search('requestBody', $keys))->toBeGreaterThan(array_search('parameters', $keys)); |
| 68 | +}); |
| 69 | + |
| 70 | +it('inserts requestBody before description when no parameters present', function (): void { |
| 71 | + $link = Link::create() |
| 72 | + ->operationId('users.show') |
| 73 | + ->requestBody(null) |
| 74 | + ->description('Fetch user'); |
| 75 | + |
| 76 | + $array = $link->toArray(); |
| 77 | + |
| 78 | + expect($array)->toHaveKey('requestBody'); |
| 79 | + $keys = array_keys($array); |
| 80 | + expect(array_search('requestBody', $keys))->toBeLessThan(array_search('description', $keys)); |
| 81 | +}); |
| 82 | + |
| 83 | +it('inserts requestBody before server when no parameters or description', function (): void { |
| 84 | + $link = Link::create() |
| 85 | + ->operationId('users.show') |
| 86 | + ->requestBody(['body' => 'data']) |
| 87 | + ->server(Server::create('https://api.example.com')); |
| 88 | + |
| 89 | + $array = $link->toArray(); |
| 90 | + |
| 91 | + expect($array)->toHaveKey('requestBody'); |
| 92 | + $keys = array_keys($array); |
| 93 | + expect(array_search('requestBody', $keys))->toBeLessThan(array_search('server', $keys)); |
| 94 | +}); |
| 95 | + |
| 96 | +it('appends requestBody at end when no parameters, description, or server', function (): void { |
| 97 | + $link = Link::create() |
| 98 | + ->operationId('users.show') |
| 99 | + ->requestBody(['body' => 'data']); |
| 100 | + |
| 101 | + $array = $link->toArray(); |
| 102 | + |
| 103 | + expect($array)->toHaveKey('requestBody'); |
| 104 | + expect(array_key_last($array))->toBe('requestBody'); |
| 105 | +}); |
0 commit comments