factory in tests

This commit is contained in:
denisdulici 2019-12-16 13:19:09 +03:00
parent 1e2b5a3621
commit b03ded8a57
3 changed files with 8 additions and 52 deletions

View File

@ -3,7 +3,6 @@
use App\Models\Auth\User;
use App\Models\Banking\Transaction;
use Faker\Generator as Faker;
use Illuminate\Http\UploadedFile;
$user = User::first();
$company = $user->companies()->first();
@ -11,8 +10,6 @@ $company = $user->companies()->first();
$factory->define(Transaction::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
$attachment = UploadedFile::fake()->create('image.jpg');
return [
'company_id' => $company->id,
'type' => 'income',
@ -25,7 +22,6 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) {
'category_id' => $company->categories()->type('income')->pluck('id')->first(),
'reference' => $faker->text(5),
'payment_method' => setting('default.payment_method'),
//'attachment' => $attachment,
];
});

View File

@ -3,7 +3,7 @@
namespace Tests\Feature\Expenses;
use App\Jobs\Banking\CreateTransaction;
use Illuminate\Http\UploadedFile;
use App\Models\Banking\Transaction;
use Tests\Feature\FeatureTestCase;
class PaymentsTest extends FeatureTestCase
@ -27,7 +27,7 @@ class PaymentsTest extends FeatureTestCase
public function testItShouldCreatePayment()
{
$this->loginAs()
->post(route('payments.store'), $this->getPaymentRequest())
->post(route('payments.store'), factory(Transaction::class)->states('expense')->raw())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -35,7 +35,7 @@ class PaymentsTest extends FeatureTestCase
public function testItShouldUpdatePayment()
{
$request = $this->getPaymentRequest();
$request = factory(Transaction::class)->states('expense')->raw();
$payment = $this->dispatch(new CreateTransaction($request));
@ -50,7 +50,7 @@ class PaymentsTest extends FeatureTestCase
public function testItShouldDeletePayment()
{
$payment = $this->dispatch(new CreateTransaction($this->getPaymentRequest()));
$payment = $this->dispatch(new CreateTransaction(factory(Transaction::class)->states('expense')->raw()));
$this->loginAs()
->delete(route('payments.destroy', $payment->id))
@ -58,24 +58,4 @@ class PaymentsTest extends FeatureTestCase
$this->assertFlashLevel('success');
}
private function getPaymentRequest()
{
$attachment = UploadedFile::fake()->create('image.jpg');
return [
'company_id' => $this->company->id,
'type' => 'expense',
'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('expense')->first()->id,
'payment_method' => setting('default.payment_method'),
'reference' => $this->faker->text(5),
'attachment' => $attachment,
];
}
}

View File

@ -3,7 +3,7 @@
namespace Tests\Feature\Incomes;
use App\Jobs\Banking\CreateTransaction;
use Illuminate\Http\UploadedFile;
use App\Models\Banking\Transaction;
use Tests\Feature\FeatureTestCase;
class RevenuesTest extends FeatureTestCase
@ -27,7 +27,7 @@ class RevenuesTest extends FeatureTestCase
public function testItShouldCreateRevenue()
{
$this->loginAs()
->post(route('revenues.store'), $this->getRevenueRequest())
->post(route('revenues.store'), factory(Transaction::class)->raw())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -35,7 +35,7 @@ class RevenuesTest extends FeatureTestCase
public function testItShouldUpdateRevenue()
{
$request = $this->getRevenueRequest();
$request = factory(Transaction::class)->raw();
$revenue = $this->dispatch(new CreateTransaction($request));
@ -50,7 +50,7 @@ class RevenuesTest extends FeatureTestCase
public function testItShouldDeleteRevenue()
{
$revenue = $this->dispatch(new CreateTransaction($this->getRevenueRequest()));
$revenue = $this->dispatch(new CreateTransaction(factory(Transaction::class)->raw()));
$this->loginAs()
->delete(route('revenues.destroy', $revenue->id))
@ -58,24 +58,4 @@ class RevenuesTest extends FeatureTestCase
$this->assertFlashLevel('success');
}
private function getRevenueRequest()
{
$attachment = UploadedFile::fake()->create('image.jpg');
return [
'company_id' => $this->company->id,
'type' => 'income',
'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('income')->first()->id,
'reference' => $this->faker->text(5),
'payment_method' => setting('default.payment_method'),
'attachment' => $attachment,
];
}
}