feat(scanner): add scanner category validation logic and related tests

This commit is contained in:
2026-08-13 11:26:13 -03:00
parent 329e0b1953
commit a2592987f5
12 changed files with 216 additions and 17 deletions

View File

@@ -119,6 +119,47 @@ class StaffControllerTest extends TestCase
->assertJsonValidationErrors('category_ids');
}
public function test_categories_are_required_by_default_for_scanner_staff(): void
{
Sanctum::actingAs($this->admin);
$this->postJson('/api/v1/adminapp/tenant/staff', [
'nombre_apellido' => 'Grace Hopper',
'dni' => '87654321',
'email' => 'grace@example.test',
'category_ids' => [],
])->assertUnprocessable()
->assertJsonValidationErrors('category_ids');
}
public function test_admin_can_manage_staff_without_categories_when_tenant_disables_validation(): void
{
$this->tenant->update(['scanner_category_validation_enabled' => false]);
Sanctum::actingAs($this->admin);
$response = $this->postJson('/api/v1/adminapp/tenant/staff', [
'nombre_apellido' => 'Grace Hopper',
'dni' => '87654321',
'email' => 'grace@example.test',
])->assertCreated()
->assertJsonCount(0, 'data.categories');
$staffId = $response->json('data.id');
$category = $this->createCategory('Entradas');
$this->putJson("/api/v1/adminapp/tenant/staff/{$staffId}", [
'nombre_apellido' => 'Grace Murray Hopper',
'dni' => '87654321',
'email' => 'grace@example.test',
'category_ids' => [$category->id],
])->assertOk()
->assertJsonCount(0, 'data.categories');
$this->assertDatabaseMissing('category_scanners', [
'user_id' => $staffId,
]);
}
public function test_customer_cannot_manage_staff(): void
{
Sanctum::actingAs(User::factory()->create([