From 05f1813a25713cf351e1e6028e8fd22897e24dee Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Sat, 21 Mar 2020 22:53:21 +0100 Subject: [PATCH] Test 2fauth console command --- app/Console/Commands/ResetDemo.php | 7 +- tests/Feature/ConsoleTest.php | 145 +++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/ConsoleTest.php diff --git a/app/Console/Commands/ResetDemo.php b/app/Console/Commands/ResetDemo.php index 57eab8ce..693438d1 100644 --- a/app/Console/Commands/ResetDemo.php +++ b/app/Console/Commands/ResetDemo.php @@ -39,8 +39,6 @@ public function __construct() */ public function handle() { - $this->callSilent('config:cache'); - if( !config('app.options.isDemoApp') ) { $this->comment('2fauth:reset-demo can only run when isDemoApp option is On'); return; @@ -57,10 +55,7 @@ public function handle() if ($demo === 'demo') { // Delete all icons - $filesForDelete = array_filter(glob('public/icons/*'), function($file) { - return false === strpos($file, '.gitignore'); - }); - + $filesForDelete = \Illuminate\Support\Facades\File::glob('public/icons/*.png'); Storage::delete($filesForDelete); $this->line('Existing icons deleted'); diff --git a/tests/Feature/ConsoleTest.php b/tests/Feature/ConsoleTest.php new file mode 100644 index 00000000..1d25a2e5 --- /dev/null +++ b/tests/Feature/ConsoleTest.php @@ -0,0 +1,145 @@ +artisan('2fauth:reset-demo') + ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On') + ->assertExitCode(0); + } + + /** + * Test 2fauth:reset-demo console command. + * + * @return void + */ + public function test2fauthResetDemowithConfirmConsoleCommand() + { + Config::set('app.options.isDemoApp', true); + + $this->artisan('2fauth:reset-demo') + ->expectsOutput('This will reset the app in order to run a clean and fresh demo.') + ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo') + ->expectsOutput('Demo app refreshed') + ->assertExitCode(0); + + $user = User::find(1); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/1') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Amazon', + 'icon' => 'amazon.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/2') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Apple', + 'icon' => 'apple.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/3') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Dropbox', + 'icon' => 'dropbox.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/4') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Facebook', + 'icon' => 'facebook.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/5') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Github', + 'icon' => 'github.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/6') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Google', + 'icon' => 'google.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/7') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Instagram', + 'icon' => 'instagram.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/8') + ->assertStatus(200) + ->assertJson([ + 'service' => 'LinkedIn', + 'icon' => 'linkedin.png', + ]); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/twofaccounts/9') + ->assertStatus(200) + ->assertJson([ + 'service' => 'Twitter', + 'icon' => 'twitter.png', + ]); + } + + /** + * Test 2fauth:reset-demo console command. + * + * @return void + */ + public function test2fauthResetDemowithBadConfirmationConsoleCommand() + { + Config::set('app.options.isDemoApp', true); + + $this->artisan('2fauth:reset-demo') + ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null') + ->expectsOutput('Bad confirmation word, nothing appened') + ->assertExitCode(0); + } + + + /** + * Test 2fauth:reset-demo console command. + * + * @return void + */ + public function test2fauthResetDemowithoutConfirmationConsoleCommand() + { + Config::set('app.options.isDemoApp', true); + + $this->artisan('2fauth:reset-demo --no-confirm') + ->expectsOutput('Demo app refreshed') + ->assertExitCode(0); + } + +} \ No newline at end of file