93 lines
3.2 KiB
PHP
93 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Application\Reports\CompareLegacyAndNewReportUseCase;
|
|
use App\Application\Reports\DTO\GenerateReportInput;
|
|
use App\Application\Reports\DTO\ReportComparisonResult;
|
|
use App\Application\Reports\GenerateReportUseCase;
|
|
use App\Domain\Reports\Contracts\AuditLogger;
|
|
use App\Domain\Reports\Contracts\PatientSource;
|
|
use App\Domain\Reports\Contracts\ReportRepository;
|
|
use App\Domain\Reports\Models\PatientCollection;
|
|
use App\Domain\Reports\Models\ReportContext;
|
|
use App\Domain\Reports\Models\ReportSnapshot;
|
|
use App\Domain\Reports\Models\SavedReportResult;
|
|
use App\Infrastructure\Reports\Adapters\LegacyReportServiceAdapter;
|
|
|
|
it('stores generated report and writes comparison audit', function () {
|
|
$input = new GenerateReportInput(
|
|
departmentId: 10,
|
|
userId: 5015,
|
|
actorUserId: 15,
|
|
periodStart: new DateTimeImmutable('2026-04-08 06:00:00'),
|
|
periodEnd: new DateTimeImmutable('2026-04-09 06:00:00'),
|
|
reportType: 'daily',
|
|
autoFill: true,
|
|
);
|
|
|
|
$patientSource = new class implements PatientSource
|
|
{
|
|
public function load(ReportContext $context): PatientCollection
|
|
{
|
|
return new PatientCollection([], [
|
|
'payload' => [
|
|
'departmentId' => $context->departmentId,
|
|
'userId' => $context->userId,
|
|
'dates' => [$context->periodStart->getTimestamp(), $context->periodEnd->getTimestamp()],
|
|
'status' => 'submitted',
|
|
'metrics' => ['metrika_item_4' => 11],
|
|
'observationPatients' => [],
|
|
'unwantedEvents' => [],
|
|
],
|
|
]);
|
|
}
|
|
};
|
|
|
|
$snapshot = new ReportSnapshot(
|
|
departmentId: 10,
|
|
userId: 5015,
|
|
actorUserId: 15,
|
|
periodStart: new DateTimeImmutable('2026-04-08 06:00:00'),
|
|
periodEnd: new DateTimeImmutable('2026-04-09 06:00:00'),
|
|
status: 'submitted',
|
|
autoFill: true,
|
|
metrics: [4 => 11],
|
|
);
|
|
|
|
$repository = \Mockery::mock(ReportRepository::class);
|
|
$repository->shouldReceive('save')
|
|
->once()
|
|
->andReturn(new SavedReportResult(88, $snapshot));
|
|
|
|
$repository->shouldReceive('findSnapshot')
|
|
->once()
|
|
->with(88)
|
|
->andReturn($snapshot);
|
|
|
|
$adapter = \Mockery::mock(LegacyReportServiceAdapter::class);
|
|
$adapter->shouldReceive('buildSnapshotFromInput')
|
|
->once()
|
|
->andReturn($snapshot);
|
|
|
|
$comparator = new CompareLegacyAndNewReportUseCase($repository, $adapter);
|
|
|
|
$auditLogger = \Mockery::mock(AuditLogger::class);
|
|
$auditLogger->shouldReceive('logComparison')->once();
|
|
|
|
$useCase = new GenerateReportUseCase(
|
|
reportRepository: $repository,
|
|
auditLogger: $auditLogger,
|
|
comparator: $comparator,
|
|
patientSource: $patientSource,
|
|
calculators: [],
|
|
compareBeforeCutover: true,
|
|
);
|
|
|
|
$result = $useCase->handle($input);
|
|
|
|
expect($result->reportId)->toBe(88)
|
|
->and($result->usedNewArchitecture)->toBeTrue()
|
|
->and($result->comparison?->status)->toBe('matched')
|
|
->and($result->comparison?->diff)->toBe([])
|
|
->and($result->comparison?->reportId)->toBe(88);
|
|
});
|