diff --git a/app/controllers/waste_carriers_engine/renews_controller.rb b/app/controllers/waste_carriers_engine/renews_controller.rb index c84bd8111..4b834e4e4 100644 --- a/app/controllers/waste_carriers_engine/renews_controller.rb +++ b/app/controllers/waste_carriers_engine/renews_controller.rb @@ -17,10 +17,10 @@ def new def validate_renew_token return render(:already_renewed) if registration.already_renewed? + return render(:past_renewal_window) if registration.past_renewal_window? # TODO # return render(:invalid_magic_link, status: 404) unless registration.present? - # return render(:past_renewal_window) if registration.past_renewal_window? end def registration diff --git a/app/models/waste_carriers_engine/registration.rb b/app/models/waste_carriers_engine/registration.rb index c23a1eae3..9ad6870d5 100644 --- a/app/models/waste_carriers_engine/registration.rb +++ b/app/models/waste_carriers_engine/registration.rb @@ -56,6 +56,10 @@ def already_renewed? check_service.date_can_renew_from > Time.now.in_time_zone("London").to_date end + def past_renewal_window? + !(check_service.expired? && check_service.in_expiry_grace_window?) + end + def expire! metaData.status = "EXPIRED" diff --git a/app/views/waste_carriers_engine/renews/past_renewal_window.html.erb b/app/views/waste_carriers_engine/renews/past_renewal_window.html.erb new file mode 100644 index 000000000..fdce86e99 --- /dev/null +++ b/app/views/waste_carriers_engine/renews/past_renewal_window.html.erb @@ -0,0 +1,13 @@ +
+

+ <%= t(".heading") %> +

+ +

+ <%= t(".paragraph1") %> +

+ +
+ <%= link_to t(".register_again"), new_start_form_path, class: "button" %> +
+
diff --git a/config/locales/forms/renews/en.yml b/config/locales/forms/renews/en.yml index 64de4e34b..feedd6b0a 100644 --- a/config/locales/forms/renews/en.yml +++ b/config/locales/forms/renews/en.yml @@ -7,3 +7,7 @@ en: paragraph2_html: "If you need to register other waste exemptions you should make a new registration." paragraph3: "If you want to discuss this registration, contact the Environment Agency. You will need your registration number." paragraph4_html: "Environment Agency helpline: 03708 506 506 (Monday to Friday, 8am to 6pm) enquiries@environment-agency.gov.uk" + past_renewal_window: + heading: "That renewal has expired" + paragraph1: "Your registration expired over 1 month ago, so you cannot renew." + register_again: "Register again" diff --git a/spec/factories/registration.rb b/spec/factories/registration.rb index 6cdd7d056..96414f1f9 100644 --- a/spec/factories/registration.rb +++ b/spec/factories/registration.rb @@ -33,6 +33,10 @@ expires_on { Rails.configuration.expires_after.years.from_now.to_date } end + trait :past_renewal_window do + expires_on { Time.now.to_date - Rails.configuration.grace_window.days - 1 } + end + trait :lower_tier do tier { "LOWER" } end diff --git a/spec/factories/renewing_registration.rb b/spec/factories/renewing_registration.rb index fbbf79ed6..4cf4ca735 100644 --- a/spec/factories/renewing_registration.rb +++ b/spec/factories/renewing_registration.rb @@ -17,6 +17,10 @@ addresses { [build(:address, :has_required_data, :registered, :from_os_places), build(:address, :has_required_data, :contact, :from_os_places)] } end + trait :expires_today do + initialize_with { new(reg_identifier: create(:registration, :has_required_data, :expires_today).reg_identifier) } + end + trait :has_key_people do key_people do [build(:key_person, :has_required_data, :unmatched_conviction_search_result, :main), diff --git a/spec/models/waste_carriers_engine/registration_spec.rb b/spec/models/waste_carriers_engine/registration_spec.rb index 366553b66..1694d6333 100644 --- a/spec/models/waste_carriers_engine/registration_spec.rb +++ b/spec/models/waste_carriers_engine/registration_spec.rb @@ -46,6 +46,26 @@ module WasteCarriersEngine end end + describe "#past_renewal_window?" do + let(:registration) { build(:registration, :has_required_data, expires_on: expires_on) } + + context "when the registration has expired too long ago" do + let(:expires_on) { Time.now.to_date - Rails.configuration.grace_window.days - 1 } + + it "returns true" do + expect(registration).to be_past_renewal_window + end + end + + context "when the registration has not expired too long ago" do + let(:expires_on) { Time.now.to_date } + + it "returns false" do + expect(registration).to_not be_past_renewal_window + end + end + end + describe "scopes" do describe ".active" do it "returns active registrations" do diff --git a/spec/requests/waste_carriers_engine/renews_spec.rb b/spec/requests/waste_carriers_engine/renews_spec.rb index 1ff1bae2b..66c538968 100644 --- a/spec/requests/waste_carriers_engine/renews_spec.rb +++ b/spec/requests/waste_carriers_engine/renews_spec.rb @@ -9,7 +9,7 @@ module WasteCarriersEngine describe "GET renew_path" do context "when the renew token is valid" do - let(:registration) { create(:registration, :has_required_data) } + let(:registration) { create(:registration, :has_required_data, :expires_today) } it "returns a 302 response, creates a new renewal registration and redirect to the renewal start form" do registration.generate_renew_token! @@ -26,7 +26,7 @@ module WasteCarriersEngine end context "when a renewal is already in progress" do - let(:transient_registration) { create(:renewing_registration, :has_required_data, workflow_state: :business_type_form) } + let(:transient_registration) { create(:renewing_registration, :has_required_data, :expires_today, workflow_state: :business_type_form) } let(:registration) { transient_registration.registration } it "does not create a new renewal and redirects to the correct form" do @@ -56,6 +56,21 @@ module WasteCarriersEngine expect(response).to render_template(:already_renewed) end end + + context "when is too late to renew" do + let(:registration) { create(:registration, :has_required_data, :past_renewal_window) } + + it "returns a 200 response code and the correct template" do + allow(Rails.configuration).to receive(:renewal_window).and_return(3) + + registration.generate_renew_token! + + get renew_path(token: registration.renew_token) + + expect(response).to have_http_status(200) + expect(response).to render_template(:past_renewal_window) + end + end end end end