Skip to content

Commit

Permalink
added more db asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jul 25, 2020
1 parent d8ea086 commit a3077d4
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 47 deletions.
6 changes: 5 additions & 1 deletion app/Http/Middleware/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public function handle($request, Closure $next)
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);
}
Expand Down
4 changes: 2 additions & 2 deletions database/factories/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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();

Expand Down
4 changes: 2 additions & 2 deletions database/factories/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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();

Expand Down
4 changes: 2 additions & 2 deletions database/factories/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
'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),
Expand Down
33 changes: 29 additions & 4 deletions tests/Feature/Purchases/BillsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,39 @@ public function testItShouldSeeBillCreatePage()

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))
Expand All @@ -66,17 +80,28 @@ public function testItShouldUpdateBill()
->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)
Expand Down
18 changes: 15 additions & 3 deletions tests/Feature/Purchases/PaymentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ public function testItShouldSeePaymentCreatePage()

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))
Expand All @@ -57,17 +63,23 @@ public function testItShouldUpdatePayment()
->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()
Expand Down
24 changes: 20 additions & 4 deletions tests/Feature/Purchases/VendorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ public function testItShouldSeeVendorCreatePage()

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))
Expand All @@ -45,12 +51,16 @@ public function testItShouldSeeVendorDetailPage()

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()
Expand All @@ -67,17 +77,23 @@ public function testItShouldUpdateVendor()
->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()
Expand Down
32 changes: 23 additions & 9 deletions tests/Feature/Sales/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,40 @@ public function testItShouldSeeCustomerCreatePage()
->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))
Expand All @@ -62,7 +68,9 @@ public function testItShouldSeeCustomerDetailPage()

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))
Expand All @@ -84,18 +92,24 @@ public function testItShouldUpdateCustomer()
->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))
->assertStatus(200);

$this->assertFlashLevel('success');

$this->assertSoftDeleted('contacts', $request);

}

public function testItShouldNotDeleteCustomerIfHasRelations()
Expand Down
33 changes: 29 additions & 4 deletions tests/Feature/Sales/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,39 @@ public function testItShouldSeeInvoiceCreatePage()

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))
Expand All @@ -66,17 +80,28 @@ public function testItShouldUpdateInvoice()
->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)
Expand Down
Loading

0 comments on commit a3077d4

Please sign in to comment.