3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-03-29 20:04:21 +00:00

Merge pull request #16576 from marcusmoore/fixes/api_company_note

Fixed notes not being saved and update for companies via api
This commit is contained in:
snipe
2025-03-31 12:20:36 +01:00
committed by GitHub
4 changed files with 106 additions and 1 deletions

View File

@ -67,7 +67,8 @@ final class Company extends SnipeModel
'phone',
'fax',
'email',
'created_by'
'created_by',
'notes',
];
private static function isFullMultipleCompanySupportEnabled()

View File

@ -295,6 +295,11 @@ class UserFactory extends Factory
return $this->appendPermission(['companies.delete' => '1']);
}
public function editCompanies()
{
return $this->appendPermission(['companies.edit' => '1']);
}
public function viewUsers()
{
return $this->appendPermission(['users.view' => '1']);

View File

@ -0,0 +1,46 @@
<?php
namespace Tests\Feature\Companies\Api;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
class CreateCompaniesTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$this->actingAsForApi(User::factory()->create())
->postJson(route('api.companies.store'))
->assertForbidden();
}
public function testValidationForCreatingCompany()
{
$this->actingAsForApi(User::factory()->createCompanies()->create())
->postJson(route('api.companies.store'))
->assertStatus(200)
->assertStatusMessageIs('error')
->assertJsonStructure([
'messages' => [
'name',
],
]);
}
public function testCanCreateCompany()
{
$this->actingAsForApi(User::factory()->createCompanies()->create())
->postJson(route('api.companies.store'), [
'name' => 'My Cool Company',
'notes' => 'A Cool Note',
])
->assertStatus(200)
->assertStatusMessageIs('success');
$this->assertDatabaseHas('companies', [
'name' => 'My Cool Company',
'notes' => 'A Cool Note',
]);
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Tests\Feature\Companies\Api;
use App\Models\Company;
use App\Models\User;
use Tests\TestCase;
class UpdateCompaniesTest extends TestCase
{
public function testRequiresPermissionToPatchCompany()
{
$company = Company::factory()->create();
$this->actingAsForApi(User::factory()->create())
->patchJson(route('api.companies.update', $company))
->assertForbidden();
}
public function testValidationForPatchingCompany()
{
$company = Company::factory()->create();
$this->actingAsForApi(User::factory()->editCompanies()->create())
->patchJson(route('api.companies.update', ['company' => $company->id]), [
'name' => '',
])
->assertStatus(200)
->assertStatusMessageIs('error')
->assertJsonStructure([
'messages' => [
'name',
],
]);
}
public function testCanPatchCompany()
{
$company = Company::factory()->create();
$this->actingAsForApi(User::factory()->editCompanies()->create())
->patchJson(route('api.companies.update', ['company' => $company->id]), [
'name' => 'A Changed Name',
'notes' => 'A Changed Note',
])
->assertStatus(200)
->assertStatusMessageIs('success');
$company->refresh();
$this->assertEquals('A Changed Name', $company->name);
$this->assertEquals('A Changed Note', $company->notes);
}
}