kusumandaru
3/14/2020 - 8:32 AM

BigQuery UserJob rspec

Spec for Bigquery User Job

RSpec.describe Bigquery::UserStreamJob, type: :job do
  describe '#perform' do    
    let(:described_service) { described_class.new }

    context 'transaction found' do
      include_context 'big query user example'

      let(:hra_init) { FactoryBot.create(:user) }
      let(:insert_json) {
        file = File.read("spec/fixtures/hra/insert_success.json")
      }

      it 'call HraDataUserService' do
        expect_any_instance_of(Bigquery::UserService).to receive(:insert_rows).and_call_original
  
        expect(described_service.perform(hra_init.id)).to be_truthy
      end
    end

    context 'transaction not found' do
      it 'not call HraDataUserService' do
        expect_any_instance_of(Bigquery::UserService).not_to receive(:insert_rows).and_call_original
  
        expect(described_service.perform('xxx')).to be_nil
      end
    end
  end
end