|
8 | 8 | let(:date) { Date.new(2022, 12, 14) } |
9 | 9 | let(:delivery) { create(:delivery, delivery_schedule: "daily") } |
10 | 10 |
|
11 | | - let(:form_document) { create(:v2_form_document, :with_steps, name: "My Form", submission_email: "to@example.com") } |
| 11 | + let(:form_document) { create(:v2_form_document, :with_steps, name: "My Form", submission_email:) } |
| 12 | + let(:submission_email) { "to@example.com" } |
12 | 13 | let(:form_id) { form_document.form_id } |
13 | 14 | let(:submissions) { [] } |
14 | 15 |
|
15 | 16 | before do |
16 | 17 | submissions |
17 | 18 | ActionMailer::Base.deliveries.clear |
| 19 | + described_class.perform_later(form_id:, mode_string:, date:, delivery:) |
18 | 20 | end |
19 | 21 |
|
20 | | - context "when the job is processed" do |
| 22 | + context "when there are no submissions" do |
21 | 23 | before do |
22 | | - described_class.perform_later(form_id:, mode_string:, date:, delivery:) |
23 | | - travel 5.seconds do |
24 | | - @job_ran_at = Time.zone.now |
25 | | - perform_enqueued_jobs |
26 | | - end |
| 24 | + perform_enqueued_jobs |
27 | 25 | end |
28 | 26 |
|
29 | | - context "when there are no submissions" do |
30 | | - it "does not send an email" do |
31 | | - expect(ActionMailer::Base.deliveries).to be_empty |
32 | | - end |
| 27 | + it "does not send an email" do |
| 28 | + expect(ActionMailer::Base.deliveries).to be_empty |
| 29 | + end |
33 | 30 |
|
34 | | - it "does not update the delivery" do |
35 | | - expect(delivery.reload.last_attempt_at).to be_nil |
36 | | - end |
| 31 | + it "does not update the delivery" do |
| 32 | + expect(delivery.reload.last_attempt_at).to be_nil |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + context "when there are submissions" do |
| 37 | + let(:submissions_to_include) do |
| 38 | + create_list( |
| 39 | + :submission, |
| 40 | + 3, |
| 41 | + form_document:, |
| 42 | + form_id:, |
| 43 | + mode: mode_string, |
| 44 | + created_at: date.beginning_of_day + 1.hour, |
| 45 | + ) |
37 | 46 | end |
| 47 | + let(:submission_not_on_date) do |
| 48 | + create(:submission, form_document:, form_id:, mode: mode_string, created_at: date.beginning_of_day - 1.day) |
| 49 | + end |
| 50 | + let(:preview_submission) do |
| 51 | + create(:submission, :preview, form_document:, form_id:, created_at: date.beginning_of_day + 1.hour) |
| 52 | + end |
| 53 | + let(:submissions) { [submissions_to_include, submission_not_on_date, preview_submission] } |
| 54 | + |
| 55 | + context "when the form does not have a submission email address" do |
| 56 | + let(:submission_email) { nil } |
38 | 57 |
|
39 | | - context "when there are submissions" do |
40 | | - let(:submissions_to_include) do |
41 | | - create_list( |
42 | | - :submission, |
43 | | - 3, |
44 | | - form_document:, |
45 | | - form_id:, |
46 | | - mode: mode_string, |
47 | | - created_at: date.beginning_of_day + 1.hour, |
48 | | - ) |
| 58 | + it "raises an error" do |
| 59 | + expect { |
| 60 | + perform_enqueued_jobs |
| 61 | + }.to raise_error(StandardError, "Form id: #{form_id} is missing a submission email address") |
49 | 62 | end |
50 | | - let(:submission_not_on_date) do |
51 | | - create(:submission, form_document:, form_id:, mode: mode_string, created_at: date.beginning_of_day - 1.day) |
| 63 | + |
| 64 | + context "when the mode is preview" do |
| 65 | + let(:mode_string) { "preview-live" } |
| 66 | + |
| 67 | + it "does not call the submission batch service" do |
| 68 | + perform_enqueued_jobs |
| 69 | + expect(AwsSesSubmissionBatchService).not_to receive(:new) |
| 70 | + end |
52 | 71 | end |
53 | | - let(:preview_submission) do |
54 | | - create(:submission, :preview, form_document:, form_id:, created_at: date.beginning_of_day + 1.hour) |
| 72 | + end |
| 73 | + |
| 74 | + context "when the form has a submission email address" do |
| 75 | + before do |
| 76 | + @job_ran_at = Time.zone.now |
| 77 | + perform_enqueued_jobs |
55 | 78 | end |
56 | | - let(:submissions) { [submissions_to_include, submission_not_on_date, preview_submission] } |
57 | 79 |
|
58 | 80 | it "sends an email" do |
59 | 81 | expect(ActionMailer::Base.deliveries.count).to eq(1) |
|
0 commit comments