-
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.
- Loading branch information
1 parent
dd248fe
commit eb33056
Showing
53 changed files
with
72 additions
and
1,710 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
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# frozen_string_literal: true | ||
require 'onfido' | ||
|
||
describe Onfido::Applicant do | ||
include_context 'fake onfido api' | ||
Onfido.configure do |config| | ||
config.api_token = ENV["ONFIDO_API_TOKEN"] | ||
config.debugging = true | ||
config.region = config.region[:EU] | ||
end | ||
|
||
subject(:applicant) { onfido.applicant } | ||
describe Onfido::Applicant do | ||
|
||
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' } | ||
let(:params) do | ||
|
@@ -27,90 +31,32 @@ | |
'location' => { | ||
'ip_address' => '127.0.0.1', | ||
'country_of_residence' => 'GBR' | ||
}, | ||
'phone_number' => '910100100' | ||
} | ||
} | ||
end | ||
|
||
describe '#create' do | ||
# Need to find a better way of testing that the request is not malformed. | ||
# Currently this runs for every feature spec. The fact that it's under here | ||
# is only for semantic reasons | ||
|
||
it 'serializes the payload correctly' do | ||
WebMock.after_request do |request_signature, _response| | ||
if request_signature.uri.path == 'v3.6/applicants' | ||
expect(Rack::Utils.parse_nested_query(request_signature.body)) | ||
.to eq(params) | ||
end | ||
end | ||
end | ||
|
||
it 'creates an applicant' do | ||
response = applicant.create(params) | ||
expect(response['id']).not_to be_nil | ||
end | ||
end | ||
|
||
describe '#update' do | ||
it 'updates an applicant' do | ||
response = applicant.update(applicant_id, params) | ||
|
||
expect(response['id']).to eq(applicant_id) | ||
end | ||
end | ||
|
||
describe '#find' do | ||
it 'returns the applicant' do | ||
response = applicant.find(applicant_id) | ||
|
||
expect(response['id']).to eq(applicant_id) | ||
end | ||
end | ||
|
||
describe '#destroy' do | ||
it 'returns success code' do | ||
expect { applicant.destroy(applicant_id) }.not_to raise_error | ||
end | ||
let(:onfido_api) do | ||
Onfido::DefaultApi.new | ||
end | ||
|
||
describe '#all' do | ||
context 'with the default page and per page params' do | ||
it 'returns all the applicants' do | ||
response = applicant.all | ||
|
||
expect(response['applicants'].size).to eq(2) | ||
end | ||
end | ||
|
||
context 'with specific range of results for a page' do | ||
it 'returns the specified applicants' do | ||
response = applicant.all(page: 1, per_page: 1) | ||
|
||
expect(response['applicants'].size).to eq(1) | ||
end | ||
end | ||
end | ||
|
||
describe '#restore' do | ||
context 'an applicant scheduled for deletion' do | ||
it 'returns nil' do | ||
expect(applicant.restore(applicant_id)).to be_nil | ||
end | ||
end | ||
|
||
context 'an applicant not scheduled for deletion' do | ||
it 'returns an error' do | ||
applicant_id = 'a2fb9c62-ab10-4898-a8ec-342c4b552ad5' | ||
|
||
expect { applicant.restore(applicant_id) }.to raise_error do |error| | ||
expect(error).to be_a(Onfido::RequestError) | ||
expect(error.message).to eq('There was a validation error on this request') | ||
expect(error.fields).to eq( | ||
'Applicant a2fb9c62-ab10-4898-a8ec-342c4b552ad5 is not scheduled for deletion' | ||
) | ||
end | ||
end | ||
describe '#create' do | ||
it 'creates an applicant' do | ||
applicant = onfido_api.create_applicant(params) | ||
expect(applicant.id).not_to be_nil | ||
expect(applicant.first_name).to eq 'Chandler' | ||
expect(applicant.last_name).to eq 'Bing' | ||
expect(applicant.email).to eq '[email protected]' | ||
expect(applicant.dob).to eq Date.parse('1968-04-08') | ||
expect(applicant.address.flat_number).to eq '4' | ||
expect(applicant.address.building_number).to eq '100' | ||
expect(applicant.address.building_name).to eq 'Awesome Building' | ||
expect(applicant.address.street).to eq 'Main Street' | ||
expect(applicant.address.sub_street).to eq 'A sub street' | ||
expect(applicant.address.town).to eq 'London' | ||
expect(applicant.address.postcode).to eq 'SW4 6EH' | ||
expect(applicant.address.country).to eq 'GBR' | ||
expect(applicant.location.ip_address).to eq '127.0.0.1' | ||
expect(applicant.location.country_of_residence).to eq 'GBR' | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.