2018-11-07 11:42:25 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Banking;
|
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
use App\Jobs\Banking\CreateTransaction;
|
2019-11-18 10:54:26 +03:00
|
|
|
use App\Models\Banking\Transfer;
|
2018-11-07 11:42:25 +03:00
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2019-11-18 10:54:26 +03:00
|
|
|
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2019-11-16 10:21:14 +03:00
|
|
|
->post(route('transfers.store'), $this->getTransferRequest($income_transaction, $expense_transaction))
|
|
|
|
->assertStatus(200);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeeTransferUpdatePage()
|
|
|
|
{
|
2019-11-18 10:54:26 +03:00
|
|
|
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('transfers.edit', ['transfer' => $transfer->id]))
|
|
|
|
->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
|
|
|
{
|
2019-11-18 10:54:26 +03:00
|
|
|
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$request = $this->getTransferRequest($income_transaction, $expense_transaction);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$transfer = Transfer::create($request);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
$request['description'] = $this->faker->text(10);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2019-11-16 10:21:14 +03:00
|
|
|
->patch(route('transfers.update', ['transfer' => $transfer->id]), $request)
|
|
|
|
->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
|
|
|
{
|
2019-11-18 10:54:26 +03:00
|
|
|
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2019-11-16 10:21:14 +03:00
|
|
|
->delete(route('transfers.destroy', ['transfer' => $transfer->id]))
|
|
|
|
->assertStatus(200);
|
2018-11-07 11:42:25 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
private function getTransferRequest($income_transaction, $expense_transaction)
|
2018-11-07 11:42:25 +03:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'company_id' => $this->company->id,
|
2019-11-16 10:21:14 +03:00
|
|
|
'income_transaction_id' => $income_transaction->id,
|
|
|
|
'expense_transaction_id' => $expense_transaction->id,
|
2018-11-07 11:42:25 +03:00
|
|
|
'from_account_id' => '1',
|
|
|
|
'to_account_id' => '2',
|
|
|
|
'amount' => '5',
|
|
|
|
'transferred_at' => $this->faker->date(),
|
|
|
|
'description'=> $this->faker->text(5),
|
|
|
|
'payment_method' => 'offlinepayment.cash.1',
|
|
|
|
'reference' => null,
|
2019-11-16 10:21:14 +03:00
|
|
|
'currency_code' => setting('default.currency'),
|
2019-04-02 18:51:06 +03:00
|
|
|
'currency_rate' => '1'
|
2018-11-07 11:42:25 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
private function getTransactionRequest($type)
|
2018-11-07 11:42:25 +03:00
|
|
|
{
|
|
|
|
$attachment = UploadedFile::fake()->create('image.jpg');
|
|
|
|
|
|
|
|
return [
|
|
|
|
'company_id' => $this->company->id,
|
2019-11-18 10:54:26 +03:00
|
|
|
'type' => $type,
|
2019-11-16 10:21:14 +03:00
|
|
|
'account_id' => setting('default.account'),
|
2018-11-07 11:42:25 +03:00
|
|
|
'paid_at' => $this->faker->date(),
|
|
|
|
'amount' => $this->faker->randomFloat(2, 2),
|
2019-11-16 10:21:14 +03:00
|
|
|
'currency_code' => setting('default.currency'),
|
2018-11-07 11:42:25 +03:00
|
|
|
'currency_rate' => '1',
|
|
|
|
'description' => $this->faker->text(5),
|
2019-11-18 10:54:26 +03:00
|
|
|
'category_id' => $this->company->categories()->type($type)->first()->id,
|
2018-11-07 11:42:25 +03:00
|
|
|
'reference' => $this->faker->text(5),
|
2019-11-16 10:21:14 +03:00
|
|
|
'payment_method' => setting('default.payment_method'),
|
2019-11-18 10:54:26 +03:00
|
|
|
'attachment' => $attachment,
|
2018-11-07 11:42:25 +03:00
|
|
|
];
|
|
|
|
}
|
2019-04-02 18:51:06 +03:00
|
|
|
}
|