From eee6733cb2ceb258be0dc284203b6135f184555c Mon Sep 17 00:00:00 2001 From: AndreasElia Date: Fri, 19 Feb 2021 00:31:05 +0000 Subject: [PATCH] add tests --- tests/Feature/ExportPostmanTest.php | 42 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/Feature/ExportPostmanTest.php b/tests/Feature/ExportPostmanTest.php index a2c419a..f33850f 100644 --- a/tests/Feature/ExportPostmanTest.php +++ b/tests/Feature/ExportPostmanTest.php @@ -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']); } }