spec/integrations/document_spec.rb in onfido-2.9.0 vs spec/integrations/document_spec.rb in onfido-3.0.0
- old
+ new
@@ -1,75 +1,46 @@
# frozen_string_literal: true
-require 'tempfile'
+require_relative '../shared_contexts/with_document'
describe Onfido::Document do
- include_context 'fake onfido api'
+ describe 'Documents' do
+ include_context 'with document'
- subject(:document) { onfido.document }
-
- describe '#create' do
- let(:params) do
- {
- applicant_id: '1030303-123123-123123',
- type: 'driving_licence',
- file: file,
- side: 'front',
- location: {
- ip_address: '127.0.0.1',
- country_of_residence: 'GBR'
- }
- }
+ 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
- context 'with a File-like object to upload' do
- let(:file) { Tempfile.new(['driving_licence', '.jpg']) }
+ it 'lists documents' do
+ list_of_documents = onfido_api.list_documents(applicant_id)
- after do
- file.close
- file.unlink
- end
-
- it 'creates a new document' do
- response = document.create(**params)
-
- expect(response['id']).not_to be_nil
- end
+ expect(list_of_documents).to be_an_instance_of(Onfido::DocumentsList)
+ expect(list_of_documents.documents.size).to be > 0
end
- context 'passing in a non-File-like file to upload' do
- let(:file) { 'https://onfido.com/images/logo.png' }
+ it 'finds a document' do
+ get_document = onfido_api.find_document(document_id)
- it 'raises an ArgumentError' do
- expect { document.create(**params) }
- .to raise_error(ArgumentError, /must be a `File`-like object/)
- end
+ expect(get_document).to be_an_instance_of(Onfido::Document)
+ expect(get_document.id).to eq document_id
end
- end
- describe '#find' do
- it 'returns the expected document' do
- document_id = '7568415-123123-123123'
- response = document.find(document_id)
+ it 'downloads a document' do
+ file = onfido_api.download_document(document_id)
- expect(response['id']).to eq(document_id)
+ expect(file.size).to be > 0
end
- end
- describe '#all' do
- it 'returns list of documents' do
- applicant_id = '1030303-123123-123123'
- response = document.all(applicant_id)
-
- expect(response['documents']).not_to be_empty
- end
- end
-
- describe '#download' do
- it 'returns the file data' do
- document_id = '1212121-123123-123123'
- response = document.download(document_id)
-
- expect(response).not_to be_nil
+ 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