From 21f705b5d6b069dcc016a5681fc7baebf1ae3e28 Mon Sep 17 00:00:00 2001 From: Davide Vacca Date: Mon, 21 Oct 2024 15:08:02 +0200 Subject: [PATCH] Add schedule to CI, fix and improve tests after library refresh --- .github/workflows/ruby.yml | 2 + ...=> classic_webhook_event_verifier_spec.rb} | 8 ++-- spec/integrations/applicant_spec.rb | 6 ++- spec/integrations/check_spec.rb | 8 ++-- spec/integrations/document_spec.rb | 2 +- .../qualified_electronic_signature_spec.rb | 2 +- spec/integrations/workflow_run_spec.rb | 6 +-- spec/shared_contexts/with_check.rb | 1 + spec/shared_contexts/with_document.rb | 2 +- spec/studio_webhook_event_verifier_spec.rb | 39 +++++++++++++++++++ 10 files changed, 61 insertions(+), 15 deletions(-) rename spec/{webhook_event_verifier_spec.rb => classic_webhook_event_verifier_spec.rb} (84%) create mode 100644 spec/studio_webhook_event_verifier_spec.rb diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index c7848b6..0416659 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -11,6 +11,8 @@ on: release: types: - published + schedule: + - cron: "0 16 * * 0" # Every Sunday, 4 hours after midday jobs: integration-tests: diff --git a/spec/webhook_event_verifier_spec.rb b/spec/classic_webhook_event_verifier_spec.rb similarity index 84% rename from spec/webhook_event_verifier_spec.rb rename to spec/classic_webhook_event_verifier_spec.rb index 3829669..a32cd42 100644 --- a/spec/webhook_event_verifier_spec.rb +++ b/spec/classic_webhook_event_verifier_spec.rb @@ -15,13 +15,13 @@ it "returns the decoded event payload" do expected_payload = JSON.parse(event_body)["payload"] expected_webhook_event = Onfido::WebhookEvent.new({ payload: Onfido::WebhookEventPayload.build_from_hash(expected_payload) }) - + webhook_event = subject.read_payload(event_body, sig) expect(webhook_event.payload).to eq(expected_webhook_event.payload) - expect(webhook_event.payload.resource_type).to eq('check') - expect(webhook_event.payload.action).to eq('check.completed') + expect(webhook_event.payload.resource_type).to eq(Onfido::WebhookEventResourceType::CHECK) + expect(webhook_event.payload.action).to eq(Onfido::WebhookEventType::CHECK_COMPLETED) expect(webhook_event.payload.object.id).to eq('f2302f45-227d-413d-ad61-09ec077a086a') - expect(webhook_event.payload.object.status).to eq('complete') + expect(webhook_event.payload.object.status).to eq(Onfido::WebhookEventObjectStatus::COMPLETE) expect(webhook_event.payload.object.completed_at_iso8601).to eq(Time.parse('2024-04-04T09:21:21Z')) expect(webhook_event.payload.object.href).to eq('https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a') end diff --git a/spec/integrations/applicant_spec.rb b/spec/integrations/applicant_spec.rb index 3c04b8b..f7e472a 100644 --- a/spec/integrations/applicant_spec.rb +++ b/spec/integrations/applicant_spec.rb @@ -27,7 +27,11 @@ 'location' => { 'ip_address' => '127.0.0.1', 'country_of_residence' => 'GBR' - } + }, + 'consents' => [{ + 'name' => Onfido::ApplicantConsentName::PRIVACY_NOTICES_READ, + 'granted' => true + }] } applicant = onfido_api.create_applicant(params) diff --git a/spec/integrations/check_spec.rb b/spec/integrations/check_spec.rb index ca3823c..16422bb 100644 --- a/spec/integrations/check_spec.rb +++ b/spec/integrations/check_spec.rb @@ -11,7 +11,7 @@ expect(check).to be_an_instance_of Onfido::Check expect(check.applicant_id).to eq applicant_id expect(check.report_ids.size).to eq 2 - expect(check.status).to eq 'in_progress' + expect(check.status).to eq Onfido::CheckStatus::IN_PROGRESS end context 'consider check' do @@ -47,7 +47,7 @@ us_driving_licence: us_driving_licence_builder, }) end - + it 'creates a driving licence check' do expect(check).not_to be_nil expect(check).to be_an_instance_of Onfido::Check @@ -65,9 +65,9 @@ it 'finds a check' do get_check = onfido_api.find_check(check_id) - + expect(get_check).to be_an_instance_of(Onfido::Check) - expect(get_check.id).to eq check_id + expect(get_check.id).to eq check_id end it 'restarts a check' do diff --git a/spec/integrations/document_spec.rb b/spec/integrations/document_spec.rb index 1ca9692..2e03594 100644 --- a/spec/integrations/document_spec.rb +++ b/spec/integrations/document_spec.rb @@ -35,7 +35,7 @@ it 'cannot download an inexistent document' do inexistent_document_id = '00000000-0000-0000-0000-000000000000' - + expect { onfido_api.download_document(inexistent_document_id) }.to raise_error(Onfido::ApiError) { |e| diff --git a/spec/integrations/qualified_electronic_signature_spec.rb b/spec/integrations/qualified_electronic_signature_spec.rb index cfc3b29..d885d75 100644 --- a/spec/integrations/qualified_electronic_signature_spec.rb +++ b/spec/integrations/qualified_electronic_signature_spec.rb @@ -27,7 +27,7 @@ let!(:workflow_run_id) { workflow_run.id } let(:file_id) do - task = onfido_api.list_tasks(workflow_run_id)[0] + task = onfido_api.list_tasks(workflow_run_id)[1] output = repeat_request_until_task_output_changes( max_retries = 10, diff --git a/spec/integrations/workflow_run_spec.rb b/spec/integrations/workflow_run_spec.rb index 2688f67..ff6e92b 100644 --- a/spec/integrations/workflow_run_spec.rb +++ b/spec/integrations/workflow_run_spec.rb @@ -9,7 +9,7 @@ it 'creates a workflow run' do expect(workflow_run).to be_an_instance_of Onfido::WorkflowRun expect(workflow_run.applicant_id).to eq applicant_id - expect(workflow_run.status).to eq 'awaiting_input' + expect(workflow_run.status).to eq Onfido::WorkflowRunStatus::AWAITING_INPUT end context 'workflow run with custom inputs' do @@ -24,11 +24,11 @@ } }) end - + it 'creates a workflow run with custom inputs' do expect(workflow_run).to be_an_instance_of Onfido::WorkflowRun expect(workflow_run.workflow_id).to eq workflow_id - expect(workflow_run.status).to eq 'approved' + expect(workflow_run.status).to eq Onfido::WorkflowRunStatus::APPROVED end end diff --git a/spec/shared_contexts/with_check.rb b/spec/shared_contexts/with_check.rb index f40ddfd..510a853 100644 --- a/spec/shared_contexts/with_check.rb +++ b/spec/shared_contexts/with_check.rb @@ -10,6 +10,7 @@ applicant_id: applicant_id, document_ids: [document_id], report_names: [Onfido::ReportName::DOCUMENT, Onfido::ReportName::IDENTITY_ENHANCED], + privacy_notices_read_consent_given: true }) end diff --git a/spec/shared_contexts/with_document.rb b/spec/shared_contexts/with_document.rb index 95a6b64..d1a1be5 100644 --- a/spec/shared_contexts/with_document.rb +++ b/spec/shared_contexts/with_document.rb @@ -8,6 +8,6 @@ let(:document_file_name) { 'sample_driving_licence.png' } let(:document_file) { File.open("spec/integrations/media/#{document_file_name}") } - let(:document) { onfido_api.upload_document('passport', applicant_id, document_file) } + let(:document) { onfido_api.upload_document(Onfido::DocumentTypes::PASSPORT, applicant_id, document_file) } let!(:document_id) { document.id } end diff --git a/spec/studio_webhook_event_verifier_spec.rb b/spec/studio_webhook_event_verifier_spec.rb new file mode 100644 index 0000000..fc83096 --- /dev/null +++ b/spec/studio_webhook_event_verifier_spec.rb @@ -0,0 +1,39 @@ +require 'onfido/webhook_event_verifier' +require 'spec_helper' + +describe Onfido::WebhookEventVerifier do + subject { described_class.new('YKOC6mkBxi6yK2zlUIrLMvsJMFEZObP5') } + describe "#read_payload" do + let(:event_body) { '{"payload":{"resource_type":"workflow_task","action":"workflow_task.started","object":{"id":"profile_1eb92","task_spec_id":"profile_1eb92","task_def_id":"profile_data","workflow_run_id":"bc77c6e5-753a-4580-96a6-aaed3e5a8d19","status":"started","started_at_iso8601":"2024-07-10T12:49:09Z","href":"https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92"},"resource":{"created_at":"2024-07-10T12:49:09Z","id":"profile_1eb92","workflow_run_id":"bc77c6e5-753a-4580-96a6-aaed3e5a8d19","updated_at":"2024-07-10T12:49:09Z","input":{},"task_def_version":null,"task_def_id":"profile_data","output":null}}}' } + let(:sig) { "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfa" } + it "raises an exception when the signature is invalid" do + expect do + subject.read_payload(event_body, "c95a5b785484f6fa1bc25f381b5595d66bf85cb442eefb06aa007802ee6a4dfb") + end.to raise_error(Onfido::OnfidoInvalidSignatureError, "Invalid signature for webhook event") + end + + it "returns the decoded event payload" do + expected_payload = JSON.parse(event_body)["payload"] + expected_webhook_event = Onfido::WebhookEvent.new({ payload: Onfido::WebhookEventPayload.build_from_hash(expected_payload) }) + + webhook_event = subject.read_payload(event_body, sig) + expect(webhook_event.payload).to eq(expected_webhook_event.payload) + expect(webhook_event.payload.resource_type).to eq(Onfido::WebhookEventResourceType::WORKFLOW_TASK) + expect(webhook_event.payload.action).to eq(Onfido::WebhookEventType::WORKFLOW_TASK_STARTED) + + expect(webhook_event.payload.object.id).to eq('profile_1eb92') + expect(webhook_event.payload.object.status).to eq(Onfido::WebhookEventObjectStatus::STARTED) + expect(webhook_event.payload.object.started_at_iso8601).to eq(Time.parse('2024-07-10T12:49:09Z')) + expect(webhook_event.payload.object.href).to eq('https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92') + + expect(webhook_event.payload.resource.created_at).to eq(Time.parse('2024-07-10T12:49:09Z')) + expect(webhook_event.payload.resource.id).to eq('profile_1eb92') + expect(webhook_event.payload.resource.workflow_run_id).to eq('bc77c6e5-753a-4580-96a6-aaed3e5a8d19') + expect(webhook_event.payload.resource.updated_at).to eq(Time.parse('2024-07-10T12:49:09Z')) + expect(webhook_event.payload.resource.input).to eq({}) + expect(webhook_event.payload.resource.task_def_version).to eq(nil) + expect(webhook_event.payload.resource.task_def_id).to eq('profile_data') + expect(webhook_event.payload.resource.output).to eq(nil) + end + end +end