Strengthen service workflow tests
This commit is contained in:
@@ -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'];
|
||||
|
||||
Reference in New Issue
Block a user