akaunting/tests/Feature/Banking/AccountsTest.php

102 lines
2.6 KiB
PHP
Raw Normal View History

2018-11-06 15:21:27 +03:00
<?php
namespace Tests\Feature\Banking;
2019-11-17 15:06:00 +03:00
use App\Jobs\Banking\CreateAccount;
2020-01-06 16:37:32 +03:00
use App\Models\Banking\Account;
2018-11-06 15:21:27 +03:00
use Tests\Feature\FeatureTestCase;
class AccountsTest extends FeatureTestCase
{
public function testItShouldSeeAccountListPage()
{
$this->loginAs()
->get(route('accounts.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.accounts', 2));
}
public function testItShouldSeeAccountCreatePage()
{
$this->loginAs()
->get(route('accounts.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.accounts', 1)]));
}
public function testItShouldCreateAccount()
{
2020-06-21 01:34:44 +03:00
$request = $this->getRequest();
2020-06-21 01:27:20 +03:00
2018-11-06 15:21:27 +03:00
$this->loginAs()
2020-06-21 01:27:20 +03:00
->post(route('accounts.store'), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-11-06 15:21:27 +03:00
$this->assertFlashLevel('success');
2020-06-21 01:27:20 +03:00
2020-06-21 01:34:44 +03:00
$this->assertDatabaseHas('accounts', $request);
2018-11-06 15:21:27 +03:00
}
public function testItShouldSeeAccountUpdatePage()
{
2020-06-21 01:34:44 +03:00
$request = $this->getRequest();
2020-06-21 01:27:20 +03:00
$account = $this->dispatch(new CreateAccount($request));
2018-11-06 15:21:27 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->get(route('accounts.edit', $account->id))
2018-11-06 15:21:27 +03:00
->assertStatus(200)
->assertSee($account->name);
}
public function testItShouldUpdateAccount()
{
2020-01-07 01:28:05 +03:00
$request = $this->getRequest();
2018-11-06 15:21:27 +03:00
2019-11-18 10:54:26 +03:00
$account = $this->dispatch(new CreateAccount($request));
2018-11-06 15:21:27 +03:00
2020-01-14 01:05:32 +03:00
$request['name'] = $this->faker->text(10);
2018-11-06 15:21:27 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->patch(route('accounts.update', $account->id), $request)
2020-01-13 17:20:28 +03:00
->assertStatus(200)
->assertSee($request['name']);
2018-11-06 15:21:27 +03:00
$this->assertFlashLevel('success');
2020-06-21 01:27:20 +03:00
2020-06-21 01:34:44 +03:00
$this->assertDatabaseHas('accounts', $request);
2018-11-06 15:21:27 +03:00
}
public function testItShouldDeleteAccount()
{
2020-06-21 01:27:20 +03:00
$request = $this->getRequest();
$account = $this->dispatch(new CreateAccount($request));
2018-11-06 15:21:27 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->delete(route('accounts.destroy', $account->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-11-06 15:21:27 +03:00
$this->assertFlashLevel('success');
2020-06-21 01:27:20 +03:00
2020-06-21 01:34:44 +03:00
$this->assertSoftDeleted('accounts', $request);
2018-11-06 15:21:27 +03:00
}
2020-01-07 01:28:05 +03:00
2021-11-10 14:03:32 +03:00
public function testItShouldShowAccount()
{
$request = $this->getRequest();
$account = $this->dispatch(new CreateAccount($request));
$this->loginAs()
->get(route('accounts.show', $account->id))
->assertStatus(200)
->assertSee($account->name);
}
2020-01-07 01:28:05 +03:00
public function getRequest()
{
2020-10-14 17:07:59 +03:00
return Account::factory()->enabled()->raw();
2020-01-07 01:28:05 +03:00
}
2018-11-06 15:21:27 +03:00
}