spec/integrations/motion_capture_spec.rb in onfido-2.9.0 vs spec/integrations/motion_capture_spec.rb in onfido-3.0.0

- old
+ new

@@ -1,44 +1,50 @@ # frozen_string_literal: true -require 'tempfile' +require_relative '../shared_contexts/with_onfido' describe Onfido::MotionCapture do - include_context 'fake onfido api' + describe 'Motion Capture' do + include_context 'with onfido' - subject(:motion_capture) { onfido.motion_capture } + let(:applicant_id) { ENV['ONFIDO_SAMPLE_APPLICANT_ID'] } + let(:motion_id) { ENV['ONFIDO_SAMPLE_MOTION_ID_1'] } - let(:motion_capture_id) { 'b1ae05b7-fb12-47c3-971c-311b56fc8de6' } + it 'lists motion captures' do + motion_captures = onfido_api.list_motion_captures(applicant_id) - describe '#find' do - it 'returns the expected motion capture' do - response = motion_capture.find(motion_capture_id) + expect(motion_captures.motion_captures.length).to be > 0 + expect(motion_captures).to be_an_instance_of Onfido::MotionCapturesList + expect(motion_captures.motion_captures.first).to be_an_instance_of Onfido::MotionCapture + end - expect(response['id']).to eq(motion_capture_id) + it 'retrieves motion capture' do + get_motion_capture = onfido_api.find_motion_capture(motion_id) + + expect(get_motion_capture.id).to eq(motion_id) + expect(get_motion_capture).to be_an_instance_of Onfido::MotionCapture end - end - describe '#all' do - it 'returns list of motion captures' do - applicant_id = '1030303-123123-123123' - response = motion_capture.all(applicant_id) + it 'downloads motion capture' do + file = onfido_api.download_motion_capture(motion_id) - expect(response['motion_captures']).not_to be_empty + expect(file.length).to be > 0 end - end - describe '#download' do - it 'returns the file data' do - response = motion_capture.download(motion_capture_id) + it 'downloads motion capture frame' do + file = onfido_api.download_motion_capture_frame(motion_id) - expect(response).not_to be_nil + expect(file.length).to be > 0 end - end - describe '#frame' do - it 'returns the frame data' do - response = motion_capture.frame(motion_capture_id) + it 'raises an error with the correct status code when trying to download an inexistent motion capture' do + inexistent_motion_id = '00000000-0000-0000-0000-000000000000' - expect(response).not_to be_nil + expect { + onfido_api.download_motion_capture(inexistent_motion_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