Skip to content

Commit

Permalink
Add schedule to CI, fix and improve tests after library refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
dvacca-onfido committed Oct 21, 2024
1 parent ca06f97 commit 21f705b
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
release:
types:
- published
schedule:
- cron: "0 16 * * 0" # Every Sunday, 4 hours after midday

jobs:
integration-tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/integrations/applicant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spec/integrations/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/integrations/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion spec/integrations/qualified_electronic_signature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions spec/integrations/workflow_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/shared_contexts/with_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/shared_contexts/with_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions spec/studio_webhook_event_verifier_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 21f705b

Please sign in to comment.