Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/bundler/govuk_design_system_formb…
Browse files Browse the repository at this point in the history
…uilder-5.3.3
  • Loading branch information
PaulDoyle-DEFRA committed Apr 25, 2024
2 parents c5a26ee + 14f03b2 commit d76d891
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 38 deletions.
Expand Up @@ -316,19 +316,19 @@ def set_contact_address_as_registered_address
end

def send_renewal_pending_online_payment_email
WasteCarriersEngine::Notify::RenewalPendingOnlinePaymentEmailService.run(registration:)
WasteCarriersEngine::Notify::RenewalPendingOnlinePaymentEmailService.run(registration: self)
rescue StandardError => e
Airbrake.notify(e, registration_no: reg_identifier) if defined?(Airbrake)
end

def send_renewal_pending_checks_email
WasteCarriersEngine::Notify::RenewalPendingChecksEmailService.run(registration:)
WasteCarriersEngine::Notify::RenewalPendingChecksEmailService.run(registration: self)
rescue StandardError => e
Airbrake.notify(e, registration_no: reg_identifier) if defined?(Airbrake)
end

def send_renewal_pending_payment_email
WasteCarriersEngine::Notify::RenewalPendingPaymentEmailService.run(registration:)
WasteCarriersEngine::Notify::RenewalPendingPaymentEmailService.run(registration: self)
rescue StandardError => e
Airbrake.notify(e, registration_no: reg_identifier) if defined?(Airbrake)
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/waste_carriers_engine/renewing_registration.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
module WasteCarriersEngine
class RenewingRegistration < TransientRegistration
include CanCheckIfRegistrationTypeChanged
Expand Down Expand Up @@ -49,6 +50,10 @@ def registration
@_registration ||= Registration.find_by(reg_identifier: reg_identifier)
end

def communication_records
registration.communication_records
end

def fee_including_possible_type_change
if registration_type_changed?
Rails.configuration.renewal_charge + Rails.configuration.type_change_charge
Expand Down Expand Up @@ -141,3 +146,4 @@ def registration_type_base_charges
end
end
end
# rubocop:enable Metrics/ClassLength
Expand Up @@ -23,7 +23,7 @@ module WasteCarriersEngine

expect(Notify::RenewalPendingPaymentEmailService)
.to have_received(:run)
.with(registration: renewing_registration.registration)
.with(registration: renewing_registration)
.once
end
end
Expand Down
Expand Up @@ -49,7 +49,7 @@ module WasteCarriersEngine

expect(Notify::RenewalPendingOnlinePaymentEmailService)
.to have_received(:run)
.with(registration: renewing_registration.registration)
.with(registration: renewing_registration)
.once
end
end
Expand All @@ -68,7 +68,7 @@ module WasteCarriersEngine

expect(Notify::RenewalPendingChecksEmailService)
.to have_received(:run)
.with(registration: renewing_registration.registration)
.with(registration: renewing_registration)
.once
end
end
Expand Down
Expand Up @@ -10,22 +10,19 @@ module Notify
RSpec.describe RenewalPendingChecksEmailService do
let(:template_id) { "d2442022-4f4c-4edd-afc5-aaa0607dabdf" }
let(:reg_identifier) { registration.reg_identifier }
let(:contact_email) { "foo@example.com" }
let(:expected_notify_options) do
{
email_address: "foo@example.com",
email_address: contact_email,
template_id: template_id,
personalisation: {
reg_identifier: reg_identifier,
registration_type: "carrier, broker and dealer"
}
}
end
let(:registration) { create(:registration, :has_required_data) }

before do
registration.finance_details = build(:finance_details, :has_required_data)
registration.save
end
let(:renewing_registration) { create(:renewing_registration, :has_required_data, :has_finance_details, contact_email: contact_email) }
let(:registration) { renewing_registration.registration }

describe ".run" do
context "with a contact_email" do
Expand All @@ -38,11 +35,11 @@ module Notify

subject(:run_service) do
VCR.use_cassette("notify_renewal_pending_checks_sends_an_email") do
described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end

let(:recipient) { registration.contact_email }
let(:recipient) { renewing_registration.contact_email }

it "sends an email" do
expect(run_service).to be_a(Notifications::Client::ResponseNotification)
Expand All @@ -56,12 +53,12 @@ module Notify
end

context "with no contact_email" do
before { registration.contact_email = nil }
before { renewing_registration.contact_email = nil }

it "does not attempt to send an email" do
expect_any_instance_of(Notifications::Client).not_to receive(:send_email)

described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end
end
Expand Down
Expand Up @@ -10,6 +10,7 @@ module Notify
RSpec.describe RenewalPendingOnlinePaymentEmailService do
let(:template_id) { "3da098e3-3db2-4c99-8e96-ed9d1a8ef227" }
let(:reg_identifier) { registration.reg_identifier }
let(:contact_email) { "foo@example.com" }
let(:expected_notify_options) do
{
email_address: "foo@example.com",
Expand All @@ -20,12 +21,8 @@ module Notify
}
}
end
let(:registration) { create(:registration, :has_required_data) }

before do
registration.finance_details = build(:finance_details, :has_required_data)
registration.save
end
let(:renewing_registration) { create(:renewing_registration, :has_required_data, :has_finance_details, contact_email: contact_email) }
let(:registration) { renewing_registration.registration }

describe ".run" do
context "with a contact_email" do
Expand All @@ -38,7 +35,7 @@ module Notify

subject(:run_service) do
VCR.use_cassette("notify_renewal_pending_online_payment_sends_an_email") do
described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end

Expand All @@ -54,12 +51,12 @@ module Notify
end

context "with no contact_email" do
before { registration.contact_email = nil }
before { renewing_registration.contact_email = nil }

it "does not attempt to send an email" do
expect_any_instance_of(Notifications::Client).not_to receive(:send_email)

described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end
end
Expand Down
Expand Up @@ -10,29 +10,27 @@ module Notify
RSpec.describe RenewalPendingPaymentEmailService do
let(:template_id) { "25a54b31-cdb0-4139-9ffe-50add03d572e" }
let(:reg_identifier) { registration.reg_identifier }
let(:contact_email) { "foo@example.com" }
let(:expected_notify_options) do
{
email_address: "foo@example.com",
template_id: template_id,
personalisation: {
reg_identifier: reg_identifier,
first_name: "Jane",
last_name: "Doe",
first_name: renewing_registration.first_name,
last_name: renewing_registration.last_name,
sort_code: "60-70-80",
account_number: "1001 4411",
payment_due: "100",
payment_due: "110",
iban: "GB23 NWBK 607080 10014411",
swiftbic: "NWBK GB2L",
currency: "Sterling"
}
}
end
let(:registration) { create(:registration, :has_required_data) }

before do
registration.finance_details = build(:finance_details, :has_required_data)
registration.save
end
let(:renewing_registration) { create(:renewing_registration, :has_required_data, :has_finance_details, contact_email: contact_email) }
let(:registration) { renewing_registration.registration }

describe ".run" do
context "with a contact_email" do
Expand All @@ -45,7 +43,7 @@ module Notify

subject(:run_service) do
VCR.use_cassette("notify_renewal_pending_payment_sends_an_email") do
described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end

Expand All @@ -58,16 +56,15 @@ module Notify
end

it_behaves_like "can create a communication record", "email"

end

context "with no contact_email" do
before { registration.contact_email = nil }
before { renewing_registration.contact_email = nil }

it "does not attempt to send an email" do
expect_any_instance_of(Notifications::Client).not_to receive(:send_email)

described_class.run(registration: registration)
described_class.run(registration: renewing_registration)
end
end
end
Expand Down

0 comments on commit d76d891

Please sign in to comment.