2018-11-07 11:42:25 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Banking;
|
|
|
|
|
2020-01-07 09:29:45 +03:00
|
|
|
use App\Models\Banking\Account;
|
2018-11-07 11:42:25 +03:00
|
|
|
use Tests\Feature\FeatureTestCase;
|
2020-01-07 09:29:45 +03:00
|
|
|
use App\Jobs\Banking\CreateTransfer;
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
class TransfersTest extends FeatureTestCase
|
|
|
|
{
|
|
|
|
public function testItShouldSeeTransferListPage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('transfers.index'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans_choice('general.transfers', 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeeTransferCreatePage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('transfers.create'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.transfers', 1)]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldCreateTransfer()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
2020-01-06 16:37:32 +03:00
|
|
|
->post(route('transfers.store'), $this->getRequest())
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeeTransferUpdatePage()
|
|
|
|
{
|
2020-01-07 09:29:45 +03:00
|
|
|
$transfer = $this->dispatch(new CreateTransfer($this->getRequest()));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->get(route('transfers.edit', $transfer->id))
|
2018-11-07 11:42:25 +03:00
|
|
|
->assertStatus(200)
|
2019-11-18 10:54:26 +03:00
|
|
|
->assertSee($transfer->description);
|
2018-11-07 11:42:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
public function testItShouldUpdateTransfer()
|
2018-11-07 11:42:25 +03:00
|
|
|
{
|
2020-01-06 16:37:32 +03:00
|
|
|
$request = $this->getRequest();
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2020-01-07 09:29:45 +03:00
|
|
|
$transfer = $this->dispatch(new CreateTransfer($request));
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-01-14 01:05:32 +03:00
|
|
|
$request['description'] = $this->faker->text(15);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->patch(route('transfers.update', $transfer->id), $request)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
public function testItShouldDeleteTransfer()
|
2018-11-07 11:42:25 +03:00
|
|
|
{
|
2020-01-07 09:29:45 +03:00
|
|
|
$transfer = $this->dispatch(new CreateTransfer($this->getRequest()));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->delete(route('transfers.destroy', $transfer->id))
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2020-01-07 01:28:05 +03:00
|
|
|
public function getRequest()
|
2018-11-07 11:42:25 +03:00
|
|
|
{
|
2020-01-07 17:53:57 +03:00
|
|
|
$from_account = factory(Account::class)->states('enabled', 'default_currency')->create();
|
2020-01-06 16:37:32 +03:00
|
|
|
|
2020-01-07 17:53:57 +03:00
|
|
|
$to_account = factory(Account::class)->states('enabled', 'default_currency')->create();
|
2020-01-06 16:37:32 +03:00
|
|
|
|
2018-11-07 11:42:25 +03:00
|
|
|
return [
|
|
|
|
'company_id' => $this->company->id,
|
2020-01-07 09:29:45 +03:00
|
|
|
'from_account_id' => $from_account->id,
|
|
|
|
'to_account_id' => $to_account->id,
|
2020-01-14 01:05:32 +03:00
|
|
|
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
2018-11-07 11:42:25 +03:00
|
|
|
'transferred_at' => $this->faker->date(),
|
2020-01-14 01:05:32 +03:00
|
|
|
'description'=> $this->faker->text(20),
|
2019-11-16 10:21:14 +03:00
|
|
|
'payment_method' => setting('default.payment_method'),
|
2020-01-14 01:05:32 +03:00
|
|
|
'reference' => $this->faker->text(20),
|
2018-11-07 11:42:25 +03:00
|
|
|
];
|
|
|
|
}
|
2020-01-07 09:45:40 +03:00
|
|
|
}
|