From 0051f43c67f52779bd51981f86c808c0272975e6 Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Thu, 12 Dec 2019 00:04:07 +0300 Subject: [PATCH] Deleting problem of currencies at wizard step is fixed. It also solves issue #934 Feature tests are added. --- database/seeds/Roles.php | 32 +++++------ routes/wizard.php | 9 ++-- tests/Feature/Wizard/CurrenciesTest.php | 70 +++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 tests/Feature/Wizard/CurrenciesTest.php diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index 98ca30760..1dfad191a 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -17,12 +17,12 @@ class Roles extends Seeder public function run() { Model::unguard(); - + $this->create($this->roles(), $this->map()); - + Model::reguard(); } - + private function roles() { $rows = [ @@ -76,7 +76,7 @@ class Roles extends Seeder 'settings-schedule' => 'r', 'settings-taxes' => 'c,r,u,d', 'wizard-companies' => 'c,r,u', - 'wizard-currencies' => 'c,r,u', + 'wizard-currencies' => 'c,r,u,d', 'wizard-finish' => 'c,r,u', 'wizard-taxes' => 'c,r,u', ], @@ -127,10 +127,10 @@ class Roles extends Seeder 'portal-profile' => 'r,u', ], ]; - + return $rows; } - + private function map() { $rows = [ @@ -139,14 +139,14 @@ class Roles extends Seeder 'u' => 'update', 'd' => 'delete' ]; - + return $rows; } - + private function create($roles, $map) { $mapPermission = collect($map); - + foreach ($roles as $key => $modules) { // Create a new role $role = Role::create([ @@ -154,26 +154,26 @@ class Roles extends Seeder 'display_name' => ucwords(str_replace("_", " ", $key)), 'description' => ucwords(str_replace("_", " ", $key)) ]); - + $this->command->info('Creating Role '. strtoupper($key)); - + // Reading role permission modules foreach ($modules as $module => $value) { $permissions = explode(',', $value); - + foreach ($permissions as $p => $perm) { $permissionValue = $mapPermission->get($perm); - + $moduleName = ucwords(str_replace("-", " ", $module)); - + $permission = Permission::firstOrCreate([ 'name' => $permissionValue . '-' . $module, 'display_name' => ucfirst($permissionValue) . ' ' . $moduleName, 'description' => ucfirst($permissionValue) . ' ' . $moduleName, ]); - + $this->command->info('Creating Permission to '.$permissionValue.' for '. $moduleName); - + if (!$role->hasPermission($permission->name)) { $role->attachPermission($permission); } else { diff --git a/routes/wizard.php b/routes/wizard.php index 9e0c1ff7a..74354ed73 100644 --- a/routes/wizard.php +++ b/routes/wizard.php @@ -3,16 +3,17 @@ Route::group(['as' => 'wizard.'], function () { Route::get('companies', 'Wizard\Companies@edit')->name('companies.edit'); Route::patch('companies', 'Wizard\Companies@update')->name('companies.update'); - + Route::get('currencies', 'Wizard\Currencies@index')->name('currencies.index'); - Route::get('currencies/{currency}/delete', 'Wizard\Currencies@destroy')->name('currencies.delete'); + Route::delete('currencies/{currency}', 'Wizard\Currencies@destroy')->name('currencies.delete'); Route::post('currencies', 'Wizard\Currencies@store')->name('currencies.store'); Route::patch('currencies/{currency}', 'Wizard\Currencies@update')->name('currencies.update'); - + Route::get('taxes', 'Wizard\Taxes@index')->name('taxes.index'); Route::get('taxes/{tax}/delete', 'Wizard\Taxes@destroy')->name('taxes.delete'); Route::post('taxes', 'Wizard\Taxes@store')->name('taxes.store'); Route::patch('taxes/{tax}', 'Wizard\Taxes@update')->name('taxes.update'); - + Route::get('finish', 'Wizard\Finish@index')->name('finish.index'); }); + \ No newline at end of file diff --git a/tests/Feature/Wizard/CurrenciesTest.php b/tests/Feature/Wizard/CurrenciesTest.php new file mode 100644 index 000000000..63277fd12 --- /dev/null +++ b/tests/Feature/Wizard/CurrenciesTest.php @@ -0,0 +1,70 @@ +loginAs() + ->get(route('wizard.currencies.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.currencies', 2)); + } + + public function testItShouldCreateCurrency() + { + $this->loginAs() + ->post(route('wizard.currencies.store'), $this->getCurrencyRequest()) + ->assertStatus(200); + + $this->assertFlashLevel('success'); + } + + public function testItShouldUpdateCurrency() + { + $request = $this->getCurrencyRequest(); + + $currency = $this->dispatch(new CreateCurrency($request)); + + $request['name'] = $this->faker->text(15); + + $this->loginAs() + ->patch(route('wizard.currencies.update', $currency->id), $request) + ->assertStatus(200); + + $this->assertFlashLevel('success'); + } + + public function testItShouldDeleteCurrency() + { + $currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest())); + + $this->loginAs() + ->delete(route('wizard.currencies.delete', $currency->id)) + ->assertStatus(200); + + $this->assertFlashLevel('success'); + } + + private function getCurrencyRequest() + { + return [ + 'company_id' => $this->company->id, + 'name' => $this->faker->text(15), + 'code' => $this->faker->text(strtoupper(5)), + 'rate' => $this->faker->boolean(1), + 'precision' => $this->faker->text(5), + 'symbol' => $this->faker->text(5), + 'symbol_first' => 1, + 'symbol_position' => 'after_amount', + 'decimal_mark' => $this->faker->text(5), + 'thousands_separator' => $this->faker->text(5), + 'enabled' => $this->faker->boolean ? 1 : 0, + 'default_currency' => 0 + ]; + } +}