Skip to content

Commit eee6733

Browse files
committed
add tests
1 parent 32d472f commit eee6733

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

tests/Feature/ExportPostmanTest.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,53 @@ public function test_standard_export_works()
4040

4141
public function test_bearer_export_works()
4242
{
43-
$this->artisan('export:postman --bearer=1234567890')
44-
->assertExitCode(0);
43+
$this->artisan('export:postman --bearer=1234567890')->assertExitCode(0);
4544

46-
$this->assertTrue(true);
45+
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);
46+
47+
$routes = $this->app['router']->getRoutes();
48+
49+
$collectionVariables = $collection['variable'];
50+
51+
foreach ($collectionVariables as $variable) {
52+
if ($variable['key'] != 'token') {
53+
continue;
54+
}
4755

48-
// ensure output contains json x
56+
$this->assertEquals($variable['value'], '1234567890');
57+
}
58+
59+
$this->assertCount(2, $collectionVariables);
60+
61+
$collectionItems = $collection['item'];
4962

50-
// ensure output has headers and variable json
63+
$this->assertCount(count($routes), $collectionItems);
64+
65+
foreach ($routes as $route) {
66+
$collectionRoute = Arr::first($collectionItems, function ($item) use ($route) {
67+
return $item['name'] == $route->uri();
68+
});
69+
70+
$this->assertNotNull($collectionRoute);
71+
$this->assertTrue(in_array($collectionRoute['request']['method'], $route->methods()));
72+
}
5173
}
5274

5375
public function test_structured_export_works()
5476
{
55-
// set structured to true in config
77+
config()->set('api-postman.structured', true);
5678

5779
$this->artisan('export:postman')
5880
->assertExitCode(0);
5981

6082
$this->assertTrue(true);
6183

62-
// ensure output contains json x
84+
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);
85+
86+
$routes = $this->app['router']->getRoutes();
87+
88+
$collectionItems = $collection['item'];
89+
90+
$this->assertCount(count($routes), $collectionItems[0]['item']);
6391
}
6492
}

0 commit comments

Comments
 (0)