-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from onfido/add-tests
test: add tests for onfido-ruby library
- Loading branch information
Showing
27 changed files
with
1,127 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../shared_contexts/with_onfido' | ||
|
||
describe Onfido::Address do | ||
describe 'Address picker' do | ||
include_context 'with onfido' | ||
|
||
it 'finds an address based on post code' do | ||
post_code = 'S2 2DF' | ||
addresses_with_post_code = onfido_api.find_addresses(post_code).addresses | ||
|
||
expect(addresses_with_post_code[0].postcode).to eq post_code | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../shared_contexts/with_check' | ||
|
||
describe Onfido::Check do | ||
describe 'Checks' do | ||
include_context 'with check' | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
context 'US driving licence check' do | ||
let(:us_driving_licence_builder) do | ||
Onfido::UsDrivingLicenceBuilder.new({ | ||
id_number: '12345', | ||
issue_state: 'GA', | ||
}) | ||
end | ||
|
||
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 | ||
|
||
it 'lists checks' do | ||
list_of_checks = onfido_api.list_checks(applicant_id) | ||
|
||
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 '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 | ||
|
||
it 'restarts a check' do | ||
onfido_api.resume_check(check_id) | ||
end | ||
|
||
it 'downloads a check' do | ||
file = onfido_api.download_check(check_id) | ||
|
||
expect(file.size).to be > 0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../shared_contexts/with_document' | ||
|
||
describe Onfido::Document do | ||
describe 'Documents' do | ||
include_context 'with document' | ||
|
||
it 'uploads a document' do | ||
expect(document).not_to be_nil | ||
expect(document.id).not_to be_empty | ||
expect(document.file_name).to eq('sample_driving_licence.png') | ||
expect(document).to be_an_instance_of(Onfido::Document) | ||
end | ||
|
||
it 'lists documents' do | ||
list_of_documents = onfido_api.list_documents(applicant_id) | ||
|
||
expect(list_of_documents).to be_an_instance_of(Onfido::DocumentsList) | ||
expect(list_of_documents.documents.size).to be > 0 | ||
end | ||
|
||
it 'finds a document' do | ||
get_document = onfido_api.find_document(document_id) | ||
|
||
expect(get_document).to be_an_instance_of(Onfido::Document) | ||
expect(get_document.id).to eq document_id | ||
end | ||
|
||
it 'downloads a document' do | ||
file = onfido_api.download_document(document_id) | ||
|
||
expect(file.size).to be > 0 | ||
end | ||
|
||
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| | ||
expect(e.code).to eq(404) | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../shared_contexts/with_document' | ||
|
||
describe Onfido::Extraction do | ||
describe 'Extraction' do | ||
include_context 'with document' | ||
|
||
it 'performs extraction on a document' do | ||
extraction = onfido_api.extract( | ||
Onfido::ExtractRequest.new({ | ||
'document_id': document_id | ||
}) | ||
) | ||
|
||
expect(extraction).not_to be_nil | ||
expect(extraction).to be_an_instance_of Onfido::Extraction | ||
expect(extraction.document_id).to eq document_id | ||
|
||
document_classification = extraction.document_classification | ||
extracted_data = extraction.extracted_data | ||
|
||
# Check response body: document classification | ||
expect(document_classification).not_to be_nil | ||
expect(document_classification.document_type).to eq Onfido::DocumentTypes::DRIVING_LICENCE | ||
expect(document_classification.issuing_country).to eq Onfido::CountryCodes::GBR | ||
|
||
# Check response body: extracted data | ||
expect(extracted_data).not_to be_nil | ||
expect(extracted_data.date_of_birth).to eq Date.parse('1976-03-11') | ||
expect(extracted_data.date_of_expiry).to eq Date.parse('2031-05-28') | ||
expect(extracted_data.document_number).to eq '200407512345' | ||
expect(extracted_data.first_name).to eq 'SARAH' | ||
expect(extracted_data.last_name).to eq 'MORGAN' | ||
expect(extracted_data.gender).to eq 'Female' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../shared_contexts/with_applicant' | ||
|
||
describe Onfido::IdPhoto do | ||
describe 'Id Photo' do | ||
include_context 'with applicant' | ||
|
||
let(:id_photo) do | ||
onfido_api.upload_id_photo( | ||
applicant_id: applicant_id, | ||
file: File.new('spec/integrations/media/sample_photo.png') | ||
) | ||
end | ||
let!(:id_photo_id) { id_photo.id } | ||
|
||
it 'uploads a Id photo' do | ||
expect(id_photo).not_to be_nil | ||
expect(id_photo_id).not_to be_empty | ||
expect(id_photo).to be_an_instance_of Onfido::IdPhoto | ||
expect(id_photo.file_name).to eq "#{id_photo_id}.png" | ||
end | ||
|
||
it 'lists id photos' do | ||
id_photos = onfido_api.list_id_photos(applicant_id) | ||
|
||
expect(id_photos.id_photos.length).to be > 0 | ||
expect(id_photos).to be_an_instance_of Onfido::IDPhotosList | ||
end | ||
|
||
it 'retrieves id photo' do | ||
get_id_photo = onfido_api.find_id_photo(id_photo_id) | ||
|
||
expect(get_id_photo).to be_an_instance_of Onfido::IdPhoto | ||
expect(get_id_photo.id).to eq id_photo_id | ||
end | ||
|
||
it 'downloads id photo' do | ||
file = onfido_api.download_id_photo(id_photo_id) | ||
|
||
expect(file.length).to be > 0 | ||
end | ||
|
||
it 'raises an error with the correct status code when trying to download an inexistent id photo' do | ||
inexistent_id_photo_id = '00000000-0000-0000-0000-000000000000' | ||
|
||
expect { | ||
onfido_api.download_id_photo(inexistent_id_photo_id) | ||
}.to raise_error(Onfido::ApiError) { |e| | ||
expect(e.message).to match(/the server returns an error/) | ||
expect(e.code).to eq(404) | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.