Skip to content

Commit

Permalink
Do not show change registration date menu item if registration is cea…
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDoyle-DEFRA committed Jun 20, 2023
1 parent 085d921 commit be19319
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 191 deletions.
9 changes: 6 additions & 3 deletions app/helpers/action_links_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ def display_confirmation_letter_link_for?(resource)
end

def display_renew_links_for?(resource)
can?(:renew, resource) &&
resource.renewable?
resource.is_a?(WasteExemptionsEngine::Registration) &&
can?(:renew, resource) &&
resource.renewable? &&
(resource.contact_email.present? || resource.applicant_email.present?)
end

def display_renew_window_closed_text_for?(resource)
can?(:renew, resource) &&
resource.present? &&
can?(:renew, resource) &&
resource.in_renewable_state? &&
resource.past_renewal_window?
end
Expand Down
83 changes: 74 additions & 9 deletions spec/forms/modify_expiry_date_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,80 @@
)).to be(true)
end

it "updates the registration date for each registration_exemption" do
form.submit(
date_day: valid_modified_date.day.to_s,
date_month: valid_modified_date.month.to_s,
date_year: valid_modified_date.year.to_s
)

registration.registration_exemptions.each do |exemption|
expect(exemption.expires_on).to eq(valid_modified_date)
context "with specific exemption types" do
let(:modified_exemption) { registration.registration_exemptions.first }
let(:original_expiry_date) { modified_exemption.expires_on }

before do
form.submit(
date_day: valid_modified_date.day.to_s,
date_month: valid_modified_date.month.to_s,
date_year: valid_modified_date.year.to_s
)
end

shared_examples "all exemptions updated" do
it "updates the expiry date for each registration_exemption" do
registration.registration_exemptions.each do |exemption|
expect(exemption.expires_on).to eq(valid_modified_date)
end
end
end

shared_examples "no exemptions updated" do
it "does not update the expiry date for any registration_exemption" do
registration.registration_exemptions.each do |exemption|
expect(exemption.expires_on).to eq(original_expiry_date)
end
end
end

shared_examples "only one exemption updated" do
it "updates the expiry date for the first exemption" do
expect(modified_exemption.expires_on).to eq valid_modified_date
end
end

it "does not update the expiry date for the other exemptions" do
registration.registration_exemptions.each do |re|
next if re == modified_exemption

expect(re.expires_on).to eq original_expiry_date
end
end

context "with all active exemptions" do
it_behaves_like "all exemptions updated", :active
end

context "with all expired exemptions" do
before { registration.registration_exemptions.update(state: "expired") }

it_behaves_like "all exemptions updated"
end

context "with all ceased exemptions" do
before { registration.registration_exemptions.update(state: "ceased") }

it_behaves_like "no exemptions updated"
end

context "with all revoked exemptions" do
before { registration.registration_exemptions.update(state: "revoked") }

it_behaves_like "no exemptions updated"
end

context "with active and ceased exemptions" do
before { registration.registration_exemptions.first.update(state: "ceased") }

it_behaves_like "only one exemption updated"
end

context "with active and revoked exemptions" do
before { registration.registration_exemptions.first.update(state: "revoked") }

it_behaves_like "only one exemption updated"
end
end
end
Expand Down
Loading

0 comments on commit be19319

Please sign in to comment.