diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8b7af98..44c6007 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -18,6 +18,8 @@ on: release: types: - published + schedule: + - cron: "0 15 * * 0" # Every Sunday, 3 hours after midday jobs: integration-tests: diff --git a/test/WebhookEventVerifierTest.php b/test/ClassicWebhookEventVerifierTest.php similarity index 67% rename from test/WebhookEventVerifierTest.php rename to test/ClassicWebhookEventVerifierTest.php index 3927aa8..3dac07d 100644 --- a/test/WebhookEventVerifierTest.php +++ b/test/ClassicWebhookEventVerifierTest.php @@ -6,33 +6,19 @@ use Onfido as Onfido; -class WebhookEventVerifierTest extends TestCase +class ClassicWebhookEventVerifierTest extends TestCase { private static $rawEvent = "{\"payload\":{\"resource_type\":\"check\",\"action\":\"check.completed\",\"object\":{\"id\":\"f2302f45-227d-413d-ad61-09ec077a086a\",\"status\":\"complete\",\"completed_at_iso8601\":\"2024-04-04T09:21:21Z\",\"href\":\"https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a\"}}}"; private static $webhookToken = "wU99mE6jJ7nXOLFwZ0tJymM1lpI15pZh"; private static $webhookEventVerifier; - private static $expectedEvent; - /** * Setup before running any test case */ public static function setUpBeforeClass(): void { self::$webhookEventVerifier = new Onfido\WebhookEventVerifier(self::$webhookToken); - - self::$expectedEvent = new Onfido\Model\WebhookEvent( - [ 'payload' => new Onfido\Model\WebhookEventPayload( - [ 'action' => Onfido\Model\WebhookEventType::CHECK_COMPLETED, - 'resource_type' => 'check', - 'object' => new Onfido\Model\WebhookEventPayloadObject( - [ 'id' => 'f2302f45-227d-413d-ad61-09ec077a086a', - 'href' => 'https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a', - 'status' => 'complete', - 'completed_at_iso8601' => '2024-04-04T09:21:21Z' ]) - ]) - ]); } public function testValidSignature(): void @@ -44,10 +30,10 @@ public function testValidSignature(): void $object = $payload->getObject(); $this->assertSame(Onfido\Model\WebhookEventType::CHECK_COMPLETED, $payload->getAction()); - $this->assertSame('check', $payload->getResourceType()); + $this->assertSame(Onfido\Model\WebhookEventResourceType::CHECK, $payload->getResourceType()); $this->assertSame('f2302f45-227d-413d-ad61-09ec077a086a', $object->getId()); $this->assertSame('https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a', $object->getHref()); - $this->assertSame('complete', $object->getStatus()); + $this->assertSame(Onfido\Model\WebhookEventObjectStatus::COMPLETE, $object->getStatus()); $this->assertSame('2024-04-04T09:21:21+00:00', $object->getCompletedAtIso8601()->format('c')); } diff --git a/test/OnfidoTestCase.php b/test/OnfidoTestCase.php index 91aa269..f0d9735 100644 --- a/test/OnfidoTestCase.php +++ b/test/OnfidoTestCase.php @@ -62,6 +62,12 @@ protected function createApplicant(): Onfido\Model\Applicant ]), 'email' => 'first.last@gmail.com', 'phone_number' => '351911111111', + 'consents' => [ + new Onfido\Model\ApplicantConsentBuilder([ + 'name' => Onfido\Model\ApplicantConsentName::PRIVACY_NOTICES_READ, + 'granted' => true + ]) + ] ] ), ); @@ -106,7 +112,7 @@ protected static function cleanUpWebhooks(): void protected function uploadDocument(string $applicantId): Onfido\Model\Document { return self::$onfido->uploadDocument( - 'passport', + Onfido\Model\DocumentTypes::PASSPORT, $applicantId, new \SplFileObject('test/media/sample_driving_licence.png') ); @@ -220,6 +226,7 @@ protected function repeatRequestUntilHttpCodeChanges( $sleepTime = 1 ) { + $instance = null; $iteration = 0; while($iteration <= $maxRetries) { try { diff --git a/test/Resource/ChecksTest.php b/test/Resource/ChecksTest.php index f381d11..21165a3 100644 --- a/test/Resource/ChecksTest.php +++ b/test/Resource/ChecksTest.php @@ -5,6 +5,7 @@ use Onfido\Test\OnfidoTestCase as OnfidoTestCase; use Onfido\Model\ReportName as ReportName; use Onfido\Model\Check as Check; +use Onfido\Model\CheckStatus as CheckStatus; use Onfido\Model\CheckBuilder as CheckBuilder; use Onfido\Model\UsDrivingLicenceBuilder as UsDrivingLicenceBuilder; @@ -31,7 +32,7 @@ public function setUp(): void public function testCreateCheck(): void { $this->assertSame($this->applicantId, $this->check->getApplicantId()); - $this->assertSame(Check::STATUS_IN_PROGRESS, $this->check->getStatus()); + $this->assertSame(CheckStatus::IN_PROGRESS, $this->check->getStatus()); $this->assertSame(2, sizeOf($this->check->getReportIds())); } @@ -41,11 +42,13 @@ public function testCreateConsiderCheck(): void 'applicant_id' => $this->applicantId, 'document_ids' => [$this->documentId], 'report_names' => [ReportName::DOCUMENT], - 'consider' => [ReportName::DOCUMENT] + 'consider' => [ReportName::DOCUMENT], + 'privacy_notices_read_consent_given' => true ]); $check = $this->createCheck($checkBuilder); $this->assertSame($this->applicantId, $check->getApplicantId()); + $this->assertSame(true, $check->getPrivacyNoticesReadConsentGiven()); } public function testCreateDrivingLicenceCheck(): void diff --git a/test/Resource/QualifiedElectronicSignatureTest.php b/test/Resource/QualifiedElectronicSignatureTest.php index eae6366..bf127a6 100644 --- a/test/Resource/QualifiedElectronicSignatureTest.php +++ b/test/Resource/QualifiedElectronicSignatureTest.php @@ -25,8 +25,8 @@ public function testDownloadQesDocument(): void ] ]); $workflowRun = $this->createWorkflowRun($workflowRunBuilder); - - $task = self::$onfido->listTasks($workflowRun["id"])[0]; + + $task = self::$onfido->listTasks($workflowRun["id"])[1]; $workflowRunId = $workflowRun["id"]; $taskId = $task->getId(); diff --git a/test/Resource/WorkflowRunOutputsTest.php b/test/Resource/WorkflowRunOutputsTest.php index 36373b4..df896f3 100644 --- a/test/Resource/WorkflowRunOutputsTest.php +++ b/test/Resource/WorkflowRunOutputsTest.php @@ -4,6 +4,7 @@ use Onfido\Test\OnfidoTestCase as OnfidoTestCase; use Onfido\Model\WorkflowRun as WorkflowRun; +use Onfido\Model\WorkflowRunStatus as WorkflowRunStatus; use Onfido\Model\CompleteTaskBuilder as CompleteTaskBuilder; class WorkflowRunOutputsTest extends OnfidoTestCase @@ -56,13 +57,13 @@ public function testProfileDataCaptureAsOutput(): void $workflowRunOutputs = $this->repeatRequestUntilStatusChanges( $this->findWorkflowRunFn, [$workflowRunId], - WorkflowRun::STATUS_APPROVED + WorkflowRunStatus::APPROVED )->getOutput(); // Can't compare output with profileData directly due to issues with types, // so converting the output into array and comparing key by key value // (without the address which also causes issues and is compared separately) - $keysExceptAddress = array_filter(array_keys($this->profileData), + $keysExceptAddress = array_filter(array_keys($this->profileData), function($key) { return $key !== 'address'; } @@ -96,7 +97,7 @@ public function testDocumentAndFacialSimilarityReportAsOutput() 'last_name' => 'Last' ]]) ); - + $tasks = self::$onfido->listTasks($workflowRunId); $documentCaptureTaskId = $this->getTaskIdByPartialId($tasks, 'document'); self::$onfido->completeTask( @@ -120,7 +121,7 @@ public function testDocumentAndFacialSimilarityReportAsOutput() $workflowRunOutputs = $this->repeatRequestUntilStatusChanges( $this->findWorkflowRunFn, [$workflowRunId], - WorkflowRun::STATUS_APPROVED + WorkflowRunStatus::APPROVED )->getOutput(); $documentReportOutput = (array) $workflowRunOutputs['doc']; diff --git a/test/Resource/WorkflowRunsTest.php b/test/Resource/WorkflowRunsTest.php index 6ec2aca..366d26e 100644 --- a/test/Resource/WorkflowRunsTest.php +++ b/test/Resource/WorkflowRunsTest.php @@ -4,6 +4,7 @@ use Onfido\Test\OnfidoTestCase as OnfidoTestCase; use Onfido\Model\WorkflowRun as WorkflowRun; +use Onfido\Model\WorkflowRunStatus as WorkflowRunStatus; use Onfido\Model\WorkflowRunBuilder as WorkflowRunBuilder; class WorkflowRunsTest extends OnfidoTestCase @@ -22,7 +23,7 @@ public function setUp(): void public function testCreateWorkflowRun(): void { $this->assertSame($this->workflowId, $this->workflowRun->getWorkflowId()); - $this->assertSame(WorkflowRun::STATUS_AWAITING_INPUT, $this->workflowRun->getStatus()); + $this->assertSame(WorkflowRunStatus::AWAITING_INPUT, $this->workflowRun->getStatus()); } public function testCreateWorkflowRunWithCustomInputs(): void @@ -40,7 +41,7 @@ public function testCreateWorkflowRunWithCustomInputs(): void $workflowRun = $this->createWorkflowRun($workflowRunBuilder); $this->assertSame($workflowId, $workflowRun->getWorkflowId()); - $this->assertSame(WorkflowRun::STATUS_APPROVED, $workflowRun->getStatus()); + $this->assertSame(WorkflowRunStatus::APPROVED, $workflowRun->getStatus()); } public function testListWorkflowRuns(): void @@ -72,7 +73,7 @@ public function testGenerateTimelineFile(): void $this->repeatRequestUntilStatusChanges( $findWorkflowRunFn, [$workflowRunId], - WorkflowRun::STATUS_APPROVED + WorkflowRunStatus::APPROVED )->getOutput(); $workflowTimelineFileData = self::$onfido->createTimelineFile($workflowRunId); @@ -96,7 +97,7 @@ public function testDownloadTimelineFile(): void $this->repeatRequestUntilStatusChanges( $findWorkflowRunFn, [$workflowRunId], - WorkflowRun::STATUS_APPROVED + WorkflowRunStatus::APPROVED )->getOutput(); $workflowTimelineFileId = self::$onfido->createTimelineFile($workflowRunId) @@ -106,7 +107,7 @@ public function testDownloadTimelineFile(): void $getTimelineFileFn, [$workflowRunId, $workflowTimelineFileId] ); - + $this->assertGreaterThan(0, $file->getSize()); } } diff --git a/test/StudioWebhookEventVerifierTest.php b/test/StudioWebhookEventVerifierTest.php new file mode 100644 index 0000000..99f6edc --- /dev/null +++ b/test/StudioWebhookEventVerifierTest.php @@ -0,0 +1,57 @@ +readPayload(self::$rawEvent, $signature); + $payload = $event->getPayload(); + $object = $payload->getObject(); + + $this->assertSame(Onfido\Model\WebhookEventType::WORKFLOW_TASK_STARTED, $payload->getAction()); + $this->assertSame(Onfido\Model\WebhookEventResourceType::WORKFLOW_TASK, $payload->getResourceType()); + $this->assertSame('profile_1eb92', $object->getId()); + $this->assertSame('https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92', $object->getHref()); + $this->assertSame(Onfido\Model\WebhookEventObjectStatus::STARTED, $object->getStatus()); + $this->assertSame('2024-07-10T12:49:09+00:00', $object->getStartedAtIso8601()->format('c')); + + $resource = $payload->getResource(); + $this->assertSame('2024-07-10T12:49:09+00:00', $resource->getCreatedAt()->format('c')); + $this->assertSame('profile_1eb92', $resource->getId()); + $this->assertSame([], $resource->getInput()); + $this->assertSame(null, $resource->getOutput()); + $this->assertSame('profile_data', $resource->getTaskDefId()); + $this->assertSame(null, $resource->getTaskDefVersion()); + $this->assertSame('2024-07-10T12:49:09+00:00', $resource->getUpdatedAt()->format('c')); + $this->assertSame('bc77c6e5-753a-4580-96a6-aaed3e5a8d19', $resource->getWorkflowRunId()); + } + + public function testInvalidSignature() + { + $signature = "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfb"; + + $this->expectException(Onfido\OnfidoInvalidSignatureError::class); + $event = self::$webhookEventVerifier->readPayload(self::$rawEvent, $signature); + } +}