Skip to content

Commit

Permalink
test: ensure coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lhguerra committed Nov 13, 2024
1 parent 4d7ce8a commit 45d3b3a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/webhook_integrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def jira_delete_card_webhook

def already_in_the_queue?(issue_id)
critical_queue = Sidekiq::Queue.new('critical')
critical_queue.map { |job| job['args'][0]['arguments'][0] }.any?(issue_id)
critical_queue&.map { |job| job['args'][0]['arguments'][0] }&.any?(issue_id)
end

def valid_jira_call?
Expand Down
19 changes: 14 additions & 5 deletions app/services/slack/slack_notification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def notify_demand_state_changed(stage, demand, demand_transition)
demand_transition.update(transition_notified: true)
end

def notify_item_assigned(item_assignment, _demand_url)
def notify_item_assigned(item_assignment, demand_url)
return if item_assignment.valid? == false

slack_configurations = slack_configurations(item_assignment.demand, :item_assigned)
Expand All @@ -204,10 +204,19 @@ def notify_item_assigned(item_assignment, _demand_url)

return if item_assignment.assignment_notified?

# slack_configurations.each do |config|
# slack_notifier = Slack::Notifier.new(config.room_webhook)
# slack_notifier.post(blocks: [info_block, divider_block])
# end
demand_title = "*<#{demand_url}|#{item_assignment.demand.external_id} - #{item_assignment.demand.demand_title}>*"
assign_message = "#{item_assignment.team_member_name} puxou a demanda em _#{item_assignment.assigned_at&.name || 'sem etapa'}_ às #{I18n.l(item_assignment.start_time, format: :short)}"
message_previous_pull = "Anterior: #{item_assignment.previous_assignment&.demand&.external_id}"
message_ongoing = ":computer: #{item_assignment.membership_open_assignments.map(&:demand).flatten.map { |demand| "#{demand.external_id} (#{demand.current_stage_name})" }.join(', ')}"
message_idle = ":zzz: #{time_distance_in_words(item_assignment.pull_interval)} :zzz: :busts_in_silhouette: #{number_to_percentage(item_assignment.membership.team.percentage_idle_members * 100, precision: 0)}"

info_block = { type: 'section', text: { type: 'mrkdwn', text: ">#{demand_title}\n>#{assign_message}\n>#{message_previous_pull}\n>#{message_ongoing}\n>#{message_idle}" } }
divider_block = { type: 'divider' }

slack_configurations.each do |config|
slack_notifier = Slack::Notifier.new(config.room_webhook)
slack_notifier.post(blocks: [info_block, divider_block])
end

ItemAssignment.transaction { item_assignment.update(assignment_notified: true) }
end
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/webhook_integrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

it 'enqueues the job' do
request.headers['Content-Type'] = 'application/json'
expect(Jira::ProcessJiraIssueJob).to receive(:perform_later).once
allow(Sidekiq::Queue).to receive(:new).with('critical')
allow(Jira::ProcessJiraIssueJob).to receive(:perform_later).once
post :jira_webhook, params: { issue: jira_issue.attrs }
expect(response).to have_http_status :ok
end
Expand All @@ -42,6 +43,7 @@

it 'enqueues the job' do
request.headers['Content-Type'] = 'application/json'
allow(Sidekiq::Queue).to receive(:new).with('critical')
expect(Jira::ProcessJiraIssueJob).to receive(:perform_later).once
post :jira_webhook, params: { issue: jira_issue.attrs }
expect(response).to have_http_status :ok
Expand Down
12 changes: 11 additions & 1 deletion spec/services/slack/slack_notification_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@

Fabricate :slack_configuration, team: team, info_type: :item_assigned, active: true

# expect_any_instance_of(Slack::Notifier).to receive(:post)
expect_any_instance_of(Slack::Notifier).to receive(:post)

described_class.instance.notify_item_assigned(item_assignment, 'htto://foo.bar/baz')
expect(item_assignment.reload.assignment_notified?).to be true
Expand All @@ -426,6 +426,16 @@
described_class.instance.notify_item_assigned(dup_item_assignment, 'htto://foo.bar/baz')
end
end

context 'without slack configuration' do
it 'just marks the assignment as notified' do
item_assignment = Fabricate :item_assignment, assignment_notified: false

described_class.instance.notify_item_assigned(item_assignment, 'htto://foo.bar/baz')

expect(item_assignment.reload.assignment_notified?).to be true
end
end
end

describe '#notify_item_blocked' do
Expand Down

0 comments on commit 45d3b3a

Please sign in to comment.