Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conviction check to handle grace window #296

Merged
merged 8 commits into from
Nov 7, 2018
Merged

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Nov 6, 2018

https://eaflood.atlassian.net/browse/WC-512

During testing of the grace window it was spotted that if a renewal was expired, and it matched during conviction checks, then it could not be continued because the button to access convictions approvals did not display.

This was because TransientRegistration.pending_manual_conviction_check? had a guard clause that checked the status was ACTIVE. This will no longer be the case for registrations which are EXPIRED but in the grace window, hence we change it to use may_renew?.

We also learnt doing this that may_renew? will only work if called on a metaData object that is linked to a registration, because of the call to registration.identifier in CanChangeRegistrationStatus.renewal_application_submitted?. Hence we had to tweak the tests and code to account for this.

Finally a test in the transient registration spec flagged that it was possible to for may_renew? to return true even if the registration in question was REVOKED. Hence a new guard in CanChangeRegistrationStatus.renewal_allowed? to check that the status of the registration is one that can be renewed.

@Cruikshanks Cruikshanks added the bug Something isn't working label Nov 6, 2018
@Cruikshanks Cruikshanks self-assigned this Nov 6, 2018
Copy link
Member

@irisfaraway irisfaraway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor stuff 👍

expect(registration.metaData).to_not allow_event :renew
let(:registration) { build(:registration, :is_active, expires_on: Date.today) }

it "cannot be renewed in 3 days time" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is personal preference, but I think this might be clearer in a separate context – I'd prefer "when the registration expiration date was three days ago, it cannot be renewed today" to "when the registration expiration date is today, it cannot be renewed in 3 days' time".

close_to_expiry_date? && should_not_be_expired?
end

def renew_expired_registration?
return true if in_expiry_grace_window?

# The only time an expired registration can be renewed is if the application has previously been submitted,
# or it is withion the grace window - otherwise expiry is an automatic no
return false if EXPIRED?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this isn't followed by further checks, there's nothing to return true if it's not EXPIRED? – I think we would get nil instead. Which makes me wonder if the tests are covering this.

https://eaflood.atlassian.net/browse/WC-512

During testing of the grace window it was spotted that if a renewal was expired, and it matched during conviction checks, then it could not be continued because the button to access convictions approvals did not display.

This was because `TransientRegistration.pending_manual_conviction_check?` had a guard clause that checked the status was `ACTIVE`. This will no longer be the case for registrations which are EXPIRED but in the grace window, hence we change it to use `may_renew?`.

We also learnt doing this that `may_renew?` will only work if called on a `metaData` object that is linked to a registration, because of the call to `registration.identifier` in `CanChangeRegistrationStatus.renewal_application_submitted?`. Hence we had to tweak the tests and code to account for this.

Finally a test in the transient registration spec flagged that it was possible to for `may_renew?` to return true even if the registration in question was REVOKED. Hence a new guard in `CanChangeRegistrationStatus.renewal_allowed?` to check that the status of the registration is one that can be renewed.

🎉 WIP 🎉
Believe the issue is that locally I have the grace window set, but in travis its set to 0. Hence tests that expect a registration that is expired to not renew work in travis, but not for me locally.

These changes should ensure we are consistent across all environments.
Now we have rubocop running, we can see what needs to be fixed. This covers minor things and does not add any exceptions.
As was pointed out in the PR, the check this line was doing is covered by the `transitions from:` line in the `:renew event`.
Left a bit of a cliff hanger on one comment, plus reference to the reg expiring is not actually true, it's the fact it cannot be renewed we are interested in.

So a bit of tidying up essentially.
Admittedly `renew_expired_registration?` was added to keep CodeClimate quiet, but the PR feedback rightly spotted that it wasn't returning a result in all cases.

From my read of the code the test that would cause us to miss all the previous logic gates in the method (and therefore return nil) was spec/models/waste_carriers_engine/registration_spec.rb:447 ("when the registration expiration date is less than 6 months away").

Debugging found this did cause nil to be returned, but the tests were still passing because nil == false i.e. we got the same result.

The issue was the name of the method did not really make it clear what it was doing, hence the logic inside didn't really make sense. After struggling to come up with a name and logic that made sense, and didn't break anything I instead came to the conclusion that CodeClimate was wrong in this case and leaving `renewal_allowed?` as it was before was the best solution.
@Cruikshanks
Copy link
Member Author

N.B. removing the unnecessary check in renewal_allowed? has also meant it can go back to how we previously had it with CodeClimate kicking off.

@Cruikshanks Cruikshanks merged commit b535c6c into master Nov 7, 2018
@Cruikshanks Cruikshanks deleted the fix-blocked-actions branch November 7, 2018 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants