diff --git a/.env.testing b/.env.testing index b85eb88f4..06665a5c2 100644 --- a/.env.testing +++ b/.env.testing @@ -1,7 +1,7 @@ APP_NAME=Akaunting APP_ENV=testing APP_LOCALE=en-GB -APP_INSTALLED=false +APP_INSTALLED=true APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc= APP_DEBUG=true APP_SCHEDULE_TIME="09:00" diff --git a/database/migrations/2019_11_17_000000_modify_sku_quantity_column_items_table.php b/database/migrations/2019_11_17_000000_modify_sku_quantity_column_items_table.php new file mode 100644 index 000000000..47ffe646b --- /dev/null +++ b/database/migrations/2019_11_17_000000_modify_sku_quantity_column_items_table.php @@ -0,0 +1,35 @@ +string('sku')->nullable()->change(); + $table->integer('quantity')->default(1)->change(); + $table->dropUnique('items_company_id_sku_deleted_at_unique'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('items', function (Blueprint $table) { + $table->string('sku')->change(); + $table->integer('quantity')->change(); + $table->unique(['company_id', 'sku', 'deleted_at']); + }); + } +} diff --git a/database/seeds/TestCompany.php b/database/seeds/TestCompany.php index 16c70e81f..42ccadedf 100644 --- a/database/seeds/TestCompany.php +++ b/database/seeds/TestCompany.php @@ -5,6 +5,7 @@ namespace Database\Seeds; use App\Abstracts\Model; use App\Models\Auth\User; use App\Models\Common\Company; +use Artisan; use Date; use Illuminate\Database\Seeder; @@ -30,16 +31,9 @@ class TestCompany extends Seeder private function createCompany() { - $rows = [ - [ - 'id' => '1', - 'domain' => 'test.com', - ], - ]; - - foreach ($rows as $row) { - Company::create($row); - } + Company::create([ + 'domain' => 'test.com', + ]); setting()->setExtraColumns(['company_id' => '1']); setting()->set([ @@ -49,11 +43,14 @@ class TestCompany extends Seeder 'localisation.financial_start' => '01-01', 'default.currency' => 'USD', 'default.account' => '1', - 'default.payment_method' => 'offline-paymentz.cash.1', + 'default.payment_method' => 'offline-payments.cash.1', 'schedule.bill_days' => '10,5,3,1', 'schedule.invoice_days' => '1,3,5,10', - 'schedule.send_invoice_reminder' => true, - 'schedule.send_bill_reminder' => true, + 'schedule.send_invoice_reminder' => '0', + 'schedule.send_bill_reminder' => '0', + 'wizard.completed' => '1', + 'contact.type.customer' => 'customer', + 'contact.type.vendor' => 'vendor', ]); setting()->save(); @@ -76,6 +73,11 @@ class TestCompany extends Seeder // Attach company $user->companies()->attach(1); + Artisan::call('user:seed', [ + 'user' => $user->id, + 'company' => 1, + ]); + $this->command->info('Admin user created.'); } } diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php deleted file mode 100644 index abe4f8099..000000000 --- a/tests/Feature/Auth/LoginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -get(route('login')) - ->assertStatus(200) - ->assertSeeText(trans('auth.login_to')); - } - - public function testItShouldLoginUser() - { - $this->post(route('login'), ['email' => $this->user->email, 'password' => $this->user->password]) - ->assertStatus(200); - - $this->isAuthenticated($this->user->user); - } - - public function testItShouldNotLoginUser() - { - $user = factory(User::class)->create([ - 'password' => bcrypt($password = 'correct-password'), - ]); - - $this->post(route('login'), ['email' => $user->email, 'password' != $user->password = $password]) - ->assertStatus(302); - - $this->dontSeeIsAuthenticated(); - } - - public function testItShouldLogoutUser() - { - $user = User::create($this->getLoginRequest()); - - $this->loginAs() - ->get(route('logout',$user->id)) - ->assertStatus(302) - ->assertRedirect(route('login')); - - $this->dontSeeIsAuthenticated(); - } - - private function getLoginRequest() - { - $password = $this->faker->password(); - return[ - 'name' => $this->faker->name, - 'email' => $this->faker->email, - 'password' => $password, - 'companies' => [session('company_id')], - 'roles' => Role::take(1)->pluck('id')->toArray(), - 'enabled' => $this->faker->boolean ? 1 : 0, - ]; - } -} \ No newline at end of file diff --git a/tests/Feature/Auth/PermissionsTest.php b/tests/Feature/Auth/PermissionsTest.php index a6ab5fc19..d6907e33c 100644 --- a/tests/Feature/Auth/PermissionsTest.php +++ b/tests/Feature/Auth/PermissionsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Auth; -use App\Models\Auth\Permission; +use App\Jobs\Auth\CreatePermission; use Tests\Feature\FeatureTestCase; class PermissionsTest extends FeatureTestCase @@ -35,7 +35,7 @@ class PermissionsTest extends FeatureTestCase public function testItShouldSeePermissionUpdatePage() { - $permission = Permission::create($this->getPermissionRequest()); + $permission = $this->dispatch(new CreatePermission($this->getPermissionRequest())); $this->loginAs() ->get(route('permissions.edit', ['permission' => $permission->id])) @@ -47,7 +47,7 @@ class PermissionsTest extends FeatureTestCase { $request = $this->getPermissionRequest(); - $permission = Permission::create($request); + $permission = $this->dispatch(new CreatePermission($request)); $request['name'] = $this->faker->name; @@ -60,7 +60,7 @@ class PermissionsTest extends FeatureTestCase public function testItShouldDeletePermission() { - $permission = Permission::create($this->getPermissionRequest()); + $permission = $this->dispatch(new CreatePermission($this->getPermissionRequest())); $this->loginAs() ->delete(route('permissions.destroy', $permission->id)) diff --git a/tests/Feature/Auth/RolesTest.php b/tests/Feature/Auth/RolesTest.php index a50c6f0a9..d2a96ff78 100644 --- a/tests/Feature/Auth/RolesTest.php +++ b/tests/Feature/Auth/RolesTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Auth; +use App\Jobs\Auth\CreateRole; use App\Models\Auth\Permission; -use App\Models\Auth\Role; use Tests\Feature\FeatureTestCase; class RolesTest extends FeatureTestCase @@ -36,7 +36,7 @@ class RolesTest extends FeatureTestCase public function testItShouldSeeRoleUpdatePage() { - $role = Role::create($this->getRoleRequest()); + $role = $this->dispatch(new CreateRole($this->getRoleRequest())); $this->loginAs() ->get(route('roles.edit', ['role' => $role->id])) @@ -48,7 +48,7 @@ class RolesTest extends FeatureTestCase { $request = $this->getRoleRequest(); - $role = Role::create($request); + $role = $this->dispatch(new CreateRole($request)); $request['name'] = $this->faker->name; @@ -61,7 +61,7 @@ class RolesTest extends FeatureTestCase public function testItShouldDeleteRole() { - $role = Role::create($this->getRoleRequest()); + $role = $this->dispatch(new CreateRole($this->getRoleRequest())); $this->loginAs() ->delete(route('roles.destroy', $role->id)) diff --git a/tests/Feature/Auth/UsersTest.php b/tests/Feature/Auth/UsersTest.php index ea2226b39..4cc72d5e3 100644 --- a/tests/Feature/Auth/UsersTest.php +++ b/tests/Feature/Auth/UsersTest.php @@ -2,13 +2,12 @@ namespace Tests\Feature\Auth; +use App\Jobs\Auth\CreateUser; use App\Models\Auth\Role; -use App\Models\Auth\User; use Tests\Feature\FeatureTestCase; class UsersTest extends FeatureTestCase { - public function testItShouldSeeUserListPage() { $this->loginAs() @@ -36,7 +35,7 @@ class UsersTest extends FeatureTestCase public function testItShouldSeeUserUpdatePage() { - $user = User::create($this->getUserRequest()); + $user = $this->dispatch(new CreateUser($this->getUserRequest())); $this->loginAs() ->get(route('users.edit', ['user' => $user->id])) @@ -48,7 +47,7 @@ class UsersTest extends FeatureTestCase { $request = $this->getUserRequest(); - $user = User::create($request); + $user = $this->dispatch(new CreateUser($request)); $request['name'] = $this->faker->name; @@ -61,7 +60,7 @@ class UsersTest extends FeatureTestCase public function testItShouldDeleteUser() { - $user = User::create($this->getUserRequest()); + $user = $this->dispatch(new CreateUser($this->getUserRequest())); $this->loginAs() ->delete(route('users.destroy', $user->id)) @@ -70,6 +69,45 @@ class UsersTest extends FeatureTestCase $this->assertFlashLevel('success'); } + public function testItShouldSeeLoginPage() + { + $this->get(route('login')) + ->assertStatus(200) + ->assertSeeText(trans('auth.login_to')); + } + + public function testItShouldLoginUser() + { + $user = $this->dispatch(new CreateUser($this->getUserRequest())); + + $this->post(route('login'), ['email' => $user->email, 'password' => $user->password]) + ->assertStatus(200); + + $this->isAuthenticated($user->user); + } + + public function testItShouldNotLoginUser() + { + $user = $this->dispatch(new CreateUser($this->getUserRequest())); + + $this->post(route('login'), ['email' => $user->email, $this->faker->password()]) + ->assertStatus(302); + + $this->assertGuest(); + } + + public function testItShouldLogoutUser() + { + $user = $this->dispatch(new CreateUser($this->getUserRequest())); + + $this->loginAs() + ->get(route('logout', $user->id)) + ->assertStatus(302) + ->assertRedirect(route('login')); + + $this->assertGuest(); + } + private function getUserRequest() { $password = $this->faker->password(); @@ -80,7 +118,7 @@ class UsersTest extends FeatureTestCase 'password' => $password, 'password_confirmation' => $password, 'locale' => 'en-GB', - 'companies' => [session('company_id')], + 'companies' => [$this->company->id], 'roles' => Role::take(1)->pluck('id')->toArray(), 'enabled' => $this->faker->boolean ? 1 : 0, ]; diff --git a/tests/Feature/Banking/AccountsTest.php b/tests/Feature/Banking/AccountsTest.php index 9cd72a6f0..f3101b69a 100644 --- a/tests/Feature/Banking/AccountsTest.php +++ b/tests/Feature/Banking/AccountsTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Banking; +use App\Jobs\Banking\CreateAccount; use App\Models\Banking\Account; use Tests\Feature\FeatureTestCase; @@ -34,7 +35,7 @@ class AccountsTest extends FeatureTestCase public function testItShouldSeeAccountUpdatePage() { - $account = Account::create($this->getAccountRequest()); + $account = $this->dispatch(new CreateAccount($this->getAccountRequest())); $this->loginAs() ->get(route('accounts.edit', ['account' => $account->id])) diff --git a/tests/Feature/Banking/ReconciliationsTest.php b/tests/Feature/Banking/ReconciliationsTest.php index 05c0f88aa..9a04af07c 100644 --- a/tests/Feature/Banking/ReconciliationsTest.php +++ b/tests/Feature/Banking/ReconciliationsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Banking; -use App\Models\Banking\Reconciliation; +use App\Jobs\Banking\CreateReconciliation; use Tests\Feature\FeatureTestCase; class ReconciliationsTest extends FeatureTestCase @@ -34,7 +34,7 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldSeeReconciliationUpdatePage() { - $reconciliation = Reconciliation::create($this->getReconciliationRequest()); + $reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest())); $this->loginAs() ->get(route('reconciliations.edit', ['reconciliation' => $reconciliation->id])) @@ -46,7 +46,7 @@ class ReconciliationsTest extends FeatureTestCase { $request = $this->getReconciliationRequest(); - $reconciliation= Reconciliation::create($request); + $reconciliation= $this->dispatch(new CreateReconciliation($request)); $request['description'] = $this->faker->text(10); @@ -59,7 +59,7 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldDeleteReconciliation() { - $reconciliation = Reconciliation::create($this->getReconciliationRequest()); + $reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest())); $this->loginAs() ->delete(route('reconciliations.destroy', ['reconciliation' => $reconciliation])) diff --git a/tests/Feature/Banking/TransfersTest.php b/tests/Feature/Banking/TransfersTest.php index 152446b21..33ea156e7 100644 --- a/tests/Feature/Banking/TransfersTest.php +++ b/tests/Feature/Banking/TransfersTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Banking; -use App\Models\Banking\Transfer; -use App\Models\Banking\Transaction; +use App\Jobs\Banking\CreateTransaction; +use App\Jobs\Banking\CreateTransfer; use Illuminate\Http\UploadedFile; use Tests\Feature\FeatureTestCase; @@ -28,10 +28,10 @@ class TransfersTest extends FeatureTestCase public function testItShouldCreateTransfer() { // Create income - $income_transaction = Transaction::create($this->getIncomeRequest()); + $income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest())); // Create expense - $expense_transaction = Transaction::create($this->getExpenseRequest()); + $expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest())); $this->loginAs() ->post(route('transfers.store'), $this->getTransferRequest($income_transaction, $expense_transaction)) @@ -43,12 +43,12 @@ class TransfersTest extends FeatureTestCase public function testItShouldSeeTransferUpdatePage() { // Create income - $income_transaction = Transaction::create($this->getIncomeRequest()); + $income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest())); // Create expense - $expense_transaction = Transaction::create($this->getExpenseRequest()); + $expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest())); - $transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction)); + $transfer = $this->dispatch(new CreateTransfer($this->getTransferRequest($income_transaction, $expense_transaction))); $this->loginAs() ->get(route('transfers.edit', ['transfer' => $transfer->id])) @@ -59,14 +59,14 @@ class TransfersTest extends FeatureTestCase public function testItShouldUpdateTransfer() { // Create income - $income_transaction = Transaction::create($this->getIncomeRequest()); + $income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest())); // Create expense - $expense_transaction = Transaction::create($this->getExpenseRequest()); + $expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest())); $request = $this->getTransferRequest($income_transaction, $expense_transaction); - $transfer = Transfer::create($request); + $transfer = $this->dispatch(new CreateTransfer($request)); $request['description'] = $this->faker->text(10); @@ -80,12 +80,12 @@ class TransfersTest extends FeatureTestCase public function testItShouldDeleteTransfer() { // Create income - $income_transaction = Transaction::create($this->getIncomeRequest()); + $income_transaction = $this->dispatch(new CreateTransaction($this->getIncomeRequest())); // Create expense - $expense_transaction = Transaction::create($this->getExpenseRequest()); + $expense_transaction = $this->dispatch(new CreateTransaction($this->getExpenseRequest())); - $transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction)); + $transfer = $this->dispatch(new CreateTransfer($this->getTransferRequest($income_transaction, $expense_transaction))); $this->loginAs() ->delete(route('transfers.destroy', ['transfer' => $transfer->id])) diff --git a/tests/Feature/Commands/BillReminderTest.php b/tests/Feature/Commands/BillReminderTest.php index e3c1b7ca0..92abd2613 100644 --- a/tests/Feature/Commands/BillReminderTest.php +++ b/tests/Feature/Commands/BillReminderTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Commands; -use App\Models\Expense\Bill; +use App\Jobs\Expense\CreateBill; use App\Notifications\Expense\Bill as BillNotification; use Illuminate\Support\Facades\Notification; use Jenssegers\Date\Date; @@ -23,7 +23,7 @@ class BillReminderTest extends FeatureTestCase { Notification::fake(); - $bill = Bill::create($this->getBillRequest()); + $bill = $this->dispatch(new CreateBill($this->getBillRequest())); Date::setTestNow(Date::now()->subDays($this->addDay)); @@ -39,7 +39,7 @@ class BillReminderTest extends FeatureTestCase } /** - * Copied in InvoicesTest + * Bill request * * @param int $recurring * @return array @@ -58,7 +58,7 @@ class BillReminderTest extends FeatureTestCase 'order_number' => '1', 'currency_code' => setting('default.currency'), 'currency_rate' => '1', - 'item' => $items, + 'items' => $items, 'discount' => '0', 'notes' => $this->faker->text(5), 'category_id' => $this->company->categories()->type('income')->first()->id, diff --git a/tests/Feature/Commands/InvoiceReminderTest.php b/tests/Feature/Commands/InvoiceReminderTest.php index fe9a05249..8a0e8fa0c 100644 --- a/tests/Feature/Commands/InvoiceReminderTest.php +++ b/tests/Feature/Commands/InvoiceReminderTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Commands; -use App\Models\Income\Invoice; +use App\Jobs\Income\CreateInvoice; use App\Notifications\Income\Invoice as InvoiceNotification; use Illuminate\Support\Facades\Notification; use Jenssegers\Date\Date; @@ -23,7 +23,7 @@ class InvoiceReminderTest extends FeatureTestCase { Notification::fake(); - $invoice = Invoice::create($this->getInvoiceRequest()); + $invoice = $this->dispatch(new CreateInvoice($this->getInvoiceRequest())); Date::setTestNow(Date::now()->addDay($this->addDay)); @@ -39,12 +39,11 @@ class InvoiceReminderTest extends FeatureTestCase } /** - * Copied in InvoicesTest + * Invoice request * - * @param int $recurring * @return array */ - private function getInvoiceRequest($recurring = 0) + private function getInvoiceRequest() { $amount = $this->faker->randomFloat(2, 2); @@ -58,7 +57,7 @@ class InvoiceReminderTest extends FeatureTestCase 'order_number' => '1', 'currency_code' => setting('default.currency'), 'currency_rate' => '1', - 'item' => $items, + 'items' => $items, 'discount' => '0', 'notes' => $this->faker->text(5), 'category_id' => $this->company->categories()->type('income')->first()->id, @@ -73,13 +72,6 @@ class InvoiceReminderTest extends FeatureTestCase 'company_id' => $this->company->id, ]; - if ($recurring) { - $data['recurring_frequency'] = 'yes'; - $data['recurring_interval'] = '1'; - $data['recurring_custom_frequency'] = $this->faker->randomElement(['monthly', 'weekly']); - $data['recurring_count'] = '1'; - } - return $data; } } diff --git a/tests/Feature/Common/DashboardTest.php b/tests/Feature/Common/DashboardTest.php index 698b8567e..aa5bc4436 100644 --- a/tests/Feature/Common/DashboardTest.php +++ b/tests/Feature/Common/DashboardTest.php @@ -9,7 +9,7 @@ class DashboardTest extends FeatureTestCase public function testItShouldSeeDashboard() { $this->loginAs() - ->get(url('/')) + ->get(route('dashboard')) ->assertStatus(200) ->assertSeeText(trans('general.dashboard')); } diff --git a/tests/Feature/Common/ItemsTest.php b/tests/Feature/Common/ItemsTest.php index 3e8f209a1..92bcd57af 100644 --- a/tests/Feature/Common/ItemsTest.php +++ b/tests/Feature/Common/ItemsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Common; -use App\Models\Common\Item; +use App\Jobs\Common\CreateItem; use Illuminate\Http\UploadedFile; use Tests\Feature\FeatureTestCase; @@ -35,7 +35,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldSeeItemUpdatePage() { - $item = Item::create($this->getItemRequest()); + $item = $this->dispatch(new CreateItem($this->getItemRequest())); $this->loginAs() ->get(route('items.edit', ['item' => $item->id])) @@ -47,7 +47,7 @@ class ItemsTest extends FeatureTestCase { $request = $this->getItemRequest(); - $item = Item::create($request); + $item = $this->dispatch(new CreateItem($request)); $request['name'] = $this->faker->text(15); @@ -60,7 +60,7 @@ class ItemsTest extends FeatureTestCase public function testItShouldDeleteItem() { - $item = Item::create($this->getItemRequest()); + $item = $this->dispatch(new CreateItem($this->getItemRequest())); $this->loginAs() ->delete(route('items.destroy', ['item' => $item])) @@ -80,7 +80,7 @@ class ItemsTest extends FeatureTestCase 'description' => $this->faker->text(100), 'purchase_price' => $this->faker->randomFloat(2, 10, 20), 'sale_price' => $this->faker->randomFloat(2, 10, 20), - 'category_id' => $this->company->categories()->type('item')->first()->id, + 'category_id' => $this->company->categories()->type('item')->pluck('id')->first(), 'tax_id' => '', 'enabled' => $this->faker->boolean ? 1 : 0 ]; diff --git a/tests/Feature/Expenses/BillsTest.php b/tests/Feature/Expenses/BillsTest.php index 6f8314889..381011710 100644 --- a/tests/Feature/Expenses/BillsTest.php +++ b/tests/Feature/Expenses/BillsTest.php @@ -35,7 +35,7 @@ class BillsTest extends FeatureTestCase public function testItShouldCreateBillWithRecurring() { $this->loginAs() - ->post(route('bills.store'), $this->getBillRequest(1)) + ->post(route('bills.store'), $this->getBillRequest(true)) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -43,7 +43,7 @@ class BillsTest extends FeatureTestCase public function testItShouldSeeBillUpdatePage() { - $bill = dispatch_now(new CreateBill($this->getBillRequest())); + $bill = $this->dispatch(new CreateBill($this->getBillRequest())); $this->loginAs() ->get(route('bills.edit', ['bill' => $bill->id])) @@ -54,35 +54,35 @@ class BillsTest extends FeatureTestCase public function testItShouldUpdateBill() { - $bill = dispatch_now(new CreateBill($this->getBillRequest())); + $request = $this->getBillRequest(); + + $bill = $this->dispatch(new CreateBill($request)); $request['contact_name'] = $this->faker->name; $this->loginAs() ->patch(route('bills.update', $bill->id), $request) - ->assertStatus(302); + ->assertStatus(200); $this->assertFlashLevel('success'); } public function testItShouldDeleteBill() { - $bill = dispatch_now(new CreateBill($this->getBillRequest())); + $bill = $this->dispatch(new CreateBill($this->getBillRequest())); $this->loginAs() ->delete(route('bills.destroy', $bill->id)) - ->assertStatus(302) - ->assertRedirect(route('bills.index')); + ->assertStatus(200); $this->assertFlashLevel('success'); - } - private function getBillRequest($recurring = 0) + private function getBillRequest($recurring = false) { $amount = $this->faker->randomFloat(2, 2); - $items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD', 'tax_id' => null]]; + $items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD', 'tax_id' => null]]; $data = [ 'company_id' => $this->company->id, @@ -95,7 +95,7 @@ class BillsTest extends FeatureTestCase 'items' => $items, 'discount' => '0', 'notes' => $this->faker->text(5), - 'category_id' => $this->company->categories()->type('expense')->first()->id, + 'category_id' => $this->company->categories()->type('expense')->pluck('id')->first(), 'recurring_frequency' => 'no', 'contact_id' => '0', 'contact_name' => $this->faker->name, diff --git a/tests/Feature/Expenses/PaymentsTest.php b/tests/Feature/Expenses/PaymentsTest.php index 979823a0c..2c8fec124 100644 --- a/tests/Feature/Expenses/PaymentsTest.php +++ b/tests/Feature/Expenses/PaymentsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Expenses; -use App\Models\Banking\Transaction; +use App\Jobs\Banking\CreateTransaction; use Illuminate\Http\UploadedFile; use Tests\Feature\FeatureTestCase; @@ -37,7 +37,7 @@ class PaymentsTest extends FeatureTestCase { $request = $this->getPaymentRequest(); - $payment = Transaction::create($request); + $payment = $this->dispatch(new CreateTransaction($request)); $request['name'] = $this->faker->text(15); @@ -50,7 +50,7 @@ class PaymentsTest extends FeatureTestCase public function testItShouldDeletePayment() { - $payment = Transaction::create($this->getPaymentRequest()); + $payment = $this->dispatch(new CreateTransaction($this->getPaymentRequest())); $this->loginAs() ->delete(route('payments.destroy', $payment->id)) diff --git a/tests/Feature/Expenses/VendorsTest.php b/tests/Feature/Expenses/VendorsTest.php index 0f4bc0a4a..a577c13a9 100644 --- a/tests/Feature/Expenses/VendorsTest.php +++ b/tests/Feature/Expenses/VendorsTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Expenses; -use App\Models\Common\Contact; +use App\Jobs\Common\CreateContact; use Tests\Feature\FeatureTestCase; class VendorsTest extends FeatureTestCase @@ -34,7 +34,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldSeeVendorDetailPage() { - $vendor = Contact::create($this->getVendorRequest()); + $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); $this->loginAs() ->get(route('vendors.show', ['vendor' => $vendor->id])) @@ -44,7 +44,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldSeeVendorUpdatePage() { - $vendor = Contact::create($this->getVendorRequest()); + $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); $this->loginAs() ->get(route('vendors.edit', ['vendor' => $vendor->id])) @@ -57,7 +57,7 @@ class VendorsTest extends FeatureTestCase { $request = $this->getVendorRequest(); - $vendor = Contact::create($request); + $vendor = $this->dispatch(new CreateContact($request)); $request['name'] = $this->faker->name; @@ -70,7 +70,7 @@ class VendorsTest extends FeatureTestCase public function testItShouldDeleteVendor() { - $vendor = Contact::create($this->getVendorRequest()); + $vendor = $this->dispatch(new CreateContact($this->getVendorRequest())); $this->loginAs() ->delete(route('vendors.destroy', $vendor->id)) diff --git a/tests/Feature/FeatureTestCase.php b/tests/Feature/FeatureTestCase.php index 43d29aa93..81d877f65 100644 --- a/tests/Feature/FeatureTestCase.php +++ b/tests/Feature/FeatureTestCase.php @@ -26,7 +26,7 @@ abstract class FeatureTestCase extends TestCase $this->faker = Factory::create(); $this->user = User::first(); - $this->company = $this->user->first()->companies()->first(); + $this->company = $this->user->companies()->first(); // Set Company settings setting()->forgetAll(); @@ -48,7 +48,7 @@ abstract class FeatureTestCase extends TestCase } if (!$company) { - $company = $user->companies()->first(); + $company = $this->company; } $this->startSession(); diff --git a/tests/Feature/Incomes/CustomersTest.php b/tests/Feature/Incomes/CustomersTest.php index d559f865f..5fb2098bb 100644 --- a/tests/Feature/Incomes/CustomersTest.php +++ b/tests/Feature/Incomes/CustomersTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Incomes; +use App\Jobs\Common\CreateContact; use App\Models\Auth\User; -use App\Models\Common\Contact; use Tests\Feature\FeatureTestCase; class CustomersTest extends FeatureTestCase @@ -62,7 +62,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldSeeCustomerDetailPage() { - $customer = Contact::create($this->getCustomerRequest()); + $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); $this->loginAs() ->get(route('customers.show', ['customer' => $customer->id])) @@ -72,7 +72,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldSeeCustomerUpdatePage() { - $customer = Contact::create($this->getCustomerRequest()); + $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); $this->loginAs() ->get(route('customers.edit', ['customer' => $customer->id])) @@ -85,7 +85,7 @@ class CustomersTest extends FeatureTestCase { $request = $this->getCustomerRequest(); - $customer = Contact::create($request); + $customer = $this->dispatch(new CreateContact($request)); $request['name'] = $this->faker->name; @@ -98,7 +98,7 @@ class CustomersTest extends FeatureTestCase public function testItShouldDeleteCustomer() { - $customer = Contact::create($this->getCustomerRequest()); + $customer = $this->dispatch(new CreateContact($this->getCustomerRequest())); $this->loginAs() ->delete(route('customers.destroy', $customer->id)) @@ -135,10 +135,10 @@ class CustomersTest extends FeatureTestCase $password = $this->faker->password; return $this->getCustomerRequest() + [ - 'create_user' => 1, - 'locale' => 'en-GB', - 'password' => $password, - 'password_confirmation' => $password - ]; + 'create_user' => 1, + 'locale' => 'en-GB', + 'password' => $password, + 'password_confirmation' => $password + ]; } } diff --git a/tests/Feature/Incomes/InvoicesTest.php b/tests/Feature/Incomes/InvoicesTest.php index 1fda02356..12718cd74 100644 --- a/tests/Feature/Incomes/InvoicesTest.php +++ b/tests/Feature/Incomes/InvoicesTest.php @@ -20,7 +20,7 @@ class InvoicesTest extends FeatureTestCase $this->loginAs() ->get(route('invoices.create')) ->assertStatus(200) - ->assertSeeText(trans( trans_choice('general.invoices', 1))); + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.invoices', 1)])); } public function testItShouldCreateInvoice() @@ -35,7 +35,7 @@ class InvoicesTest extends FeatureTestCase public function testItShouldCreateInvoiceWithRecurring() { $this->loginAs() - ->post(route('invoices.store'), $this->getInvoiceRequest(1)) + ->post(route('invoices.store'), $this->getInvoiceRequest(true)) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -43,7 +43,7 @@ class InvoicesTest extends FeatureTestCase public function testItShouldSeeInvoiceUpdatePage() { - $invoice = dispatch_now(new CreateInvoice($this->getInvoiceRequest())); + $invoice = $this->dispatch(new CreateInvoice($this->getInvoiceRequest())); $this->loginAs() ->get(route('invoices.edit', ['invoice' => $invoice->id])) @@ -54,7 +54,9 @@ class InvoicesTest extends FeatureTestCase public function testItShouldUpdateInvoice() { - $invoice = dispatch_now(new CreateInvoice($this->getInvoiceRequest())); + $request = $this->getInvoiceRequest(); + + $invoice = $this->dispatch(new CreateInvoice($request)); $request['contact_name'] = $this->faker->name; @@ -67,7 +69,7 @@ class InvoicesTest extends FeatureTestCase public function testItShouldDeleteInvoice() { - $invoice = dispatch_now(new CreateInvoice($this->getInvoiceRequest())); + $invoice = $this->dispatch(new CreateInvoice($this->getInvoiceRequest())); $this->loginAs() ->delete(route('invoices.destroy', $invoice->id)) @@ -76,11 +78,11 @@ class InvoicesTest extends FeatureTestCase $this->assertFlashLevel('success'); } - private function getInvoiceRequest($recurring = 0) + private function getInvoiceRequest($recurring = false) { $amount = $this->faker->randomFloat(2, 2); - $items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD']]; + $items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD']]; $data = [ 'company_id' => $this->company->id, @@ -93,7 +95,7 @@ class InvoicesTest extends FeatureTestCase 'items' => $items, 'discount' => '0', 'notes' => $this->faker->text(5), - 'category_id' => $this->company->categories()->type('income')->first()->id, + 'category_id' => $this->company->categories()->type('income')->pluck('id')->first(), 'recurring_frequency' => 'no', 'contact_id' => '0', 'contact_name' => $this->faker->name, diff --git a/tests/Feature/Incomes/RevenuesTest.php b/tests/Feature/Incomes/RevenuesTest.php index 00c4b4c65..b39fb2fc0 100644 --- a/tests/Feature/Incomes/RevenuesTest.php +++ b/tests/Feature/Incomes/RevenuesTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Incomes; -use App\Models\Banking\Transaction; +use App\Jobs\Banking\CreateTransaction; use Illuminate\Http\UploadedFile; use Tests\Feature\FeatureTestCase; @@ -37,7 +37,7 @@ class RevenuesTest extends FeatureTestCase { $request = $this->getRevenueRequest(); - $revenue = Transaction::create($request); + $revenue = $this->dispatch(new CreateTransaction($request)); $request['name'] = $this->faker->text(15); @@ -50,7 +50,7 @@ class RevenuesTest extends FeatureTestCase public function testItShouldDeleteRevenue() { - $revenue = Transaction::create($this->getRevenueRequest()); + $revenue = $this->dispatch(new CreateTransaction($this->getRevenueRequest())); $this->loginAs() ->delete(route('revenues.destroy', $revenue->id)) diff --git a/tests/Feature/Settings/CategoriesTest.php b/tests/Feature/Settings/CategoriesTest.php index eaac34f00..98360c1f1 100644 --- a/tests/Feature/Settings/CategoriesTest.php +++ b/tests/Feature/Settings/CategoriesTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Settings; -use App\Models\Setting\Category; +use App\Jobs\Setting\CreateCategory; use Tests\Feature\FeatureTestCase; class CategoriesTest extends FeatureTestCase @@ -34,7 +34,7 @@ class CategoriesTest extends FeatureTestCase public function testItShouldSeeCategoryUpdatePage() { - $category = Category::create($this->getCategoryRequest()); + $category = $this->dispatch(new CreateCategory($this->getCategoryRequest())); $this->loginAs() ->get(route('categories.edit', ['category' => $category->id])) @@ -46,7 +46,7 @@ class CategoriesTest extends FeatureTestCase { $request = $this->getCategoryRequest(); - $category = Category::create($request); + $category = $this->dispatch(new CreateCategory($request)); $request['name'] = $this->faker->text(15); @@ -59,7 +59,7 @@ class CategoriesTest extends FeatureTestCase public function testItShouldDeleteCategory() { - $category = Category::create($this->getCategoryRequest()); + $category = $this->dispatch(new CreateCategory($this->getCategoryRequest())); $this->loginAs() ->delete(route('categories.destroy', $category->id)) @@ -73,7 +73,7 @@ class CategoriesTest extends FeatureTestCase return [ 'company_id' => $this->company->id, 'name' => $this->faker->text(15), - 'type' => 'other', + 'type' => 'item', 'color' => $this->faker->text(15), 'enabled' => $this->faker->boolean ? 1 : 0 ]; diff --git a/tests/Feature/Settings/CurrenciesTest.php b/tests/Feature/Settings/CurrenciesTest.php index ab5ae6a19..bd5619e11 100644 --- a/tests/Feature/Settings/CurrenciesTest.php +++ b/tests/Feature/Settings/CurrenciesTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Settings; -use App\Models\Setting\Currency; +use App\Jobs\Setting\CreateCurrency; use Tests\Feature\FeatureTestCase; class CurrenciesTest extends FeatureTestCase @@ -36,7 +36,7 @@ class CurrenciesTest extends FeatureTestCase { $request = $this->getCurrencyRequest(); - $currency = Currency::create($request); + $currency = $this->dispatch(new CreateCurrency($request)); $request['name'] = $this->faker->text(15); @@ -49,7 +49,7 @@ class CurrenciesTest extends FeatureTestCase public function testItShouldDeleteCurrency() { - $currency = Currency::create($this->getCurrencyRequest()); + $currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest())); $this->loginAs() ->delete(route('currencies.destroy', $currency->id)) diff --git a/tests/Feature/Settings/TaxesTest.php b/tests/Feature/Settings/TaxesTest.php index f6d073db5..4cdb8ea17 100644 --- a/tests/Feature/Settings/TaxesTest.php +++ b/tests/Feature/Settings/TaxesTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Settings; -use App\Models\Setting\Tax; +use App\Jobs\Setting\CreateTax; use Tests\Feature\FeatureTestCase; class TaxesTest extends FeatureTestCase @@ -36,7 +36,7 @@ class TaxesTest extends FeatureTestCase { $request = $this->getTaxRequest(); - $tax = Tax::create($request); + $tax = $this->dispatch(new CreateTax($request)); $request['name'] = $this->faker->text(15); @@ -49,7 +49,7 @@ class TaxesTest extends FeatureTestCase public function testItShouldDeleteTax() { - $tax = Tax::create($this->getTaxRequest()); + $tax = $this->dispatch(new CreateTax($this->getTaxRequest())); $this->loginAs() ->delete(route('taxes.destroy', $tax->id)) diff --git a/tests/TestCase.php b/tests/TestCase.php index 519a244b3..8ef0a3305 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use App\Traits\Jobs; use Artisan; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -9,7 +10,7 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { - use CreatesApplication, DatabaseMigrations; + use CreatesApplication, DatabaseMigrations, Jobs; protected function setUp(): void {