akaunting/tests/Feature/Purchases/PaymentsTest.php

78 lines
2.0 KiB
PHP
Raw Normal View History

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