snipe-it/tests/Feature/Accessories/Api/StoreAccessoryTest.php

63 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Accessories\Api;
2024-09-18 11:53:27 -07:00
use App\Models\Category;
use App\Models\Company;
use App\Models\User;
2024-09-18 11:53:27 -07:00
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
2024-09-18 11:53:27 -07:00
class StoreAccessoryTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$this->actingAsForApi(User::factory()->create())
->postJson(route('api.accessories.store'))
->assertForbidden();
}
2024-09-18 11:47:59 -07:00
2024-09-18 11:53:27 -07:00
public function testAdheresToFullMultipleCompaniesSupportScoping()
{
$this->markTestSkipped('This behavior is not implemented');
[$companyA, $companyB] = Company::factory()->count(2)->create();
$userInCompanyA = User::factory()->for($companyA)->createAccessories()->create();
$this->settings->enableMultipleFullCompanySupport();
// attempt to store an accessory for company B
$this->actingAsForApi($userInCompanyA)
->postJson(route('api.accessories.store'), [
'category_id' => Category::factory()->forAccessories()->create()->id,
'name' => 'Accessory A',
'qty' => 1,
'company_id' => $companyB->id,
])->assertStatusMessageIs('error');
$this->assertDatabaseMissing('accessories', [
'name' => 'Accessory A',
]);
}
2024-09-18 11:47:59 -07:00
public function testValidation()
{
$this->actingAsForApi(User::factory()->createAccessories()->create())
->postJson(route('api.accessories.store'), [
//
])
->assertStatusMessageIs('error')
->assertMessagesContains([
'category_id',
'name',
'qty',
]);
}
public function testCanStoreAccessory()
{
$this->markTestIncomplete();
}
}