Tests for Payments and Revenues
This commit is contained in:
parent
70f6cbbf5c
commit
175660203d
86
tests/Feature/Expenses/PaymentsTest.php
Normal file
86
tests/Feature/Expenses/PaymentsTest.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Expenses;
|
||||
|
||||
use App\Models\Expense\Payment;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class PaymentsTest extends FeatureTestCase
|
||||
{
|
||||
|
||||
public function testItShouldSeePaymentListPage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(url('expenses/payments'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.payments', 2));
|
||||
}
|
||||
|
||||
public function testItShouldSeePaymentCreatePage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(url('expenses/payments/create'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.payments', 1)]));
|
||||
}
|
||||
|
||||
public function testItShouldCreatePayment()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(url('expenses/payments'), $this->getPaymentRequest())
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('expenses/payments'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldUpdatePayment()
|
||||
{
|
||||
$request = $this->getPaymentRequest();
|
||||
|
||||
$payment = Payment::create($request);
|
||||
|
||||
$request['name'] = $this->faker->text(15);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(url('expenses/payments', $payment->id), $request)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('expenses/payments'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldDeletePayment()
|
||||
{
|
||||
$payment = Payment::create($this->getPaymentRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->delete(url('expenses/payments', $payment->id))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(url('expenses/payments'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getPaymentRequest()
|
||||
{
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'account_id' => setting('general.default_account'),
|
||||
'paid_at' => $this->faker->date(),
|
||||
'amount' => $this->faker->randomFloat(2, 2),
|
||||
'currency_code' => setting('general.default_currency'),
|
||||
'currency_rate' => '1',
|
||||
'vendor_id' => setting('general.default_vendor'),
|
||||
'description' => $this->faker->text(5),
|
||||
'category_id' => $this->company->categories()->type('income')->first()->id,
|
||||
'payment_method' => setting('general.default_payment_method'),
|
||||
'reference' => $this->faker->text(5),
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
84
tests/Feature/Incomes/RevenuesTest.php
Normal file
84
tests/Feature/Incomes/RevenuesTest.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Incomes;
|
||||
|
||||
use App\Models\Income\Revenue;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class RevenuesTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldSeeRevenueListPage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('revenues.index'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans_choice('general.revenues', 2));
|
||||
}
|
||||
|
||||
public function testItShouldSeeRevenueCreatePage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('revenues.create'))
|
||||
->assertStatus(200)
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.revenues', 1)]));
|
||||
}
|
||||
|
||||
public function testItShouldCreateRevenue()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('revenues.store'), $this->getRevenueRequest())
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('revenues.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldUpdateRevenue()
|
||||
{
|
||||
$request = $this->getRevenueRequest();
|
||||
|
||||
$revenue = Revenue::create($request);
|
||||
|
||||
$request['name'] = $this->faker->text(15);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('revenues.update', $revenue->id), $request)
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('revenues.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldDeleteRevenue()
|
||||
{
|
||||
$revenue = Revenue::create($this->getRevenueRequest());
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('revenues.destroy', $revenue->id))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('revenues.index'));
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getRevenueRequest()
|
||||
{
|
||||
$attachment = UploadedFile::fake()->create('image.jpg');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'customer_id' => '',
|
||||
'account_id' => setting('general.default_account'),
|
||||
'paid_at' => $this->faker->date(),
|
||||
'amount' => $this->faker->randomFloat(2, 2),
|
||||
'currency_code' => setting('general.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('general.default_payment_method'),
|
||||
'attachment' => $attachment,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user