Akaunting/tests/Feature/Purchases/PaymentsTest.php

90 lines
2.3 KiB
PHP
Raw Normal View History

2018-10-09 11:18:12 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace Tests\Feature\Purchases;
2018-10-09 11:18:12 +00:00
2019-11-17 12:06:00 +00:00
use App\Jobs\Banking\CreateTransaction;
2019-12-16 10:19:09 +00:00
use App\Models\Banking\Transaction;
2018-10-09 11:18:12 +00:00
use Tests\Feature\FeatureTestCase;
class PaymentsTest extends FeatureTestCase
{
public function testItShouldSeePaymentListPage()
{
$this->loginAs()
2019-11-16 07:21:14 +00:00
->get(route('payments.index'))
2018-10-09 11:18:12 +00:00
->assertStatus(200)
->assertSeeText(trans_choice('general.payments', 2));
}
public function testItShouldSeePaymentCreatePage()
{
$this->loginAs()
2019-11-16 07:21:14 +00:00
->get(route('payments.create'))
2018-10-09 11:18:12 +00:00
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.payments', 1)]));
}
public function testItShouldCreatePayment()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
2018-10-09 11:18:12 +00:00
$this->loginAs()
2020-07-25 14:22:50 +00:00
->post(route('payments.store'), $request)
2019-11-16 07:21:14 +00:00
->assertStatus(200);
2018-10-09 11:18:12 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
$this->assertDatabaseHas('transactions', $request);
2018-10-09 11:18:12 +00:00
}
2020-01-13 07:55:19 +00:00
public function testItShouldSeePaymentUpdatePage()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
$payment = $this->dispatch(new CreateTransaction($request));
2020-01-13 07:55:19 +00:00
$this->loginAs()
->get(route('payments.edit', $payment->id))
->assertStatus(200)
->assertSee($payment->amount);
}
2018-10-09 11:18:12 +00:00
public function testItShouldUpdatePayment()
{
2020-01-06 22:28:05 +00:00
$request = $this->getRequest();
2018-10-09 11:18:12 +00:00
2019-11-17 12:06:00 +00:00
$payment = $this->dispatch(new CreateTransaction($request));
2018-10-09 11:18:12 +00:00
2020-01-13 14:20:28 +00:00
$request['amount'] = $this->faker->randomFloat(2, 1, 1000);
2018-10-09 11:18:12 +00:00
$this->loginAs()
2019-11-16 07:21:14 +00:00
->patch(route('payments.update', $payment->id), $request)
2020-01-13 14:20:28 +00:00
->assertStatus(200)
->assertSee($request['amount']);
2018-10-09 11:18:12 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
$this->assertDatabaseHas('transactions', $request);
2018-10-09 11:18:12 +00:00
}
public function testItShouldDeletePayment()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
$payment = $this->dispatch(new CreateTransaction($request));
2018-10-09 11:18:12 +00:00
$this->loginAs()
2019-11-16 07:21:14 +00:00
->delete(route('payments.destroy', $payment->id))
->assertStatus(200);
2018-10-09 11:18:12 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
$this->assertSoftDeleted('transactions', $request);
2018-10-09 11:18:12 +00:00
}
2020-01-06 22:28:05 +00:00
public function getRequest()
{
2020-10-14 14:07:59 +00:00
return Transaction::factory()->expense()->raw();
2020-01-06 22:28:05 +00:00
}
2019-04-02 15:51:06 +00:00
}