Skip to content

Commit

Permalink
Add test for deliver_batch!
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamineskola committed Oct 22, 2024
1 parent 863c7e8 commit 402f4ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/factories/neighbour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions spec/services/letter_sending_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 402f4ea

Please sign in to comment.