Skip to content

Commit 9f86399

Browse files
test(fileService): add regression tests for mapSignerDetailsToSummary validation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent d07d494 commit 9f86399

1 file changed

Lines changed: 199 additions & 0 deletions

File tree

tests/php/Unit/Service/FileServiceTest.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,203 @@ public function testToArrayUsesSignerScopedSignRequestUuidForCurrentSignerUrl():
551551
$this->assertSame('file-uuid', $result['files'][0]['uuid']);
552552
$this->assertSame('libresign.page.getPdf:file-uuid', $result['files'][0]['file']);
553553
}
554+
555+
#[DataProvider('mapSignerDetailsToSummaryProvider')]
556+
public function testMapSignerDetailsToSummaryFiltersInvalidSigners(array $signers, array $expectedSummaries): void {
557+
$service = $this->createFileService();
558+
$reflectionMethod = new \ReflectionMethod(FileService::class, 'mapSignerDetailsToSummary');
559+
$reflectionMethod->setAccessible(true);
560+
561+
$result = $reflectionMethod->invokeArgs($service, [$signers]);
562+
563+
$this->assertEquals($expectedSummaries, $result);
564+
}
565+
566+
public static function mapSignerDetailsToSummaryProvider(): array {
567+
return [
568+
'valid signer with all required fields' => [
569+
'signers' => [
570+
[
571+
'signRequestId' => 1,
572+
'displayName' => 'John Doe',
573+
'email' => 'john@example.com',
574+
'signed' => null,
575+
'status' => 0,
576+
'statusText' => 'pending',
577+
],
578+
],
579+
'expectedSummaries' => [
580+
[
581+
'signRequestId' => 1,
582+
'displayName' => 'John Doe',
583+
'email' => 'john@example.com',
584+
'signed' => null,
585+
'status' => 0,
586+
'statusText' => 'pending',
587+
],
588+
],
589+
],
590+
'filters signer with null signRequestId' => [
591+
'signers' => [
592+
[
593+
'signRequestId' => null,
594+
'displayName' => 'John',
595+
'email' => 'john@example.com',
596+
'status' => 0,
597+
'statusText' => 'pending',
598+
],
599+
],
600+
'expectedSummaries' => [],
601+
],
602+
'filters signer with missing signRequestId' => [
603+
'signers' => [
604+
[
605+
'displayName' => 'John',
606+
'email' => 'john@example.com',
607+
'status' => 0,
608+
'statusText' => 'pending',
609+
],
610+
],
611+
'expectedSummaries' => [],
612+
],
613+
'converts numeric string signRequestId to integer' => [
614+
'signers' => [
615+
[
616+
'signRequestId' => '42',
617+
'displayName' => 'Jane',
618+
'email' => 'jane@example.com',
619+
'signed' => null,
620+
'status' => 0,
621+
'statusText' => 'pending',
622+
],
623+
],
624+
'expectedSummaries' => [
625+
[
626+
'signRequestId' => 42,
627+
'displayName' => 'Jane',
628+
'email' => 'jane@example.com',
629+
'signed' => null,
630+
'status' => 0,
631+
'statusText' => 'pending',
632+
],
633+
],
634+
],
635+
'filters signer with non-numeric string signRequestId' => [
636+
'signers' => [
637+
[
638+
'signRequestId' => 'invalid',
639+
'displayName' => 'Bob',
640+
'email' => 'bob@example.com',
641+
'status' => 0,
642+
'statusText' => 'pending',
643+
],
644+
],
645+
'expectedSummaries' => [],
646+
],
647+
'filters non-array signer entries' => [
648+
'signers' => [
649+
'not an array',
650+
null,
651+
123,
652+
],
653+
'expectedSummaries' => [],
654+
],
655+
'mixed valid and invalid signers' => [
656+
'signers' => [
657+
[
658+
'signRequestId' => 1,
659+
'displayName' => 'Valid',
660+
'email' => 'valid@example.com',
661+
'signed' => null,
662+
'status' => 0,
663+
'statusText' => 'pending',
664+
],
665+
[
666+
'signRequestId' => null,
667+
'displayName' => 'Invalid',
668+
'email' => 'invalid@example.com',
669+
'signed' => null,
670+
'status' => 0,
671+
'statusText' => 'pending',
672+
],
673+
[
674+
'signRequestId' => '2',
675+
'displayName' => 'AlsoValid',
676+
'email' => 'also@example.com',
677+
'signed' => null,
678+
'status' => 1,
679+
'statusText' => 'signed',
680+
],
681+
],
682+
'expectedSummaries' => [
683+
[
684+
'signRequestId' => 1,
685+
'displayName' => 'Valid',
686+
'email' => 'valid@example.com',
687+
'signed' => null,
688+
'status' => 0,
689+
'statusText' => 'pending',
690+
],
691+
[
692+
'signRequestId' => 2,
693+
'displayName' => 'AlsoValid',
694+
'email' => 'also@example.com',
695+
'signed' => null,
696+
'status' => 1,
697+
'statusText' => 'signed',
698+
],
699+
],
700+
],
701+
'preserves identifyMethods when present' => [
702+
'signers' => [
703+
[
704+
'signRequestId' => 1,
705+
'displayName' => 'John',
706+
'email' => 'john@example.com',
707+
'signed' => null,
708+
'status' => 0,
709+
'statusText' => 'pending',
710+
'identifyMethods' => ['cpf', 'email'],
711+
],
712+
],
713+
'expectedSummaries' => [
714+
[
715+
'signRequestId' => 1,
716+
'displayName' => 'John',
717+
'email' => 'john@example.com',
718+
'signed' => null,
719+
'status' => 0,
720+
'statusText' => 'pending',
721+
'identifyMethods' => ['cpf', 'email'],
722+
],
723+
],
724+
],
725+
'type-casts string fields to proper types' => [
726+
'signers' => [
727+
[
728+
'signRequestId' => 5,
729+
'displayName' => 123,
730+
'email' => 456.78,
731+
'signed' => null,
732+
'status' => '7',
733+
'statusText' => 890,
734+
],
735+
],
736+
'expectedSummaries' => [
737+
[
738+
'signRequestId' => 5,
739+
'displayName' => '123',
740+
'email' => '456.78',
741+
'signed' => null,
742+
'status' => 7,
743+
'statusText' => '890',
744+
],
745+
],
746+
],
747+
'empty signers list' => [
748+
'signers' => [],
749+
'expectedSummaries' => [],
750+
],
751+
];
752+
}
554753
}

0 commit comments

Comments
 (0)