Company test added
This commit is contained in:
parent
4cb869d451
commit
7bef3d1569
@ -3,9 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Common\Company as Model;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Company extends Factory
|
||||
{
|
||||
@ -24,8 +22,11 @@ class Company extends Factory
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->freeEmail,
|
||||
'currency' => $this->faker->randomElement(array_keys(\Akaunting\Money\Currency::getCurrencies())),
|
||||
'country' => $this->faker->randomElement(array_keys(trans('countries'))),
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
}
|
||||
|
||||
@ -52,44 +53,4 @@ class Company extends Factory
|
||||
'enabled' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
return $this->afterCreating(function (Model $company) {
|
||||
$company->makeCurrent();
|
||||
|
||||
app()->setLocale('en-GB');
|
||||
|
||||
// Company seeds
|
||||
Artisan::call('company:seed', [
|
||||
'company' => $company->id
|
||||
]);
|
||||
|
||||
$user = User::first();
|
||||
|
||||
$user->companies()->attach($company->id);
|
||||
|
||||
// User seeds
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
|
||||
setting()->set([
|
||||
'company.name' => $this->faker->text(15),
|
||||
'company.address' => 'New Street 1254',
|
||||
'company.city' => 'London',
|
||||
'company.country' => $this->faker->countryCode,
|
||||
'default.currency' => 'USD',
|
||||
'default.locale' => 'en-GB',
|
||||
]);
|
||||
|
||||
setting()->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
126
tests/Feature/Common/CompaniesTest.php
Normal file
126
tests/Feature/Common/CompaniesTest.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Common;
|
||||
|
||||
use App\Models\Common\Company;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class CompaniesTest extends FeatureTestCase
|
||||
{
|
||||
public function testItShouldSeeCompanyInDashboard()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('dashboard'))
|
||||
->assertOk()
|
||||
->assertSeeText($this->company->name)
|
||||
->assertSeeText(trans('general.title.manage', ['type' => trans_choice('general.companies', 2)]));
|
||||
}
|
||||
|
||||
public function testItShouldSeeCompanyListPage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('companies.index'))
|
||||
->assertOk()
|
||||
->assertSeeText(trans_choice('general.companies', 2));
|
||||
}
|
||||
|
||||
public function testItShouldSeeCompanyCreatePage()
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('companies.create'))
|
||||
->assertOk()
|
||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.companies', 1)]));
|
||||
}
|
||||
|
||||
public function testItShouldCreateCompany()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$response = $this->loginAs()
|
||||
->post(route('companies.store'), $request)
|
||||
->assertOk();
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertHasCompany($response->baseResponse->original['data']->id, $request);
|
||||
}
|
||||
|
||||
public function testItShouldSwitchCompany()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$company = $this->createCompany($request);
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('companies.switch', $company->id))
|
||||
->assertStatus(302);
|
||||
|
||||
$this->assertEquals($company->id, company_id());
|
||||
}
|
||||
|
||||
public function testItShouldSeeCompanyUpdatePage()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$company = $this->createCompany($request);
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('companies.edit', $company->id))
|
||||
->assertOk()
|
||||
->assertSee($company->name);
|
||||
}
|
||||
|
||||
public function testItShouldUpdateCompany()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$company = $this->createCompany($request);
|
||||
|
||||
$request['name'] = $this->faker->text(15);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('companies.update', $company->id), $request)
|
||||
->assertOk();
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
|
||||
$this->assertHasCompany($company->id, $request);
|
||||
}
|
||||
|
||||
public function testItShouldDeleteCompany()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$company = $this->createCompany($request);
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('companies.destroy', $company->id))
|
||||
->assertOk();
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function getRequest(): array
|
||||
{
|
||||
return Company::factory()->enabled()->raw();
|
||||
}
|
||||
|
||||
public function createCompany(array $request): Company
|
||||
{
|
||||
$response = $this->loginAs()
|
||||
->post(route('companies.store'), $request)
|
||||
->assertOk();
|
||||
|
||||
return $response->baseResponse->original['data'];
|
||||
}
|
||||
|
||||
public function assertHasCompany(int $id, array $request): void
|
||||
{
|
||||
company($id)->makeCurrent();
|
||||
|
||||
$this->assertEquals(setting('company.name'), $request['name']);
|
||||
$this->assertEquals(setting('company.email'), $request['email']);
|
||||
$this->assertEquals(setting('company.country'), $request['country']);
|
||||
$this->assertEquals(setting('default.currency'), $request['currency']);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user