Skip to content

Commit

Permalink
Cover MeasurementsJob with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Feb 19, 2025
1 parent c961fe2 commit 688361a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/api/app/jobs/measurements_job.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class MeasurementsJob < ApplicationJob
queue_as :quick

def perform
return unless CONFIG['amqp_options']
def perform(config_provider = CONFIG)
return unless config_provider['amqp_options']

RabbitmqBus.send_to_bus('metrics', "group count=#{Group.count}")
RabbitmqBus.send_to_bus('metrics', "user #{measurements_to_fields(users_measurements)}")
Expand Down
33 changes: 33 additions & 0 deletions src/api/spec/jobs/measurements_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
RSpec.describe MeasurementsJob do
before do
rabbit_mock = Class.new do
attr_reader :metrics

def initialize
@metrics = {}
end

def metrics_sent
@metrics
end

def send_to_bus(category, data)
@metrics[category] = [] unless @metrics[category]
@metrics[category] << data
end
end
stub_const('RabbitMock', rabbit_mock)
end

describe 'token workflows' do
it 'gathers some intelligence about our token workflow runs' do
allow(RabbitmqBus).to receive(:send_to_bus)

MeasurementsJob.new.perform({ 'amqp_options' => true })

expect(RabbitmqBus).to have_received(:send_to_bus)
.with('metrics', 'token_workflow total_count=0,enabled=0,disabled=0,custom_configuration_path=0,custom_configuration_url=0,user_with_tokens=0,groups_sharing_tokens=0')
.at_least(1).times
end
end
end

0 comments on commit 688361a

Please sign in to comment.