Skip to content

Commit

Permalink
CAT-1068: added basic e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoPetteruti-Onfido committed May 14, 2024
1 parent dd248fe commit eb33056
Show file tree
Hide file tree
Showing 53 changed files with 72 additions and 1,710 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
ruby-version: ['2.7', '3.0', '3.1', '3.2']

steps:
- uses: actions/checkout@v2
Expand All @@ -22,4 +22,14 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run tests
if: ${{ matrix.ruby-version == '3.2' &&
github.repository_owner == 'onfido' &&
github.actor != 'dependabot[bot]' }}
run: bundle exec rspec spec
env:
ONFIDO_API_TOKEN: ${{ secrets.ONFIDO_API_TOKEN }}
ONFIDO_SAMPLE_APPLICANT_ID: ${{ secrets.ONFIDO_SAMPLE_APPLICANT_ID }}
ONFIDO_SAMPLE_VIDEO_ID_1: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_1 }}
ONFIDO_SAMPLE_VIDEO_ID_2: ${{ secrets.ONFIDO_SAMPLE_VIDEO_ID_2 }}
ONFIDO_SAMPLE_MOTION_ID_1: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_1 }}
ONFIDO_SAMPLE_MOTION_ID_2: ${{ secrets.ONFIDO_SAMPLE_MOTION_ID_2 }}
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Changelog

## v 03th May 2024
## v2.9.0 24 November 2023

- Added `signed_evidence_file` method for WorkflowRuns
Expand Down
4 changes: 2 additions & 2 deletions lib/onfido/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def basic_auth(conn)
# @param [String] mime MIME
# @return [Boolean] True if the MIME is application/json
def json_mime?(mime)
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
end

# Deserialize the response to the given return type.
Expand Down Expand Up @@ -328,7 +328,7 @@ def convert_to_type(data, return_type)
# @param [String] filename the filename to be sanitized
# @return [String] the sanitized filename
def sanitize_filename(filename)
filename.gsub(/.*[\/\\]/, '')
filename.split(/[\/\\]/).last
end

def build_request_url(path, opts = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/onfido/webhook_event_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read_payload(event_body, signature)

raise(OnfidoInvalidSignatureError, "Invalid signature for webhook event") unless OpenSSL.secure_compare(signature, event_signature)

WebhookEvent.build_from_hash(JSON.parse(event_body)["payload"])
WebhookEvent.build_from_hash(JSON.parse(event_body))
end
end
end
13 changes: 0 additions & 13 deletions spec/integrations/address_spec.rb

This file was deleted.

112 changes: 29 additions & 83 deletions spec/integrations/applicant_spec.rb
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
Expand All @@ -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
64 changes: 0 additions & 64 deletions spec/integrations/check_spec.rb

This file was deleted.

75 changes: 0 additions & 75 deletions spec/integrations/document_spec.rb

This file was deleted.

23 changes: 0 additions & 23 deletions spec/integrations/extraction_spec.rb

This file was deleted.

Loading

0 comments on commit eb33056

Please sign in to comment.