Skip to content

Commit

Permalink
ux(mattermost_notif): better motif category has changed alert on matt…
Browse files Browse the repository at this point in the history
…ermost (#2383)

* ux(mattermost_notif): better motif category has changed alert on mattermost

* add id rdvsp
  • Loading branch information
Holist authored Oct 8, 2024
1 parent 2f538c1 commit a9915cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/jobs/alert_motif_category_has_changed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def perform(motif_id)
private

def alert_message
@alert_message ||= "
⚠️ Le motif #{motif.name} (#{motif.id}) vient de changer
de catégory malgré la présence de #{motif.rdvs.count} associés.
"
@alert_message ||=
"⚠️ Le motif #{motif.name} (ID rdv-sp: #{motif.rdv_solidarites_motif_id}) de l'organisation" \
" #{motif.organisation.name} (ID rdv-sp: #{motif.organisation.rdv_solidarites_organisation_id})" \
" vient de changer de catégorie malgré la présence de #{motif.rdvs.count} rendez-vous associés."
end

def alert_on_mattermost
MattermostClient.send_to_notif_channel(alert_message)
MattermostClient.send_to_private_channel(alert_message)
end

def alert_on_sentry
Expand Down
8 changes: 6 additions & 2 deletions spec/jobs/alert_motif_category_has_changed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
let!(:rdv) { create(:rdv, motif: motif) }

it "sends a message to Mattermost and Sentry" do
expect(MattermostClient).to receive(:send_to_notif_channel)
expect(MattermostClient).to receive(:send_to_private_channel).with(
"⚠️ Le motif #{motif.name} (ID rdv-sp: #{motif.rdv_solidarites_motif_id}) de l'organisation" \
" #{motif.organisation.name} (ID rdv-sp: #{motif.organisation.rdv_solidarites_organisation_id}) vient de" \
" changer de catégorie malgré la présence de #{motif.rdvs.count} rendez-vous associés."
)
expect(Sentry).to receive(:capture_message)

subject
Expand All @@ -18,7 +22,7 @@

context "when motif has no rdvs" do
it "does not send a message to Mattermost and Sentry" do
expect(MattermostClient).not_to receive(:send_to_notif_channel)
expect(MattermostClient).not_to receive(:send_to_private_channel)
expect(Sentry).not_to receive(:capture_message)

subject
Expand Down

0 comments on commit a9915cf

Please sign in to comment.