Skip to content

Commit

Permalink
Add screen for late renewals
Browse files Browse the repository at this point in the history
From: https://eaflood.atlassian.net/browse/RUBY-1002

This adds an ad-hoc screen for when the magic link is used past the renewal window
  • Loading branch information
cintamani committed May 14, 2020
1 parent dadf607 commit c2423db
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/waste_carriers_engine/renews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/waste_carriers_engine/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="text">
<h1 class="heading-large">
<%= t(".heading") %>
</h1>

<p>
<%= t(".paragraph1") %>
</p>

<div class="form-group">
<%= link_to t(".register_again"), new_start_form_path, class: "button" %>
</div>
</div>
4 changes: 4 additions & 0 deletions config/locales/forms/renews/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ en:
paragraph2_html: "If you need to register other waste exemptions you should <a href=\"%{link_to_new_registration}\">make a new registration.</a>"
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) <a href=\"mailto:enquiries@environment-agency.gov.uk\">enquiries@environment-agency.gov.uk</a>"
past_renewal_window:
heading: "That renewal has expired"
paragraph1: "Your registration expired over 1 month ago, so you cannot renew."
register_again: "Register again"
4 changes: 4 additions & 0 deletions spec/factories/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/renewing_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 20 additions & 0 deletions spec/models/waste_carriers_engine/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions spec/requests/waste_carriers_engine/renews_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c2423db

Please sign in to comment.