snipe-it/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php

83 lines
2.5 KiB
PHP
Raw Normal View History

2024-09-04 15:43:01 -07:00
<?php
namespace Tests\Feature\Accessories\Ui;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Supplier;
use App\Models\User;
use Tests\TestCase;
class CreateAccessoriesTest extends TestCase
{
public function testRequiresPermissionToViewCreateAccessoryPage()
{
$this->actingAs(User::factory()->create())
->get(route('accessories.create'))
->assertForbidden();
}
public function testCreateAccessoryPageRenders()
{
$this->actingAs(User::factory()->createAccessories()->create())
->get(route('accessories.create'))
->assertOk()
->assertViewIs('accessories.edit');
}
2024-09-09 16:51:40 -07:00
public function testRequiresPermissionToCreateAccessory()
{
$this->actingAs(User::factory()->create())
->post(route('accessories.store'))
->assertForbidden();
}
2024-09-04 15:43:01 -07:00
public function testValidDataRequiredToCreateAccessory()
{
2024-09-04 15:48:11 -07:00
$this->actingAs(User::factory()->createAccessories()->create())
->post(route('accessories.store'), [
//
])
->assertSessionHasErrors([
'name',
'qty',
'category_id',
]);
2024-09-04 15:43:01 -07:00
}
public function testCanCreateAccessory()
{
$category = Category::factory()->create();
$company = Company::factory()->create();
$location = Location::factory()->create();
$manufacturer = Manufacturer::factory()->create();
$supplier = Supplier::factory()->create();
$data = [
'category_id' => $category->id,
2024-09-04 15:46:35 -07:00
'company_id' => $company->id,
2024-09-04 15:43:01 -07:00
'location_id' => $location->id,
2024-09-04 15:46:35 -07:00
'manufacturer_id' => $manufacturer->id,
'min_amt' => '1',
2024-09-04 15:43:01 -07:00
'model_number' => '12345',
2024-09-04 15:46:35 -07:00
'name' => 'My Accessory Name',
'notes' => 'Some notes here',
2024-09-04 15:43:01 -07:00
'order_number' => '9876',
'purchase_cost' => '99.98',
2024-09-04 15:46:35 -07:00
'purchase_date' => '2024-09-04',
2024-09-04 15:43:01 -07:00
'qty' => '3',
2024-09-04 15:46:35 -07:00
'supplier_id' => $supplier->id,
2024-09-04 15:43:01 -07:00
];
2024-09-04 15:44:52 -07:00
$user = User::factory()->createAccessories()->create();
$this->actingAs($user)
2024-09-04 15:43:01 -07:00
->post(route('accessories.store'), array_merge($data, ['redirect_option' => 'index']))
->assertRedirect(route('accessories.index'));
$this->assertDatabaseHas('accessories', array_merge($data, ['created_by' => $user->id]));
2024-09-04 15:43:01 -07:00
}
}