diff --git a/spec/factories/neighbour.rb b/spec/factories/neighbour.rb index 32ad0a502a..e7d7cdf4c2 100644 --- a/spec/factories/neighbour.rb +++ b/spec/factories/neighbour.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :neighbour do - address { "123, Made Up Street, London, W5 67S" } + address { Faker::Address.full_address } consultation end end diff --git a/spec/services/letter_sending_service_spec.rb b/spec/services/letter_sending_service_spec.rb index a582beebce..10e39f5e4e 100644 --- a/spec/services/letter_sending_service_spec.rb +++ b/spec/services/letter_sending_service_spec.rb @@ -110,4 +110,33 @@ end end end + + describe "#deliver_batch!" do + let(:user) { create(:user) } + + before do + allow(ENV).to receive(:fetch).and_call_original + allow(ENV).to receive(:fetch).with("BOPS_ENVIRONMENT", "development").and_return("production") + end + let(:consultation) { planning_application.consultation } + let(:neighbours) { create_list(:neighbour, 3, consultation:) } + let(:status) { 200 } + + before do + travel_to(Time.utc(2023, 1, 5, 5)) + end + + it "makes requests and records in the model" do + letter_content = "Application received: #{planning_application.received_at.to_fs(:day_month_year_slashes)}" + notify_request = stub_send_letter(status: 200) + + described_class.new(letter_content, letter_type: :consultation).deliver_batch!(neighbours) + + expect(notify_request).to have_been_requested.times(3) + + expect(consultation.neighbour_letter_batches.count).to eq(1) + + expect(consultation.neighbour_letter_batches.first.neighbour_letters.count).to eq(3) + end + end end diff --git a/spec/system/planning_applications/consulting/send_letters_to_neighbours_spec.rb b/spec/system/planning_applications/consulting/send_letters_to_neighbours_spec.rb index 2f855c46cc..a3303bcfec 100644 --- a/spec/system/planning_applications/consulting/send_letters_to_neighbours_spec.rb +++ b/spec/system/planning_applications/consulting/send_letters_to_neighbours_spec.rb @@ -41,7 +41,7 @@ sign_in assessor visit "/planning_applications/#{planning_application.reference}" - neighbour = create(:neighbour, consultation:) + neighbour = create(:neighbour, consultation:, address: "123, Made Up Street, London, W5 67S") neighbour_letter = create(:neighbour_letter, neighbour:, status: "submitted", notify_id: "123") stub_send_letter(status: 200)