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

- old
+ new

@@ -1,36 +1,50 @@ # frozen_string_literal: true -require 'tempfile' +require_relative '../shared_contexts/with_onfido' describe Onfido::LiveVideo do - include_context 'fake onfido api' + describe 'Live Video' do + include_context 'with onfido' - subject(:live_video) { onfido.live_video } + let(:applicant_id) { ENV['ONFIDO_SAMPLE_APPLICANT_ID'] } + let(:live_video_id) { ENV['ONFIDO_SAMPLE_VIDEO_ID_1'] } - let(:live_video_id) { 'c9701e9b-83aa-442f-995b-20320ee8fb01' } + it 'lists live videos' do + live_videos = onfido_api.list_live_videos(applicant_id) - describe '#find' do - it 'returns the expected live photo' do - response = live_video.find(live_video_id) + expect(live_videos.live_videos.length).to be > 0 + expect(live_videos).to be_an_instance_of Onfido::LiveVideosList + expect(live_videos.live_videos.first).to be_an_instance_of Onfido::LiveVideo + end - expect(response['id']).to eq(live_video_id) + it 'retrieves live videos' do + get_live_video = onfido_api.find_live_video(live_video_id) + + expect(get_live_video.id).to eq(live_video_id) + expect(get_live_video).to be_an_instance_of Onfido::LiveVideo end - end - describe '#all' do - it 'returns list of documents' do - applicant_id = '1030303-123123-123123' - response = live_video.all(applicant_id) + it 'downloads live video' do + file = onfido_api.download_live_video(live_video_id) - expect(response['live_videos']).not_to be_empty + expect(file.length).to be > 0 end - end - describe '#download' do - it 'returns the file data' do - response = live_video.download(live_video_id) + it 'downloads live video frame' do + file = onfido_api.download_live_video_frame(live_video_id) - expect(response).not_to be_nil + expect(file.length).to be > 0 + end + + it 'raises an error with the correct status code when trying to download an inexistent live video' do + inexistent_live_video_id = '00000000-0000-0000-0000-000000000000' + + expect { + onfido_api.download_live_video(inexistent_live_video_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