Skip to content

Commit 359a332

Browse files
committed
Expand tests with get request query test
1 parent c797f1a commit 359a332

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tests/Feature/ExportPostmanTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ public function test_rules_printing_export_works()
167167
$this->assertCount(1, $fields->where('key', 'field_6')->where('description', 'in:"1","2","3"'));
168168
}
169169

170+
public function test_rules_printing_get_export_works()
171+
{
172+
config([
173+
'api-postman.enable_formdata' => true,
174+
'api-postman.print_rules' => true,
175+
'api-postman.rules_to_human_readable' => false,
176+
]);
177+
178+
$this->artisan('export:postman')->assertExitCode(0);
179+
180+
$this->assertTrue(true);
181+
182+
$collection = collect(json_decode(Storage::get('postman/'.config('api-postman.filename')), true)['item']);
183+
184+
$targetRequest = $collection
185+
->where('name', 'example/getWithFormRequest')
186+
->first();
187+
188+
$fields = collect($targetRequest['request']['url']['query']);
189+
$this->assertCount(1, $fields->where('key', 'field_1')->where('description', 'required'));
190+
$this->assertCount(1, $fields->where('key', 'field_2')->where('description', 'required, integer'));
191+
$this->assertCount(1, $fields->where('key', 'field_5')->where('description', 'required, integer, max:30, min:1'));
192+
$this->assertCount(1, $fields->where('key', 'field_6')->where('description', 'in:"1","2","3"'));
193+
194+
// Check for the required structure of the get request query
195+
foreach ($fields as $field) {
196+
$this->assertEqualsCanonicalizing([
197+
'key' => $field['key'],
198+
'value' => null,
199+
'disabled' => false,
200+
'description' => $field['description']
201+
], $field);
202+
}
203+
}
204+
170205
public function test_rules_printing_export_to_human_readable_works()
171206
{
172207
config([

tests/Fixtures/ExampleController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ public function storeWithFormRequest(ExampleFormRequest $request): string
3535
{
3636
return 'storeWithFormRequest';
3737
}
38+
39+
public function getWithFormRequest(ExampleFormRequest $request): string
40+
{
41+
return 'getWithFormRequest';
42+
}
3843
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected function defineRoutes($router)
2020
$router->delete('delete', [ExampleController::class, 'delete'])->name('delete');
2121
$router->get('showWithReflectionMethod', [ExampleController::class, 'showWithReflectionMethod'])->name('show-with-reflection-method');
2222
$router->post('storeWithFormRequest', [ExampleController::class, 'storeWithFormRequest'])->name('store-with-form-request');
23+
$router->get('getWithFormRequest', [ExampleController::class, 'getWithFormRequest'])->name('get-with-form-request');
2324
});
2425
}
2526
}

0 commit comments

Comments
 (0)