Skip to content

Commit 26113c0

Browse files
committed
Source notify log entry purpose from the template, not a dispatcher
Delivery jobs now record `purpose: template.purpose` when creating a NotifyLogEntry. NotifyLogEntry.purpose_for_template_name and its spec go away. Jira-Issue: MAV-6739
1 parent 3560a35 commit 26113c0

4 files changed

Lines changed: 2 additions & 132 deletions

File tree

app/jobs/email_delivery_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def perform(
103103
subject: rendered[:subject],
104104
template_id: template.id,
105105
type: :email,
106-
purpose: NotifyLogEntry.purpose_for_template_name(template_name_sym),
106+
purpose: template.purpose,
107107
notify_log_entry_programmes_attributes:
108108
personalisation.programmes.map do
109109
{ programme_type: it.type, disease_types: it.disease_types }

app/jobs/sms_delivery_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def perform(
9393
sent_by:,
9494
template_id: template.id,
9595
type: :sms,
96-
purpose: NotifyLogEntry.purpose_for_template_name(template_name_sym),
96+
purpose: template.purpose,
9797
notify_log_entry_programmes_attributes:
9898
personalisation.programmes.map do
9999
{ programme_type: it.type, disease_types: it.disease_types }

app/models/notify_log_entry.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,40 +159,6 @@ def title
159159

160160
def programmes = notify_log_entry_programmes.map(&:programme)
161161

162-
def self.purpose_for_template_name(template_name_sym)
163-
name = template_name_sym.to_s
164-
165-
if name.include?("consent") && name.include?("request")
166-
:consent_request
167-
elsif name.include?("consent") && name.include?("reminder")
168-
:consent_reminder
169-
elsif name.include?("consent_confirmation")
170-
:consent_confirmation
171-
elsif name.include?("consent") && name.include?("warning")
172-
:consent_warning
173-
elsif name.include?("clinic") && name.include?("invitation")
174-
:clinic_invitation
175-
elsif name.include?("session_school_reminder")
176-
:session_reminder
177-
elsif name.include?("triage_vaccination_will_happen")
178-
:triage_vaccination_will_happen
179-
elsif name.include?("triage_vaccination_wont_happen")
180-
:triage_vaccination_wont_happen
181-
elsif name.include?("triage_vaccination_at_clinic")
182-
:triage_vaccination_at_clinic
183-
elsif name.include?("triage_delay_vaccination")
184-
:triage_delay_vaccination
185-
elsif name.include?("vaccination_administered")
186-
:vaccination_administered
187-
elsif name.include?("vaccination_already_had")
188-
:vaccination_already_had
189-
elsif name.include?("vaccination_not_administered")
190-
:vaccination_not_administered
191-
elsif name.include?("vaccination_deleted")
192-
:vaccination_deleted
193-
end
194-
end
195-
196162
private
197163

198164
def template_name

spec/models/notify_log_entry_spec.rb

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -51,102 +51,6 @@
5151
it { should be_valid }
5252
end
5353

54-
describe ".purpose_for_template_name" do
55-
subject(:purpose) do
56-
described_class.purpose_for_template_name(template_name)
57-
end
58-
59-
context "when the template indicates a consent request" do
60-
let(:template_name) { :consent_school_request }
61-
62-
it { should eq(:consent_request) }
63-
end
64-
65-
context "when the template indicates a consent reminder" do
66-
let(:template_name) { :consent_school_reminder }
67-
68-
it { should eq(:consent_reminder) }
69-
end
70-
71-
context "when the template indicates a consent confirmation" do
72-
let(:template_name) { :consent_confirmation_given }
73-
74-
it { should eq(:consent_confirmation) }
75-
end
76-
77-
context "when the template indicates a consent warning" do
78-
let(:template_name) { :consent_unknown_contact_details_warning }
79-
80-
it { should eq(:consent_warning) }
81-
end
82-
83-
context "when the template indicates a clinic invitation" do
84-
let(:template_name) { :clinic_flu_invitation }
85-
86-
it { should eq(:clinic_invitation) }
87-
end
88-
89-
context "when the template indicates a session reminder" do
90-
let(:template_name) { :session_school_reminder_today }
91-
92-
it { should eq(:session_reminder) }
93-
end
94-
95-
context "when the template indicates triage vaccination will happen" do
96-
let(:template_name) { :triage_vaccination_will_happen_outcome }
97-
98-
it { should eq(:triage_vaccination_will_happen) }
99-
end
100-
101-
context "when the template indicates triage vaccination won't happen" do
102-
let(:template_name) { :triage_vaccination_wont_happen_outcome }
103-
104-
it { should eq(:triage_vaccination_wont_happen) }
105-
end
106-
107-
context "when the template indicates triage vaccination at clinic" do
108-
let(:template_name) { :triage_vaccination_at_clinic_outcome }
109-
110-
it { should eq(:triage_vaccination_at_clinic) }
111-
end
112-
113-
context "when the template indicates a triage delay vaccination update" do
114-
let(:template_name) { :triage_delay_vaccination_outcome }
115-
116-
it { should eq(:triage_delay_vaccination) }
117-
end
118-
119-
context "when the template indicates vaccination administered" do
120-
let(:template_name) { :vaccination_administered_notification }
121-
122-
it { should eq(:vaccination_administered) }
123-
end
124-
125-
context "when the template indicates vaccination already had" do
126-
let(:template_name) { :vaccination_already_had_notification }
127-
128-
it { should eq(:vaccination_already_had) }
129-
end
130-
131-
context "when the template indicates vaccination not administered" do
132-
let(:template_name) { :vaccination_not_administered_notification }
133-
134-
it { should eq(:vaccination_not_administered) }
135-
end
136-
137-
context "when the template indicates vaccination deleted" do
138-
let(:template_name) { :vaccination_deleted_notification }
139-
140-
it { should eq(:vaccination_deleted) }
141-
end
142-
143-
context "when the template name does not match any known purpose" do
144-
let(:template_name) { :something_else_entirely }
145-
146-
it { should be_nil }
147-
end
148-
end
149-
15054
describe "#title" do
15155
subject(:title) { notify_log_entry.title }
15256

0 commit comments

Comments
 (0)