fixed tests
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\Banking;
|
||||
|
||||
use App\Jobs\Banking\CreateAccount;
|
||||
use App\Models\Banking\Account;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class AccountsTest extends FeatureTestCase
|
||||
@@ -26,7 +27,7 @@ class AccountsTest extends FeatureTestCase
|
||||
public function testItShouldCreateAccount()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('accounts.index'), $this->getAccountRequest())
|
||||
->post(route('accounts.index'), factory(Account::class)->raw())
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
@@ -34,7 +35,7 @@ class AccountsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldSeeAccountUpdatePage()
|
||||
{
|
||||
$account = $this->dispatch(new CreateAccount($this->getAccountRequest()));
|
||||
$account = $this->dispatch(new CreateAccount(factory(Account::class)->raw()));
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('accounts.edit', ['account' => $account->id]))
|
||||
@@ -44,7 +45,7 @@ class AccountsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldUpdateAccount()
|
||||
{
|
||||
$request = $this->getAccountRequest();
|
||||
$request = factory(Account::class)->raw();
|
||||
|
||||
$account = $this->dispatch(new CreateAccount($request));
|
||||
|
||||
@@ -59,7 +60,7 @@ class AccountsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldDeleteAccount()
|
||||
{
|
||||
$account = $this->dispatch(new CreateAccount($this->getAccountRequest()));
|
||||
$account = $this->dispatch(new CreateAccount(factory(Account::class)->raw()));
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('accounts.destroy', ['account' => $account]))
|
||||
@@ -67,20 +68,4 @@ class AccountsTest extends FeatureTestCase
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getAccountRequest()
|
||||
{
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'name' => $this->faker->text(5),
|
||||
'number' => (string) $this->faker->randomNumber(2),
|
||||
'currency_code' => setting('default.currency', 'USD'),
|
||||
'opening_balance' => '0',
|
||||
'bank_name' => $this->faker->text(5),
|
||||
'bank_phone' => null,
|
||||
'bank_address' => null,
|
||||
'default_account' => 0,
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,8 +26,8 @@ abstract class FeatureTestCase extends TestCase
|
||||
$this->company = $this->user->companies()->first();
|
||||
|
||||
// Set Company settings
|
||||
setting()->forgetAll();
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
setting()->load(true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user