Skip to content

Commit

Permalink
test: add timeline file tests and clean up applicants and webhooks af…
Browse files Browse the repository at this point in the history
…ter the tests run
  • Loading branch information
sofia-gomes-onfido committed Jun 4, 2024
1 parent b97e996 commit 167c866
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/integrations/workflow_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,34 @@

expect(file.size).to be > 0
end

context 'with start -> approved workflow' do
let(:workflow_id) { '221f9d24-cf72-4762-ac4a-01bf3ccc09dd' }

it 'generates a timeline file' do
repeat_request_until_status_changes('approved') do
onfido_api.find_workflow_run(workflow_run_id)
end

workflow_timeline_file_data = onfido_api.create_timeline_file(workflow_run_id)

expect(workflow_timeline_file_data).to be_an_instance_of Onfido::TimelineFileReference
expect(workflow_timeline_file_data.workflow_timeline_file_id).to_not be_nil
expect(workflow_timeline_file_data.href).to_not be_nil
end

it 'finds a timeline file' do
repeat_request_until_status_changes('approved') do
onfido_api.find_workflow_run(workflow_run_id)
end

timeline_file_id = onfido_api.create_timeline_file(workflow_run_id).workflow_timeline_file_id
file = repeat_request_unti_http_code_changes do
onfido_api.find_timeline_file(workflow_run_id, timeline_file_id)
end

expect(file.size).to be > 0
end
end
end
end
52 changes: 52 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@
config.warnings = false
config.expose_dsl_globally = true

config.after(:suite) do
# clean-up applicants and webhooks
sample_applicant_id = ENV['ONFIDO_SAMPLE_APPLICANT_ID']
onfido_api = Onfido::DefaultApi.new

applicants = onfido_api.list_applicants(
page: 1,
per_page: 100,
include_deleted: false,
).applicants

applicants.each do |applicant|
if applicant.id != sample_applicant_id
begin
onfido_api.delete_applicant(applicant.id)
rescue Onfido::ApiError
# ignore failures during cleanup
end
end
end

webhooks = onfido_api.list_webhooks().webhooks

webhooks.each do |webhook|
begin
onfido_api.delete_webhook(webhook.id)
rescue Onfido::ApiError
# ignore failures during cleanup
end
end
end

# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
Expand Down Expand Up @@ -53,3 +85,23 @@ def repeat_request_until_status_changes(expected_status, max_retries = 10,

instance
end

def repeat_request_unti_http_code_changes(max_retries = 10,
interval = 1, &proc)
# max_retries --> how many times to retry the request
# interval --> how many seconds to wait until the next retry
# proc --> code containing the request

iteration = 0
while iteration <= max_retries
begin
instance = proc.call
break
rescue Onfido::ApiError
sleep(interval)
iteration += 1
end
end

instance
end

0 comments on commit 167c866

Please sign in to comment.