diff --git a/spec/integrations/workflow_run_spec.rb b/spec/integrations/workflow_run_spec.rb index d7276b8..2688f67 100644 --- a/spec/integrations/workflow_run_spec.rb +++ b/spec/integrations/workflow_run_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4bb1d26..6905ee1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 @@ -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