mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Merge pull request #15470 from marcusmoore/company_tests
Added UI tests for creating companies
This commit is contained in:
commit
e7e5dfbdfa
|
@ -241,6 +241,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['components.view' => '1']);
|
return $this->appendPermission(['components.view' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createCompanies()
|
||||||
|
{
|
||||||
|
return $this->appendPermission(['companies.create' => '1']);
|
||||||
|
}
|
||||||
|
|
||||||
public function createComponents()
|
public function createComponents()
|
||||||
{
|
{
|
||||||
return $this->appendPermission(['components.create' => '1']);
|
return $this->appendPermission(['components.create' => '1']);
|
||||||
|
|
60
tests/Feature/Companies/Ui/CreateCompaniesTest.php
Normal file
60
tests/Feature/Companies/Ui/CreateCompaniesTest.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Companies\Ui;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CreateCompaniesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRequiresPermissionToViewCreateCompanyPage()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('companies.create'))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateCompanyPageRenders()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->createCompanies()->create())
|
||||||
|
->get(route('companies.create'))
|
||||||
|
->assertOk()
|
||||||
|
->assertViewIs('companies.edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRequiresPermissionToCreateCompany()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->post(route('companies.store'))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidDataRequiredToCreateCompany()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->createCompanies()->create())
|
||||||
|
->post(route('companies.store'), [
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->assertSessionHasErrors([
|
||||||
|
'name',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanCreateCompany()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'email' => 'email@example.com',
|
||||||
|
'fax' => '619-666-6666',
|
||||||
|
'name' => 'My New Company',
|
||||||
|
'phone' => '619-555-5555',
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = User::factory()->createCompanies()->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->post(route('companies.store'), array_merge($data, ['redirect_option' => 'index']))
|
||||||
|
->assertRedirect(route('companies.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('companies', array_merge($data));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue