70 lines
2.5 KiB
PHP
70 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace MintyPHP\Tests\Module\Audit\Service;
|
||
|
|
|
||
|
|
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
|
||
|
|
use MintyPHP\Module\Audit\Service\UserLifecycleAuditDashboardService;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
class UserLifecycleAuditDashboardServiceTest extends TestCase
|
||
|
|
{
|
||
|
|
public function testActionCountInWindowReturnsZeroForUnknownAction(): void
|
||
|
|
{
|
||
|
|
$repository = $this->createMock(UserLifecycleAuditRepository::class);
|
||
|
|
$repository->expects($this->never())->method('countActionInWindow');
|
||
|
|
|
||
|
|
$service = new UserLifecycleAuditDashboardService($repository);
|
||
|
|
|
||
|
|
$this->assertSame(0, $service->actionCountInWindow('not-a-real-action', 30));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testActionCountInWindowReturnsZeroForUnknownStatus(): void
|
||
|
|
{
|
||
|
|
$repository = $this->createMock(UserLifecycleAuditRepository::class);
|
||
|
|
$repository->expects($this->never())->method('countActionInWindow');
|
||
|
|
|
||
|
|
$service = new UserLifecycleAuditDashboardService($repository);
|
||
|
|
|
||
|
|
$this->assertSame(0, $service->actionCountInWindow('deactivate', 30, 'not-a-status'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testActionCountInWindowDelegatesNormalizedValuesToRepository(): void
|
||
|
|
{
|
||
|
|
$repository = $this->createMock(UserLifecycleAuditRepository::class);
|
||
|
|
$repository->expects($this->once())
|
||
|
|
->method('countActionInWindow')
|
||
|
|
->with('deactivate', 30, 'success')
|
||
|
|
->willReturn(7);
|
||
|
|
|
||
|
|
$service = new UserLifecycleAuditDashboardService($repository);
|
||
|
|
|
||
|
|
$this->assertSame(7, $service->actionCountInWindow('Deactivate', 30, 'Success'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testSummaryByActionReturnsEmptyForUnknownStatus(): void
|
||
|
|
{
|
||
|
|
$repository = $this->createMock(UserLifecycleAuditRepository::class);
|
||
|
|
$repository->expects($this->never())->method('sumByActionInWindow');
|
||
|
|
|
||
|
|
$service = new UserLifecycleAuditDashboardService($repository);
|
||
|
|
|
||
|
|
$this->assertSame([], $service->summaryByAction(30, 'not-a-status'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testSummaryByActionDelegatesNormalizedStatus(): void
|
||
|
|
{
|
||
|
|
$repository = $this->createMock(UserLifecycleAuditRepository::class);
|
||
|
|
$repository->expects($this->once())
|
||
|
|
->method('sumByActionInWindow')
|
||
|
|
->with(30, 'success')
|
||
|
|
->willReturn(['deactivate' => 4, 'delete' => 2]);
|
||
|
|
|
||
|
|
$service = new UserLifecycleAuditDashboardService($repository);
|
||
|
|
|
||
|
|
$this->assertSame(
|
||
|
|
['deactivate' => 4, 'delete' => 2],
|
||
|
|
$service->summaryByAction(30, 'Success')
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|