spec/integrations/workflow_run_spec.rb in onfido-2.9.0 vs spec/integrations/workflow_run_spec.rb in onfido-3.0.0
- old
+ new
@@ -1,54 +1,84 @@
# frozen_string_literal: true
+require_relative '../shared_contexts/with_workflow_run'
+
describe Onfido::WorkflowRun do
- include_context 'fake onfido api'
+ describe 'Workflow run' do
+ include_context 'with workflow run'
- subject(:workflow_run) { onfido.workflow_run }
+ 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'
+ end
- let(:workflow_run_id) { 'fcb73186-0733-4f6f-9c57-d9d5ef979443' }
- let(:params) do
- {
- 'a' => 'b'
- }
- end
-
- describe '#create' do
- it 'serializes the payload correctly' do
- WebMock.after_request do |request_signature, _response|
- if request_signature.uri.path == 'v3.6/workflow_run'
- expect(Rack::Utils.parse_nested_query(request_signature.body))
- .to eq(params)
- end
+ context 'workflow run with custom inputs' do
+ let(:workflow_id) { '45092b29-f220-479e-aa6f-a6f989baac4c' }
+ let(:workflow_run_builder) do
+ Onfido::WorkflowRunBuilder.new({
+ applicant_id: applicant_id,
+ workflow_id: workflow_id,
+ custom_data: {
+ age: 18,
+ is_employed: false
+ }
+ })
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'
+ end
end
- it 'creates a workflow run' do
- response = workflow_run.create(params)
- expect(response['id']).not_to be_nil
+ it 'lists workflow runs' do
+ list_of_workflow_runs = onfido_api.list_workflow_runs()
+
+ expect(list_of_workflow_runs[0]).to be_an_instance_of Onfido::WorkflowRun
+ expect(list_of_workflow_runs.size).to be > 0
end
- end
- describe '#find' do
- it 'returns the workflow run' do
- response = workflow_run.find(workflow_run_id)
+ it 'finds a workflow run' do
+ get_workflow_run = onfido_api.find_workflow_run(workflow_run_id)
- expect(response['id']).to eq(workflow_run_id)
+ expect(get_workflow_run).to be_an_instance_of Onfido::WorkflowRun
+ expect(get_workflow_run.id).to eq workflow_run_id
end
- end
- describe '#all' do
- it 'returns the workflow runs' do
- response = workflow_run.all({ page: 1, sort: 'asc' })
+ it 'downloads evidence file' do
+ file = onfido_api.download_signed_evidence_file(workflow_run_id)
- expect(response.count).to eq(2)
+ expect(file.size).to be > 0
end
- end
- describe '#evidence' do
- it 'returns the signed PDF' do
- response = workflow_run.evidence(workflow_run_id)
+ context 'with start -> approved workflow' do
+ let(:workflow_id) { '221f9d24-cf72-4762-ac4a-01bf3ccc09dd' }
- expect(response[0..4]).to eq('%PDF-')
+ 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