2024-12-05 11:37:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-12-05 11:12:35 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe TelemetrySendingJob, type: :job do
|
2024-12-05 11:37:50 -05:00
|
|
|
describe '#perform' do
|
|
|
|
|
let(:gather_service) { instance_double(Telemetry::Gather) }
|
|
|
|
|
let(:send_service) { instance_double(Telemetry::Send) }
|
|
|
|
|
let(:telemetry_data) { { some: 'data' } }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
allow(Telemetry::Gather).to receive(:new).and_return(gather_service)
|
|
|
|
|
allow(gather_service).to receive(:call).and_return(telemetry_data)
|
|
|
|
|
allow(Telemetry::Send).to receive(:new).with(telemetry_data).and_return(send_service)
|
|
|
|
|
allow(send_service).to receive(:call)
|
|
|
|
|
end
|
|
|
|
|
|
2024-12-11 08:53:07 -05:00
|
|
|
context 'with default env' do
|
|
|
|
|
it 'does not send telemetry data' do
|
|
|
|
|
described_class.perform_now
|
2024-12-05 11:37:50 -05:00
|
|
|
|
2024-12-11 08:53:07 -05:00
|
|
|
expect(send_service).not_to have_received(:call)
|
|
|
|
|
end
|
2024-12-05 11:37:50 -05:00
|
|
|
end
|
2024-12-05 11:46:24 -05:00
|
|
|
|
2024-12-11 08:53:07 -05:00
|
|
|
context 'when ENABLE_TELEMETRY is set to true' do
|
2024-12-05 11:46:24 -05:00
|
|
|
before do
|
2024-12-11 08:53:07 -05:00
|
|
|
stub_const('ENV', ENV.to_h.merge('ENABLE_TELEMETRY' => 'true'))
|
2024-12-05 11:46:24 -05:00
|
|
|
end
|
|
|
|
|
|
2024-12-11 08:53:07 -05:00
|
|
|
it 'gathers telemetry data and sends it' do
|
2024-12-05 11:46:24 -05:00
|
|
|
described_class.perform_now
|
|
|
|
|
|
2024-12-11 08:53:07 -05:00
|
|
|
expect(gather_service).to have_received(:call)
|
|
|
|
|
expect(send_service).to have_received(:call)
|
2024-12-05 11:46:24 -05:00
|
|
|
end
|
|
|
|
|
end
|
2024-12-05 11:37:50 -05:00
|
|
|
end
|
2024-12-05 11:12:35 -05:00
|
|
|
end
|