fixed tests
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace Tests\Feature\Banking;
|
||||
|
||||
use App\Jobs\Banking\CreateTransaction;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class TransfersTest extends FeatureTestCase
|
||||
@@ -27,12 +26,8 @@ class TransfersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldCreateTransfer()
|
||||
{
|
||||
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
||||
|
||||
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
||||
|
||||
$this->loginAs()
|
||||
->post(route('transfers.store'), $this->getTransferRequest($income_transaction, $expense_transaction))
|
||||
->post(route('transfers.store'), $this->getRequest())
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
@@ -40,11 +35,7 @@ class TransfersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldSeeTransferUpdatePage()
|
||||
{
|
||||
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
||||
|
||||
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
||||
|
||||
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));
|
||||
$transfer = Transfer::create($this->getRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('transfers.edit', ['transfer' => $transfer->id]))
|
||||
@@ -54,11 +45,7 @@ class TransfersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldUpdateTransfer()
|
||||
{
|
||||
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
||||
|
||||
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
||||
|
||||
$request = $this->getTransferRequest($income_transaction, $expense_transaction);
|
||||
$request = $this->getRequest();
|
||||
|
||||
$transfer = Transfer::create($request);
|
||||
|
||||
@@ -73,11 +60,7 @@ class TransfersTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldDeleteTransfer()
|
||||
{
|
||||
$income_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('income')));
|
||||
|
||||
$expense_transaction = $this->dispatch(new CreateTransaction($this->getTransactionRequest('expense')));
|
||||
|
||||
$transfer = Transfer::create($this->getTransferRequest($income_transaction, $expense_transaction));
|
||||
$transfer = Transfer::create($this->getRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('transfers.destroy', ['transfer' => $transfer->id]))
|
||||
@@ -86,41 +69,23 @@ class TransfersTest extends FeatureTestCase
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getTransferRequest($income_transaction, $expense_transaction)
|
||||
private function getRequest()
|
||||
{
|
||||
$income_transaction = factory(Transaction::class)->create();
|
||||
|
||||
$expense_transaction = factory(Transaction::class)->state('expense')->create();
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'from_account_id' => '1',
|
||||
'to_account_id' => '2',
|
||||
'from_account_id' => $income_transaction->account_id,
|
||||
'to_account_id' => $expense_transaction->account_id,
|
||||
'amount' => '5',
|
||||
'transferred_at' => $this->faker->date(),
|
||||
'description'=> $this->faker->text(5),
|
||||
'payment_method' => 'offlinepayment.cash.1',
|
||||
'reference' => null,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_rate' => '1'
|
||||
];
|
||||
}
|
||||
|
||||
private function getTransactionRequest($type)
|
||||
{
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'type' => $type,
|
||||
'account_id' => setting('default.account'),
|
||||
'paid_at' => $this->faker->date(),
|
||||
'amount' => $this->faker->randomFloat(2, 2),
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_rate' => '1',
|
||||
'description' => $this->faker->text(5),
|
||||
'category_id' => $this->company->categories()->type($type)->first()->id,
|
||||
'reference' => $this->faker->text(5),
|
||||
'payment_method' => setting('default.payment_method'),
|
||||
'attachment' => $attachment,
|
||||
'reference' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user