spec/integrations/check_spec.rb in onfido-2.9.0 vs spec/integrations/check_spec.rb in onfido-3.0.0

- old
+ new

@@ -1,64 +1,83 @@ # frozen_string_literal: true +require_relative '../shared_contexts/with_check' + describe Onfido::Check do - include_context 'fake onfido api' + describe 'Checks' do + include_context 'with check' - subject(:check) { onfido.check } - - let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' } - let(:check_id) { '8546921-123123-123123' } - - describe '#create' do - it 'creates a new check for an applicant' do - response = check.create( - applicant_id: applicant_id, - report_names: ['identity_enhanced'] - ) - expect(response['id']).not_to be_nil + it 'creates a check' do + expect(check).not_to be_nil + 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' end - end - describe '#find' do - it 'returns an existing check for the applicant' do - response = check.find(check_id) + context 'consider check' do + let(:check_builder) do + check_builder = Onfido::CheckBuilder.new({ + applicant_id: applicant_id, + document_ids: [document_id], + report_names: [Onfido::ReportName::DOCUMENT], + consider: [Onfido::ReportName::DOCUMENT], + }) + end - expect(response['id']).to eq(check_id) + it 'creates a consider check' do + expect(check).not_to be_nil + expect(check).to be_an_instance_of Onfido::Check + expect(check.applicant_id).to eq applicant_id + end end - it 'returns report_ids' do - response = check.find(check_id) + context 'US driving licence check' do + let(:us_driving_licence_builder) do + Onfido::UsDrivingLicenceBuilder.new({ + id_number: '12345', + issue_state: 'GA', + }) + end - expect(response['report_ids'].first).to be_a(String) + let(:check_builder) do + Onfido::CheckBuilder.new({ + applicant_id: applicant_id, + document_ids: [document_id], + report_names: [Onfido::ReportName::DOCUMENT], + 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 + expect(check.applicant_id).to eq applicant_id + end end - end - describe '#all' do - context 'with the default page and per page params' do - it 'returns all existing checks for the applicant' do - response = check.all(applicant_id) + it 'lists checks' do + list_of_checks = onfido_api.list_checks(applicant_id) - expect(response['checks'].size).to eq(1) - end + expect(list_of_checks).not_to be_nil + expect(list_of_checks).to be_an_instance_of Onfido::ChecksList + expect(list_of_checks.checks.size).to be > 0 end - it 'returns report_ids' do - response = check.all(applicant_id) - - expect(response['checks'].first['report_ids'].first).to be_a(String) + 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 end - end - describe '#resume' do - it 'returns success response' do - expect { check.resume(check_id) }.not_to raise_error + it 'restarts a check' do + onfido_api.resume_check(check_id) end - end - describe '#download' do - it 'returns the file data' do - response = check.download(check_id) + it 'downloads a check' do + file = onfido_api.download_check(check_id) - expect(response).not_to be_nil + expect(file.size).to be > 0 end end end