akaunting/tests/Feature/Incomes/RevenuesTest.php

82 lines
2.3 KiB
PHP
Raw Normal View History

2018-10-09 14:18:12 +03:00
<?php
namespace Tests\Feature\Incomes;
2019-11-16 10:21:14 +03:00
use App\Models\Banking\Transaction;
2018-10-09 14:18:12 +03:00
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())
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-09 14:18:12 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldUpdateRevenue()
{
$request = $this->getRevenueRequest();
2019-11-16 10:21:14 +03:00
$revenue = Transaction::create($request);
2018-10-09 14:18:12 +03:00
$request['name'] = $this->faker->text(15);
$this->loginAs()
->patch(route('revenues.update', $revenue->id), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-09 14:18:12 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldDeleteRevenue()
{
2019-11-16 10:21:14 +03:00
$revenue = Transaction::create($this->getRevenueRequest());
2018-10-09 14:18:12 +03:00
$this->loginAs()
->delete(route('revenues.destroy', $revenue->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-09 14:18:12 +03:00
$this->assertFlashLevel('success');
}
private function getRevenueRequest()
{
$attachment = UploadedFile::fake()->create('image.jpg');
return [
'company_id' => $this->company->id,
2019-11-16 10:21:14 +03:00
'type' => 'income',
'account_id' => setting('default.account'),
2018-10-09 14:18:12 +03:00
'paid_at' => $this->faker->date(),
'amount' => $this->faker->randomFloat(2, 2),
2019-11-16 10:21:14 +03:00
'currency_code' => setting('default.currency'),
2018-10-09 14:18:12 +03:00
'currency_rate' => '1',
'description' => $this->faker->text(5),
'category_id' => $this->company->categories()->type('income')->first()->id,
'reference' => $this->faker->text(5),
2019-11-16 10:21:14 +03:00
'payment_method' => setting('default.payment_method'),
2018-10-09 14:18:12 +03:00
'attachment' => $attachment,
];
}
2019-04-02 18:51:06 +03:00
}