factory in tests
This commit is contained in:
parent
1e2b5a3621
commit
b03ded8a57
@ -3,7 +3,6 @@
|
|||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
use Faker\Generator as Faker;
|
use Faker\Generator as Faker;
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
|
|
||||||
$user = User::first();
|
$user = User::first();
|
||||||
$company = $user->companies()->first();
|
$company = $user->companies()->first();
|
||||||
@ -11,8 +10,6 @@ $company = $user->companies()->first();
|
|||||||
$factory->define(Transaction::class, function (Faker $faker) use ($company) {
|
$factory->define(Transaction::class, function (Faker $faker) use ($company) {
|
||||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||||
|
|
||||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'type' => 'income',
|
'type' => 'income',
|
||||||
@ -25,7 +22,6 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) {
|
|||||||
'category_id' => $company->categories()->type('income')->pluck('id')->first(),
|
'category_id' => $company->categories()->type('income')->pluck('id')->first(),
|
||||||
'reference' => $faker->text(5),
|
'reference' => $faker->text(5),
|
||||||
'payment_method' => setting('default.payment_method'),
|
'payment_method' => setting('default.payment_method'),
|
||||||
//'attachment' => $attachment,
|
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace Tests\Feature\Expenses;
|
namespace Tests\Feature\Expenses;
|
||||||
|
|
||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use Illuminate\Http\UploadedFile;
|
use App\Models\Banking\Transaction;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class PaymentsTest extends FeatureTestCase
|
class PaymentsTest extends FeatureTestCase
|
||||||
@ -27,7 +27,7 @@ class PaymentsTest extends FeatureTestCase
|
|||||||
public function testItShouldCreatePayment()
|
public function testItShouldCreatePayment()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('payments.store'), $this->getPaymentRequest())
|
->post(route('payments.store'), factory(Transaction::class)->states('expense')->raw())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -35,7 +35,7 @@ class PaymentsTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdatePayment()
|
public function testItShouldUpdatePayment()
|
||||||
{
|
{
|
||||||
$request = $this->getPaymentRequest();
|
$request = factory(Transaction::class)->states('expense')->raw();
|
||||||
|
|
||||||
$payment = $this->dispatch(new CreateTransaction($request));
|
$payment = $this->dispatch(new CreateTransaction($request));
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class PaymentsTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeletePayment()
|
public function testItShouldDeletePayment()
|
||||||
{
|
{
|
||||||
$payment = $this->dispatch(new CreateTransaction($this->getPaymentRequest()));
|
$payment = $this->dispatch(new CreateTransaction(factory(Transaction::class)->states('expense')->raw()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('payments.destroy', $payment->id))
|
->delete(route('payments.destroy', $payment->id))
|
||||||
@ -58,24 +58,4 @@ class PaymentsTest extends FeatureTestCase
|
|||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$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,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace Tests\Feature\Incomes;
|
namespace Tests\Feature\Incomes;
|
||||||
|
|
||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use Illuminate\Http\UploadedFile;
|
use App\Models\Banking\Transaction;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class RevenuesTest extends FeatureTestCase
|
class RevenuesTest extends FeatureTestCase
|
||||||
@ -27,7 +27,7 @@ class RevenuesTest extends FeatureTestCase
|
|||||||
public function testItShouldCreateRevenue()
|
public function testItShouldCreateRevenue()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('revenues.store'), $this->getRevenueRequest())
|
->post(route('revenues.store'), factory(Transaction::class)->raw())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -35,7 +35,7 @@ class RevenuesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdateRevenue()
|
public function testItShouldUpdateRevenue()
|
||||||
{
|
{
|
||||||
$request = $this->getRevenueRequest();
|
$request = factory(Transaction::class)->raw();
|
||||||
|
|
||||||
$revenue = $this->dispatch(new CreateTransaction($request));
|
$revenue = $this->dispatch(new CreateTransaction($request));
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class RevenuesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeleteRevenue()
|
public function testItShouldDeleteRevenue()
|
||||||
{
|
{
|
||||||
$revenue = $this->dispatch(new CreateTransaction($this->getRevenueRequest()));
|
$revenue = $this->dispatch(new CreateTransaction(factory(Transaction::class)->raw()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('revenues.destroy', $revenue->id))
|
->delete(route('revenues.destroy', $revenue->id))
|
||||||
@ -58,24 +58,4 @@ class RevenuesTest extends FeatureTestCase
|
|||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$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,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user