akaunting/tests/Feature/Sales/RevenuesTest.php

174 lines
4.7 KiB
PHP
Raw Normal View History

2018-10-09 14:18:12 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace Tests\Feature\Sales;
2018-10-09 14:18:12 +03:00
use App\Exports\Sales\Revenues as Export;
2019-11-17 15:06:00 +03:00
use App\Jobs\Banking\CreateTransaction;
2019-12-16 13:19:09 +03:00
use App\Models\Banking\Transaction;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\File;
2018-10-09 14:18:12 +03:00
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));
}
2021-06-30 12:56:46 +03:00
public function testItShouldSeeRevenueShowPage()
{
$request = $this->getRequest();
$revenue = $this->dispatch(new CreateTransaction($request));
$this->loginAs()
->get(route('revenues.show', $revenue->id))
->assertStatus(200)
->assertSee($revenue->contact->email);
}
2018-10-09 14:18:12 +03:00
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()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
2018-10-09 14:18:12 +03:00
$this->loginAs()
2020-07-25 17:22:50 +03:00
->post(route('revenues.store'), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-09 14:18:12 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertDatabaseHas('transactions', $request);
2018-10-09 14:18:12 +03:00
}
2020-01-13 10:55:19 +03:00
public function testItShouldSeeRevenueUpdatePage()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$revenue = $this->dispatch(new CreateTransaction($request));
2020-01-13 10:55:19 +03:00
$this->loginAs()
->get(route('revenues.edit', $revenue->id))
->assertStatus(200)
->assertSee($revenue->amount);
}
2018-10-09 14:18:12 +03:00
public function testItShouldUpdateRevenue()
{
2020-01-07 01:28:05 +03:00
$request = $this->getRequest();
2018-10-09 14:18:12 +03:00
2019-11-17 15:06:00 +03:00
$revenue = $this->dispatch(new CreateTransaction($request));
2018-10-09 14:18:12 +03:00
2020-01-13 17:20:28 +03:00
$request['amount'] = $this->faker->randomFloat(2, 1, 1000);
2018-10-09 14:18:12 +03:00
$this->loginAs()
->patch(route('revenues.update', $revenue->id), $request)
2020-01-13 17:20:28 +03:00
->assertStatus(200)
->assertSee($request['amount']);
2018-10-09 14:18:12 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertDatabaseHas('transactions', $request);
2018-10-09 14:18:12 +03:00
}
public function testItShouldDeleteRevenue()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$revenue = $this->dispatch(new CreateTransaction($request));
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');
2020-07-25 17:22:50 +03:00
$this->assertSoftDeleted('transactions', $request);
2018-10-09 14:18:12 +03:00
}
2020-01-07 01:28:05 +03:00
public function testItShouldExportRevenues()
{
$count = 5;
Transaction::factory()->income()->count($count)->create();
\Excel::fake();
$this->loginAs()
->get(route('revenues.export'))
->assertStatus(200);
2021-05-23 17:13:13 +03:00
\Excel::matchByRegex();
\Excel::assertDownloaded(
2021-05-23 17:13:13 +03:00
'/' . \Str::filename(trans_choice('general.revenues', 2)) . '-\d{10}\.xlsx/',
function (Export $export) use ($count) {
// Assert that the correct export is downloaded.
return $export->collection()->count() === $count;
}
);
}
public function testItShouldExportSelectedRevenues()
{
2021-05-23 17:13:13 +03:00
$create_count = 5;
$select_count = 3;
$revenues = Transaction::factory()->income()->count($create_count)->create();
\Excel::fake();
$this->loginAs()
->post(
route('bulk-actions.action', ['group' => 'sales', 'type' => 'revenues']),
2021-05-23 17:13:13 +03:00
['handle' => 'export', 'selected' => $revenues->take($select_count)->pluck('id')->toArray()]
)
->assertStatus(200);
2021-05-23 17:13:13 +03:00
\Excel::matchByRegex();
\Excel::assertDownloaded(
2021-05-23 17:13:13 +03:00
'/' . \Str::filename(trans_choice('general.revenues', 2)) . '-\d{10}\.xlsx/',
function (Export $export) use ($select_count) {
return $export->collection()->count() === $select_count;
}
);
}
public function testItShouldImportRevenues()
{
\Excel::fake();
$this->loginAs()
->post(
route('revenues.import'),
[
'import' => UploadedFile::fake()->createWithContent(
'revenues.xlsx',
File::get(public_path('files/import/revenues.xlsx'))
),
]
)
->assertStatus(200);
\Excel::assertImported('revenues.xlsx');
$this->assertFlashLevel('success');
}
2020-01-07 01:28:05 +03:00
public function getRequest()
{
2020-10-14 17:07:59 +03:00
return Transaction::factory()->income()->raw();
2020-01-07 01:28:05 +03:00
}
2019-04-02 18:51:06 +03:00
}