|
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 | 24 | travel 5.seconds do |
24 | 25 | @job_ran_at = Time.zone.now |
25 | 26 | perform_enqueued_jobs |
26 | 27 | end |
27 | 28 | end |
28 | 29 |
|
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 |
| 30 | + it "does not send an email" do |
| 31 | + expect(ActionMailer::Base.deliveries).to be_empty |
| 32 | + end |
33 | 33 |
|
34 | | - it "does not update the delivery" do |
35 | | - expect(delivery.reload.last_attempt_at).to be_nil |
36 | | - end |
| 34 | + it "does not update the delivery" do |
| 35 | + expect(delivery.reload.last_attempt_at).to be_nil |
37 | 36 | end |
| 37 | + end |
38 | 38 |
|
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 | | - ) |
| 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 | + ) |
| 49 | + 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) |
| 52 | + end |
| 53 | + let(:preview_submission) do |
| 54 | + create(:submission, :preview, form_document:, form_id:, created_at: date.beginning_of_day + 1.hour) |
| 55 | + end |
| 56 | + let(:submissions) { [submissions_to_include, submission_not_on_date, preview_submission] } |
| 57 | + |
| 58 | + context "when the form does not have a submission email address" do |
| 59 | + let(:submission_email) { nil } |
| 60 | + |
| 61 | + it "raises an error" do |
| 62 | + expect { |
| 63 | + travel 5.seconds do |
| 64 | + @job_ran_at = Time.zone.now |
| 65 | + perform_enqueued_jobs |
| 66 | + end |
| 67 | + }.to raise_error(StandardError, "Form id: #{form_id} is missing a submission email address") |
49 | 68 | 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) |
| 69 | + |
| 70 | + context "when the mode is preview" do |
| 71 | + let(:mode_string) { "preview-live" } |
| 72 | + |
| 73 | + it "does not call the submission batch service" do |
| 74 | + travel 5.seconds do |
| 75 | + @job_ran_at = Time.zone.now |
| 76 | + perform_enqueued_jobs |
| 77 | + end |
| 78 | + expect(AwsSesSubmissionBatchService).not_to receive(:new) |
| 79 | + end |
52 | 80 | end |
53 | | - let(:preview_submission) do |
54 | | - create(:submission, :preview, form_document:, form_id:, created_at: date.beginning_of_day + 1.hour) |
| 81 | + end |
| 82 | + |
| 83 | + context "when the form has a submission email address" do |
| 84 | + before do |
| 85 | + travel 5.seconds do |
| 86 | + @job_ran_at = Time.zone.now |
| 87 | + perform_enqueued_jobs |
| 88 | + end |
55 | 89 | end |
56 | | - let(:submissions) { [submissions_to_include, submission_not_on_date, preview_submission] } |
57 | 90 |
|
58 | 91 | it "sends an email" do |
59 | 92 | expect(ActionMailer::Base.deliveries.count).to eq(1) |
|
0 commit comments