Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaselia committed Feb 19, 2021
1 parent 32d472f commit eee6733
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions tests/Feature/ExportPostmanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,53 @@ public function test_standard_export_works()

public function test_bearer_export_works()
{
$this->artisan('export:postman --bearer=1234567890')
->assertExitCode(0);
$this->artisan('export:postman --bearer=1234567890')->assertExitCode(0);

$this->assertTrue(true);
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);

$routes = $this->app['router']->getRoutes();

$collectionVariables = $collection['variable'];

foreach ($collectionVariables as $variable) {
if ($variable['key'] != 'token') {
continue;
}

// ensure output contains json x
$this->assertEquals($variable['value'], '1234567890');
}

$this->assertCount(2, $collectionVariables);

$collectionItems = $collection['item'];

// ensure output has headers and variable json
$this->assertCount(count($routes), $collectionItems);

foreach ($routes as $route) {
$collectionRoute = Arr::first($collectionItems, function ($item) use ($route) {
return $item['name'] == $route->uri();
});

$this->assertNotNull($collectionRoute);
$this->assertTrue(in_array($collectionRoute['request']['method'], $route->methods()));
}
}

public function test_structured_export_works()
{
// set structured to true in config
config()->set('api-postman.structured', true);

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

$this->assertTrue(true);

// ensure output contains json x
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);

$routes = $this->app['router']->getRoutes();

$collectionItems = $collection['item'];

$this->assertCount(count($routes), $collectionItems[0]['item']);
}
}

0 comments on commit eee6733

Please sign in to comment.