spec/integrations/live_photo_spec.rb in onfido-2.9.0 vs spec/integrations/live_photo_spec.rb in onfido-3.0.0
- old
+ new
@@ -1,64 +1,47 @@
# frozen_string_literal: true
-require 'tempfile'
+require_relative '../shared_contexts/with_live_photo'
describe Onfido::LivePhoto do
- include_context 'fake onfido api'
+ describe 'Live Photo' do
+ include_context 'with live photo'
- subject(:live_photo) { onfido.live_photo }
-
- describe '#create' do
- let(:params) { { applicant_id: '123456', file: file } }
-
- context 'with a File-like object to upload' do
- let(:file) { Tempfile.new(['passport', '.jpg']) }
-
- after do
- file.close
- file.unlink
- end
-
- it 'creates a new photo' do
- response = live_photo.create(**params)
-
- expect(response['id']).not_to be_nil
- end
+ it 'uploads a live photo' do
+ expect(live_photo).not_to be_nil
+ expect(live_photo_id).not_to be_empty
+ expect(live_photo.file_name).to eq('sample_photo.png')
+ expect(live_photo).to be_an_instance_of Onfido::LivePhoto
end
- context 'passing in a non-File-like file to upload' do
- let(:file) { 'https://onfido.com/images/photo.jpg' }
+ it 'lists live photos' do
+ live_photos = onfido_api.list_live_photos(applicant_id)
- it 'raises an ArgumentError' do
- expect { live_photo.create(**params) }
- .to raise_error(ArgumentError, /must be a `File`-like object/)
- end
+ expect(live_photos.live_photos.length).to be > 0
+ expect(live_photos).to be_an_instance_of Onfido::LivePhotosList
end
- end
- describe '#find' do
- it 'returns the expected live photo' do
- live_photo_id = '3538c8f6-fdce-4745-9d34-fc246bc05aa1'
- response = live_photo.find(live_photo_id)
+ it 'retrieves live photo' do
+ live_photo = onfido_api.find_live_photo(live_photo_id)
- expect(response['id']).to eq(live_photo_id)
+ expect(live_photo_id).to eq(live_photo_id)
+ expect(live_photo).to be_an_instance_of Onfido::LivePhoto
end
- end
- describe '#all' do
- it 'returns list of documents' do
- applicant_id = '1030303-123123-123123'
- response = live_photo.all(applicant_id)
+ it 'downloads live photo' do
+ file = onfido_api.download_live_photo(live_photo_id)
- expect(response['live_photos']).not_to be_empty
+ expect(file.length).to be > 0
end
- end
- describe '#download' do
- it 'returns the file data' do
- live_photo_id = '3538c8f6-fdce-4745-9d34-fc246bc05aa1'
- response = live_photo.download(live_photo_id)
+ it 'raises an error with the correct status code when trying to download an inexistent live photo' do
+ inexistent_live_photo_id = '00000000-0000-0000-0000-000000000000'
- expect(response).not_to be_nil
+ expect {
+ onfido_api.download_live_photo(inexistent_live_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