Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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