Strengthen service workflow tests

This commit is contained in:
2026-03-19 20:28:04 +01:00
parent f7b03926b0
commit 56c3e30f43
3 changed files with 224 additions and 47 deletions

View File

@@ -84,6 +84,37 @@ class RoleServiceTest extends TestCase
$this->assertNotEmpty($result['errors']);
}
public function testCreateFromAdminReturnsErrorWhenRepositoryCreateFails(): void
{
$this->roleRepo
->expects($this->once())
->method('existsByCode')
->with('EDITOR', 0)
->willReturn(false);
$this->roleRepo
->expects($this->once())
->method('create')
->willReturn(false);
$this->roleRepo
->expects($this->never())
->method('find');
$this->auditService
->expects($this->never())
->method('record');
$result = $this->service->createFromAdmin([
'description' => 'Editor',
'code' => 'EDITOR',
'active' => 1,
], 5);
$this->assertFalse($result['ok']);
$this->assertNotEmpty($result['errors']);
}
public function testCreateFromAdminSetsDefaultRoleWhenRequested(): void
{
$this->roleRepo
@@ -175,6 +206,40 @@ class RoleServiceTest extends TestCase
$this->assertNotEmpty($result['errors']);
}
public function testUpdateFromAdminReturnsErrorWhenRepositoryUpdateFails(): void
{
$this->roleRepo
->expects($this->once())
->method('existsByCode')
->with('MGR', 10)
->willReturn(false);
$this->roleRepo
->expects($this->once())
->method('find')
->with(10)
->willReturn(['id' => 10, 'uuid' => 'uuid-10', 'active' => 1]);
$this->roleRepo
->expects($this->once())
->method('update')
->with(10, $this->anything())
->willReturn(false);
$this->auditService
->expects($this->never())
->method('record');
$result = $this->service->updateFromAdmin(10, [
'description' => 'Manager',
'code' => 'MGR',
'active' => 1,
], 5);
$this->assertFalse($result['ok']);
$this->assertNotEmpty($result['errors']);
}
public function testDeleteByUuidSucceeds(): void
{
$role = ['id' => 7, 'uuid' => 'uuid-7', 'description' => 'Guest'];