diff --git a/app/Http/Middleware/DateFormat.php b/app/Http/Middleware/DateFormat.php index df0676bd6..27d342193 100644 --- a/app/Http/Middleware/DateFormat.php +++ b/app/Http/Middleware/DateFormat.php @@ -26,7 +26,11 @@ class DateFormat continue; } - $new_date = Date::parse($date)->format('Y-m-d') . ' ' . Date::now()->format('H:i:s'); + if (Date::parse($date)->format('H:i:s') == '00:00:00') { + $new_date = Date::parse($date)->format('Y-m-d') . ' ' . Date::now()->format('H:i:s'); + } else { + $new_date = Date::parse($date)->toDateTimeString(); + } $request->request->set($field, $new_date); } diff --git a/database/factories/Bill.php b/database/factories/Bill.php index 3392bdee7..968455fc8 100644 --- a/database/factories/Bill.php +++ b/database/factories/Bill.php @@ -20,8 +20,8 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) { session(['company_id' => $company->id]); setting()->setExtraColumns(['company_id' => $company->id]); - $billed_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'); - $due_at = Date::parse($billed_at)->addDays(10)->format('Y-m-d'); + $billed_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'); + $due_at = Date::parse($billed_at)->addDays(10)->format('Y-m-d H:i:s'); $contacts = Contact::vendor()->enabled()->get(); diff --git a/database/factories/Invoice.php b/database/factories/Invoice.php index 78e09ad33..38aaa1b17 100644 --- a/database/factories/Invoice.php +++ b/database/factories/Invoice.php @@ -21,8 +21,8 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) { session(['company_id' => $company->id]); setting()->setExtraColumns(['company_id' => $company->id]); - $invoiced_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'); - $due_at = Date::parse($invoiced_at)->addDays(setting('invoice.payment_terms'))->format('Y-m-d'); + $invoiced_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'); + $due_at = Date::parse($invoiced_at)->addDays(setting('invoice.payment_terms'))->format('Y-m-d H:i:s'); $contacts = Contact::customer()->enabled()->get(); diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php index 2bdc0c6ff..d0b6e3bcc 100644 --- a/database/factories/Transaction.php +++ b/database/factories/Transaction.php @@ -17,10 +17,10 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) { 'company_id' => $company->id, 'type' => $type, 'account_id' => setting('default.account'), - 'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'), + 'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'), 'amount' => $faker->randomFloat(2, 1, 1000), 'currency_code' => setting('default.currency'), - 'currency_rate' => '1', + 'currency_rate' => '1.0', 'description' => $faker->text(5), 'category_id' => $company->categories()->type($type)->get()->random(1)->pluck('id')->first(), 'reference' => $faker->text(5), diff --git a/tests/Feature/Purchases/BillsTest.php b/tests/Feature/Purchases/BillsTest.php index 51abdab5f..69c7199b4 100644 --- a/tests/Feature/Purchases/BillsTest.php +++ b/tests/Feature/Purchases/BillsTest.php @@ -26,25 +26,39 @@ class BillsTest extends FeatureTestCase public function testItShouldCreateBill() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('bills.store'), $this->getRequest()) + ->post(route('bills.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('bills', [ + 'bill_number' => $request['bill_number'], + ]); } public function testItShouldCreateBillWithRecurring() { + $request = $this->getRequest(true); + $this->loginAs() - ->post(route('bills.store'), $this->getRequest(true)) + ->post(route('bills.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('bills', [ + 'bill_number' => $request['bill_number'], + ]); } public function testItShouldSeeBillUpdatePage() { - $bill = $this->dispatch(new CreateBill($this->getRequest())); + $request = $this->getRequest(); + + $bill = $this->dispatch(new CreateBill($request)); $this->loginAs() ->get(route('bills.edit', $bill->id)) @@ -66,17 +80,28 @@ class BillsTest extends FeatureTestCase ->assertSee($request['contact_email']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('bills', [ + 'bill_number' => $request['bill_number'], + 'contact_email' => $request['contact_email'], + ]); } public function testItShouldDeleteBill() { - $bill = $this->dispatch(new CreateBill($this->getRequest())); + $request = $this->getRequest(); + + $bill = $this->dispatch(new CreateBill($request)); $this->loginAs() ->delete(route('bills.destroy', $bill->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('bills', [ + 'bill_number' => $request['bill_number'], + ]); } public function getRequest($recurring = false) diff --git a/tests/Feature/Purchases/PaymentsTest.php b/tests/Feature/Purchases/PaymentsTest.php index 0a64b37ea..34b3cf8c8 100644 --- a/tests/Feature/Purchases/PaymentsTest.php +++ b/tests/Feature/Purchases/PaymentsTest.php @@ -26,16 +26,22 @@ class PaymentsTest extends FeatureTestCase public function testItShouldCreatePayment() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('payments.store'), $this->getRequest()) + ->post(route('payments.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('transactions', $request); } public function testItShouldSeePaymentUpdatePage() { - $payment = $this->dispatch(new CreateTransaction($this->getRequest())); + $request = $this->getRequest(); + + $payment = $this->dispatch(new CreateTransaction($request)); $this->loginAs() ->get(route('payments.edit', $payment->id)) @@ -57,17 +63,23 @@ class PaymentsTest extends FeatureTestCase ->assertSee($request['amount']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('transactions', $request); } public function testItShouldDeletePayment() { - $payment = $this->dispatch(new CreateTransaction($this->getRequest())); + $request = $this->getRequest(); + + $payment = $this->dispatch(new CreateTransaction($request)); $this->loginAs() ->delete(route('payments.destroy', $payment->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('transactions', $request); } public function getRequest() diff --git a/tests/Feature/Purchases/VendorsTest.php b/tests/Feature/Purchases/VendorsTest.php index f9bdebfc7..ef2c297c0 100644 --- a/tests/Feature/Purchases/VendorsTest.php +++ b/tests/Feature/Purchases/VendorsTest.php @@ -26,16 +26,22 @@ class VendorsTest extends FeatureTestCase public function testItShouldCreateVendor() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('vendors.store'), $this->getRequest()) + ->post(route('vendors.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('contacts', $request); } public function testItShouldSeeVendorDetailPage() { - $vendor = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $vendor = $this->dispatch(new CreateContact($request)); $this->loginAs() ->get(route('vendors.show', $vendor->id)) @@ -45,12 +51,16 @@ class VendorsTest extends FeatureTestCase public function testItShouldSeeVendorUpdatePage() { - $vendor = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $vendor = $this->dispatch(new CreateContact($request)); $this->loginAs() ->get(route('vendors.edit', $vendor->id)) ->assertStatus(200) ->assertSee($vendor->email); + + $this->assertDatabaseHas('contacts', $request); } public function testItShouldUpdateVendor() @@ -67,17 +77,23 @@ class VendorsTest extends FeatureTestCase ->assertSee($request['email']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('contacts', $request); } public function testItShouldDeleteVendor() { - $vendor = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $vendor = $this->dispatch(new CreateContact($request)); $this->loginAs() ->delete(route('vendors.destroy', $vendor->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('contacts', $request); } public function getRequest() diff --git a/tests/Feature/Sales/CustomersTest.php b/tests/Feature/Sales/CustomersTest.php index fa8f88816..38172d946 100644 --- a/tests/Feature/Sales/CustomersTest.php +++ b/tests/Feature/Sales/CustomersTest.php @@ -25,34 +25,40 @@ class CustomersTest extends FeatureTestCase ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.customers', 1)])); } - public function testItShouldCreateOnlyCustomerWithoutUser() + public function testItShouldCreateCustomer() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('customers.store'), $this->getRequest()) + ->post(route('customers.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('contacts', $request); } public function testItShouldCreateCustomerWithUser() { - $customer = $this->getRequestWithUser(); + $request = $this->getRequestWithUser(); $this->loginAs() - ->post(route('customers.store'), $customer) + ->post(route('customers.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); - $user = User::where('email', $customer['email'])->first(); + $user = User::where('email', $request['email'])->first(); $this->assertNotNull($user); - $this->assertEquals($customer['email'], $user->email); + $this->assertEquals($request['email'], $user->email); } public function testItShouldSeeCustomerDetailPage() { - $customer = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $customer = $this->dispatch(new CreateContact($request)); $this->loginAs() ->get(route('customers.show', $customer->id)) @@ -62,7 +68,9 @@ class CustomersTest extends FeatureTestCase public function testItShouldSeeCustomerUpdatePage() { - $customer = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $customer = $this->dispatch(new CreateContact($request)); $this->loginAs() ->get(route('customers.edit', $customer->id)) @@ -84,11 +92,15 @@ class CustomersTest extends FeatureTestCase ->assertSee($request['email']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('contacts', $request); } public function testItShouldDeleteCustomer() { - $customer = $this->dispatch(new CreateContact($this->getRequest())); + $request = $this->getRequest(); + + $customer = $this->dispatch(new CreateContact($request)); $this->loginAs() ->delete(route('customers.destroy', $customer->id)) @@ -96,6 +108,8 @@ class CustomersTest extends FeatureTestCase $this->assertFlashLevel('success'); + $this->assertSoftDeleted('contacts', $request); + } public function testItShouldNotDeleteCustomerIfHasRelations() diff --git a/tests/Feature/Sales/InvoicesTest.php b/tests/Feature/Sales/InvoicesTest.php index 5f34926e1..3997706d3 100644 --- a/tests/Feature/Sales/InvoicesTest.php +++ b/tests/Feature/Sales/InvoicesTest.php @@ -26,25 +26,39 @@ class InvoicesTest extends FeatureTestCase public function testItShouldCreateInvoice() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('invoices.store'), $this->getRequest()) + ->post(route('invoices.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('invoices', [ + 'invoice_number' => $request['invoice_number'], + ]); } public function testItShouldCreateInvoiceWithRecurring() { + $request = $this->getRequest(true); + $this->loginAs() - ->post(route('invoices.store'), $this->getRequest(true)) + ->post(route('invoices.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('invoices', [ + 'invoice_number' => $request['invoice_number'], + ]); } public function testItShouldSeeInvoiceUpdatePage() { - $invoice = $this->dispatch(new CreateInvoice($this->getRequest())); + $request = $this->getRequest(); + + $invoice = $this->dispatch(new CreateInvoice($request)); $this->loginAs() ->get(route('invoices.edit', $invoice->id)) @@ -66,17 +80,28 @@ class InvoicesTest extends FeatureTestCase ->assertSee($request['contact_email']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('invoices', [ + 'invoice_number' => $request['invoice_number'], + 'contact_email' => $request['contact_email'], + ]); } public function testItShouldDeleteInvoice() { - $invoice = $this->dispatch(new CreateInvoice($this->getRequest())); + $request = $this->getRequest(); + + $invoice = $this->dispatch(new CreateInvoice($request)); $this->loginAs() ->delete(route('invoices.destroy', $invoice->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('invoices', [ + 'invoice_number' => $request['invoice_number'], + ]); } public function getRequest($recurring = false) diff --git a/tests/Feature/Sales/RevenuesTest.php b/tests/Feature/Sales/RevenuesTest.php index 2c8d32c9c..147aeca6e 100644 --- a/tests/Feature/Sales/RevenuesTest.php +++ b/tests/Feature/Sales/RevenuesTest.php @@ -26,16 +26,22 @@ class RevenuesTest extends FeatureTestCase public function testItShouldCreateRevenue() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('revenues.store'), $this->getRequest()) + ->post(route('revenues.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('transactions', $request); } public function testItShouldSeeRevenueUpdatePage() { - $revenue = $this->dispatch(new CreateTransaction($this->getRequest())); + $request = $this->getRequest(); + + $revenue = $this->dispatch(new CreateTransaction($request)); $this->loginAs() ->get(route('revenues.edit', $revenue->id)) @@ -57,17 +63,23 @@ class RevenuesTest extends FeatureTestCase ->assertSee($request['amount']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('transactions', $request); } public function testItShouldDeleteRevenue() { - $revenue = $this->dispatch(new CreateTransaction($this->getRequest())); + $request = $this->getRequest(); + + $revenue = $this->dispatch(new CreateTransaction($request)); $this->loginAs() ->delete(route('revenues.destroy', $revenue->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('transactions', $request); } public function getRequest() diff --git a/tests/Feature/Settings/CategoriesTest.php b/tests/Feature/Settings/CategoriesTest.php index a905d7647..b7346e260 100644 --- a/tests/Feature/Settings/CategoriesTest.php +++ b/tests/Feature/Settings/CategoriesTest.php @@ -26,16 +26,22 @@ class CategoriesTest extends FeatureTestCase public function testItShouldCreateCategory() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('categories.store'), $this->getRequest()) + ->post(route('categories.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('categories', $request); } public function testItShouldSeeCategoryUpdatePage() { - $category = $this->dispatch(new CreateCategory($this->getRequest())); + $request = $this->getRequest(); + + $category = $this->dispatch(new CreateCategory($request)); $this->loginAs() ->get(route('categories.edit', $category->id)) @@ -57,17 +63,23 @@ class CategoriesTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('categories', $request); } public function testItShouldDeleteCategory() { - $category = $this->dispatch(new CreateCategory($this->getRequest())); + $request = $this->getRequest(); + + $category = $this->dispatch(new CreateCategory($request)); $this->loginAs() ->delete(route('categories.destroy', $category->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('categories', $request); } public function getRequest() diff --git a/tests/Feature/Settings/CurrenciesTest.php b/tests/Feature/Settings/CurrenciesTest.php index 5a88f8dc0..45ac0af97 100644 --- a/tests/Feature/Settings/CurrenciesTest.php +++ b/tests/Feature/Settings/CurrenciesTest.php @@ -26,16 +26,22 @@ class CurrenciesTest extends FeatureTestCase public function testItShouldCreateCurrency() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('currencies.store'), $this->getRequest()) + ->post(route('currencies.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('currencies', $request); } public function testItShouldSeeCurrencyUpdatePage() { - $currency = $this->dispatch(new CreateCurrency($this->getRequest())); + $request = $this->getRequest(); + + $currency = $this->dispatch(new CreateCurrency($request)); $this->loginAs() ->get(route('currencies.edit', $currency->id)) @@ -57,17 +63,23 @@ class CurrenciesTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('currencies', $request); } public function testItShouldDeleteCurrency() { - $currency = $this->dispatch(new CreateCurrency($this->getRequest())); + $request = $this->getRequest(); + + $currency = $this->dispatch(new CreateCurrency($request)); $this->loginAs() ->delete(route('currencies.destroy', $currency->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('currencies', $request); } public function getRequest() diff --git a/tests/Feature/Settings/TaxesTest.php b/tests/Feature/Settings/TaxesTest.php index fec81c8fc..319a56e69 100644 --- a/tests/Feature/Settings/TaxesTest.php +++ b/tests/Feature/Settings/TaxesTest.php @@ -26,16 +26,22 @@ class TaxesTest extends FeatureTestCase public function testItShouldCreateTax() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('taxes.store'), $this->getRequest()) + ->post(route('taxes.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function testItShouldSeeTaxUpdatePage() { - $tax = $this->dispatch(new CreateTax($this->getRequest())); + $request = $this->getRequest(); + + $tax = $this->dispatch(new CreateTax($request)); $this->loginAs() ->get(route('taxes.edit', $tax->id)) @@ -57,17 +63,23 @@ class TaxesTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function testItShouldDeleteTax() { - $tax = $this->dispatch(new CreateTax($this->getRequest())); + $request = $this->getRequest(); + + $tax = $this->dispatch(new CreateTax($request)); $this->loginAs() ->delete(route('taxes.destroy', $tax->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function getRequest() diff --git a/tests/Feature/Wizard/CurrenciesTest.php b/tests/Feature/Wizard/CurrenciesTest.php index 8f12337c8..2214e5d4a 100644 --- a/tests/Feature/Wizard/CurrenciesTest.php +++ b/tests/Feature/Wizard/CurrenciesTest.php @@ -17,11 +17,15 @@ class CurrenciesTest extends FeatureTestCase public function testItShouldCreateCurrency() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('wizard.currencies.store'), $this->getRequest()) + ->post(route('wizard.currencies.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('currencies', $request); } public function testItShouldUpdateCurrency() @@ -37,17 +41,23 @@ class CurrenciesTest extends FeatureTestCase ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('currencies', $request); } public function testItShouldDeleteCurrency() { - $currency = $this->dispatch(new CreateCurrency($this->getRequest())); + $request = $this->getRequest(); + + $currency = $this->dispatch(new CreateCurrency($request)); $this->loginAs() ->delete(route('wizard.currencies.destroy', $currency->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('currencies', $request); } public function getRequest() diff --git a/tests/Feature/Wizard/TaxesTest.php b/tests/Feature/Wizard/TaxesTest.php index 4ea5afc7e..ab8fabf7a 100644 --- a/tests/Feature/Wizard/TaxesTest.php +++ b/tests/Feature/Wizard/TaxesTest.php @@ -17,11 +17,15 @@ class TaxesTest extends FeatureTestCase public function testItShouldCreateTax() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('wizard.taxes.store'), $this->getRequest()) + ->post(route('wizard.taxes.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function testItShouldUpdateTax() @@ -37,17 +41,23 @@ class TaxesTest extends FeatureTestCase ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function testItShouldDeleteTax() { - $tax = $this->dispatch(new CreateTax($this->getRequest())); + $request = $this->getRequest(); + + $tax = $this->dispatch(new CreateTax($request)); $this->loginAs() ->delete(route('wizard.taxes.destroy', $tax->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('taxes', $request); } public function getRequest()