|
69 | 69 | perform_enqueued_jobs |
70 | 70 | end |
71 | 71 |
|
72 | | - it "sends an email" do |
73 | | - expect(ActionMailer::Base.deliveries.count).to eq(1) |
74 | | - expect(mail.to).to include(form_document.submission_email) |
75 | | - end |
76 | | - |
77 | | - it "includes the date in London time in the subject" do |
78 | | - expect(mail.subject).to include("10 April 2025") |
79 | | - end |
80 | | - |
81 | 72 | it "updates the delivery" do |
82 | 73 | expect(delivery.reload.delivery_reference).to eq(mail.message_id) |
83 | 74 | expect(delivery.reload.last_attempt_at).to be_within(1.second).of(@job_ran_at) |
|
94 | 85 | failure_reason: "bounced") |
95 | 86 | end |
96 | 87 |
|
97 | | - it "updates the resets the delivery details" do |
| 88 | + it "resets the delivery details" do |
98 | 89 | expect(delivery.reload.delivered_at).to be_nil |
99 | 90 | expect(delivery.reload.failed_at).to be_nil |
100 | 91 | expect(delivery.reload.failure_reason).to be_nil |
101 | 92 | end |
102 | 93 | end |
103 | 94 |
|
104 | | - it "attaches a csv with the expected filename" do |
105 | | - expect(mail.attachments).not_to be_empty |
| 95 | + context "when the delivery is for a daily batch" do |
| 96 | + it "sends an email" do |
| 97 | + expect(ActionMailer::Base.deliveries.count).to eq(1) |
| 98 | + expect(mail.to).to include(form_document.submission_email) |
| 99 | + end |
106 | 100 |
|
107 | | - filenames = mail.attachments.map(&:filename) |
108 | | - expect(filenames).to contain_exactly("govuk_forms_my_form_2025-04-10.csv") |
109 | | - end |
| 101 | + it "includes the date in London time in the subject" do |
| 102 | + expect(mail.subject).to include("10 April 2025") |
| 103 | + end |
| 104 | + |
| 105 | + it "attaches a csv with the expected filename" do |
| 106 | + expect(mail.attachments).not_to be_empty |
| 107 | + |
| 108 | + filenames = mail.attachments.map(&:filename) |
| 109 | + expect(filenames).to contain_exactly("govuk_forms_my_form_2025-04-10.csv") |
| 110 | + end |
110 | 111 |
|
111 | | - it "attaches a csv containing header plus one line per submission" do |
112 | | - csv_content = mail.attachments.first.decoded |
113 | | - expect(csv_content.lines.count).to eq(submissions.count + 1) |
| 112 | + it "attaches a csv containing header plus one line per submission" do |
| 113 | + csv_content = mail.attachments.first.decoded |
| 114 | + expect(csv_content.lines.count).to eq(submissions.count + 1) |
| 115 | + end |
| 116 | + |
| 117 | + it "logs that the email was sent" do |
| 118 | + expect(log_lines).to include( |
| 119 | + hash_including( |
| 120 | + "event" => "form_daily_batch_email_sent", |
| 121 | + "form_id" => form_id, |
| 122 | + "mode" => mode_string, |
| 123 | + "preview" => "false", |
| 124 | + "batch_begin_date" => date.to_s, |
| 125 | + "number_of_submissions" => submissions.count, |
| 126 | + "delivery_reference" => mail.message_id, |
| 127 | + "delivery_id" => delivery.id, |
| 128 | + "job_id" => @job_id, |
| 129 | + ), |
| 130 | + ) |
| 131 | + end |
114 | 132 | end |
115 | 133 |
|
116 | | - it "logs that the email was sent" do |
117 | | - expect(log_lines).to include( |
118 | | - hash_including( |
119 | | - "event" => "form_daily_batch_email_sent", |
120 | | - "form_id" => form_id, |
121 | | - "mode" => mode_string, |
122 | | - "preview" => "false", |
123 | | - "batch_date" => date.to_s, |
124 | | - "number_of_submissions" => submissions.count, |
125 | | - "delivery_reference" => mail.message_id, |
126 | | - "delivery_id" => delivery.id, |
127 | | - "job_id" => @job_id, |
128 | | - ), |
129 | | - ) |
| 134 | + context "when the delivery is for a weekly batch" do |
| 135 | + let(:delivery) { create(:delivery, delivery_schedule: "weekly", submissions:, batch_begin_at:) } |
| 136 | + |
| 137 | + it "sends an email" do |
| 138 | + expect(ActionMailer::Base.deliveries.count).to eq(1) |
| 139 | + expect(mail.to).to include(form_document.submission_email) |
| 140 | + end |
| 141 | + |
| 142 | + it "includes the date range in London time in the subject" do |
| 143 | + expect(mail.subject).to include("10 April 2025 to 16 April 2025") |
| 144 | + end |
| 145 | + |
| 146 | + it "attaches a csv containing header plus one line per submission" do |
| 147 | + csv_content = mail.attachments.first.decoded |
| 148 | + expect(csv_content.lines.count).to eq(submissions.count + 1) |
| 149 | + end |
| 150 | + |
| 151 | + it "logs that the email was sent" do |
| 152 | + expect(log_lines).to include( |
| 153 | + hash_including( |
| 154 | + "event" => "form_weekly_batch_email_sent", |
| 155 | + "form_id" => form_id, |
| 156 | + "mode" => mode_string, |
| 157 | + "preview" => "false", |
| 158 | + "batch_begin_date" => date.to_s, |
| 159 | + "number_of_submissions" => submissions.count, |
| 160 | + "delivery_reference" => mail.message_id, |
| 161 | + "delivery_id" => delivery.id, |
| 162 | + "job_id" => @job_id, |
| 163 | + ), |
| 164 | + ) |
| 165 | + end |
130 | 166 | end |
131 | 167 | end |
132 | 168 |
|
|
0 commit comments