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

Remove covid grace window logic, update gems and fix rubocop warnings #1305

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ jobs:
WCRS_REGISTRATION_EXPIRES_AFTER: 3
WCRS_REGISTRATION_RENEWAL_WINDOW: 3
WCRS_REGISTRATION_GRACE_WINDOW: 5
WCRS_REGISTRATION_COVID_GRACE_WINDOW: 180
WCRS_END_OF_COVID_EXTENSION_YEAR: 2020
WCRS_END_OF_COVID_EXTENSION_MONTH: 10
WCRS_END_OF_COVID_EXTENSION_DAY: 1
WCRS_RENEWAL_CHARGE: 10500
WCRS_NEW_REGISTRATION_CHARGE: 15400
WCRS_TYPE_CHANGE_CHARGE: 4000
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ group :development, :test do
end

group :development do
# Allows us to automatically generate the change log from the tags, issues,
# labels and pull requests on GitHub. Added as a dependency so all dev's have
# access to it to generate a log, and so they are using the same version.
# New dev's should first create GitHub personal app token and add it to their
# ~/.bash_profile (or equivalent)
# https://github.com/skywinder/github-changelog-generator#github-token
gem "github_changelog_generator"

# Access an IRB console on exception pages or by using <%= console %> in views
gem "web-console"

Expand Down
72 changes: 36 additions & 36 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
aasm (5.3.1)
aasm (5.4.0)
concurrent-ruby (~> 1.0)
actioncable (6.1.7)
actionpack (= 6.1.7)
Expand Down Expand Up @@ -116,11 +116,11 @@ GEM
byebug (11.1.3)
cancancan (3.4.0)
coderay (1.1.3)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.0)
console (1.13.1)
fiber-local
countries (5.1.2)
sixarm_ruby_unaccent (~> 1.1)
countries (5.3.0)
unaccent (~> 0.3)
crack (0.4.5)
rexml
crass (1.0.6)
Expand Down Expand Up @@ -152,15 +152,14 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.5.0)
digest (3.1.0)
docile (1.3.2)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
railties (>= 3.2)
erubi (1.11.0)
erubi (1.12.0)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
Expand Down Expand Up @@ -202,7 +201,7 @@ GEM
rake (>= 10.0)
globalid (1.0.0)
activesupport (>= 5.0)
govuk_design_system_formbuilder (3.1.2)
govuk_design_system_formbuilder (3.3.0)
actionview (>= 6.1)
activemodel (>= 6.1)
activesupport (>= 6.1)
Expand All @@ -219,9 +218,9 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.3.0)
jwt (2.3.0)
loofah (2.18.0)
json (2.6.3)
jwt (2.6.0)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand All @@ -233,38 +232,36 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
mongo (2.18.0)
mini_portile2 (2.8.1)
minitest (5.17.0)
mongo (2.18.2)
bson (>= 4.14.1, < 5.0.0)
mongoid (7.5.1)
mongoid (7.5.2)
activemodel (>= 5.1, < 7.1, != 7.0.0)
mongo (>= 2.10.5, < 3.0.0)
ruby2_keywords (~> 0.0.5)
mongoid-locker (2.0.0)
mongoid (>= 5.0, < 8)
multi_json (1.15.0)
multipart-post (2.1.1)
net-protocol (0.1.3)
net-protocol (0.2.1)
timeout
net-smtp (0.3.1)
digest
net-smtp (0.3.3)
net-protocol
timeout
netrc (0.11.0)
nio4r (2.5.8)
nokogiri (1.13.8)
nokogiri (1.14.0)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
notifications-ruby-client (5.3.0)
notifications-ruby-client (5.4.0)
jwt (>= 1.5, < 3)
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
orm_adapter (0.5.0)
os_map_ref (0.5.0)
parallel (1.22.1)
parser (3.1.2.1)
parser (3.2.0.0)
ast (~> 2.4.1)
phonelib (0.6.55)
protocol-hpack (1.4.2)
Expand All @@ -281,8 +278,8 @@ GEM
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
public_suffix (5.0.0)
racc (1.6.0)
rack (2.2.4)
racc (1.6.2)
rack (2.2.6.2)
rack-test (2.0.2)
rack (>= 1.3)
rails (6.1.7)
Expand All @@ -307,8 +304,8 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (6.1.7)
actionpack (= 6.1.7)
activesupport (= 6.1.7)
Expand All @@ -318,7 +315,7 @@ GEM
rainbow (3.1.1)
rake (13.0.6)
rbtree3 (0.7.0)
regexp_parser (2.5.0)
regexp_parser (2.6.2)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
Expand Down Expand Up @@ -352,20 +349,23 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.11.0)
rubocop (1.36.0)
rubocop (1.44.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.24.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-rspec (2.13.2)
rubocop-capybara (2.17.0)
rubocop (~> 1.41)
rubocop-rspec (2.18.1)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
Expand All @@ -387,7 +387,6 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sixarm_ruby_unaccent (1.2.0)
spring (4.1.0)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
Expand All @@ -404,18 +403,19 @@ GEM
thor (1.2.1)
tilt (2.0.10)
timecop (0.9.5)
timeout (0.3.0)
timeout (0.3.1)
timers (4.3.3)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
uk_postcode (2.1.8)
unaccent (0.4.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unicode-display_width (2.3.0)
unicode-display_width (2.4.2)
validates_email_format_of (1.6.3)
i18n
vcr (6.1.0)
Expand All @@ -435,7 +435,7 @@ GEM
websocket-extensions (0.1.5)
wicked_pdf (2.6.3)
activesupport
zeitwerk (2.6.0)
zeitwerk (2.6.6)

PLATFORMS
ruby
Expand Down
12 changes: 3 additions & 9 deletions app/models/waste_carriers_engine/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,15 @@ class Registration

field :renew_token, type: String

def self.lower_tier_or_unexpired_or_in_covid_grace_window
def self.lower_tier_or_unexpired
beginning_of_today = Time.now.in_time_zone("London").beginning_of_day
normal_expiry_date = beginning_of_today + 1.day
earliest_day_of_covid_grace_window = beginning_of_today - Rails.configuration.covid_grace_window.days + 1.day
expiry_date = beginning_of_today + 1.day

any_of(
# Registration is lower tier
{ tier: LOWER_TIER },
# Registration expires on or after the current date
{ :expires_on.gte => normal_expiry_date },
# Registration had a COVID extension and is within the COVID grace window
{ expires_on: {
"$lt" => Rails.configuration.end_of_covid_extension,
"$gte" => earliest_day_of_covid_grace_window
} }
{ :expires_on.gte => expiry_date }
)
end

Expand Down
7 changes: 2 additions & 5 deletions app/services/waste_carriers_engine/expiry_check_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ def in_renewal_window?
# adding 3 days to that date would give the impression the grace window lasts
# till Oct 4 (i.e. 1 + 3) when in fact we need to include the 1st as one of
# our grace window days.
def in_expiry_grace_window?(ignore_extended_grace_window: false)
last_day_of_grace_window = LastDayOfGraceWindowService.run(
registration: registration,
ignore_extended_grace_window: ignore_extended_grace_window
)
def in_expiry_grace_window?
last_day_of_grace_window = LastDayOfGraceWindowService.run(registration: registration)

current_day_is_within_grace_window?(last_day_of_grace_window)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,22 @@ module WasteCarriersEngine
class LastDayOfGraceWindowService < BaseService
attr_reader :registration

delegate :expires_on, to: :registration

def run(registration:, ignore_extended_grace_window: false)
raise "ExpiryCheckService expects a registration" if registration.nil?
def run(registration:)
raise "LastDayOfGraceWindowService expects a registration" if registration.nil?

@registration = registration
@ignore_extended_grace_window = ignore_extended_grace_window

run_grace_window_rules
last_day_of_grace_window
end

private

def run_grace_window_rules
if extended_grace_window_available?
last_day_of_extended_grace_window
elsif registration_had_covid_extension?
last_day_of_grace_window_with_covid_extension
else
last_day_of_standard_grace_window
end
end

def extended_grace_window_available?
return false if ignore_extended_grace_window?

FeatureToggle.active?(:use_extended_grace_window) && WasteCarriersEngine.configuration.host_is_back_office?
end

def registration_had_covid_extension?
end_of_covid_extension = Rails.configuration.end_of_covid_extension

expiry_date < end_of_covid_extension
end

# The last day that you can add 3 years to a registration and have it still
# be active.
def last_day_of_extended_grace_window
(expiry_date + Rails.configuration.expires_after.years) - 1.day
end

# This was an extended grace window applied from March to October 2020
# to deal with decreased capacity due to COVID.
def last_day_of_grace_window_with_covid_extension
(expiry_date + Rails.configuration.covid_grace_window.days) - 1.day
end

# The default grace window with no extensions applied.
def last_day_of_standard_grace_window
def last_day_of_grace_window
(expiry_date + Rails.configuration.grace_window.days) - 1.day
end

def expiry_date
@_expiry_date ||= ExpiryDateService.run(registration: registration).to_date
end

def ignore_extended_grace_window?
@ignore_extended_grace_window == true
end
end
end
4 changes: 0 additions & 4 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ class Application < Rails::Application
# Times
config.renewal_window = ENV["WCRS_REGISTRATION_RENEWAL_WINDOW"].to_i
config.expires_after = ENV["WCRS_REGISTRATION_EXPIRES_AFTER"].to_i
config.covid_grace_window = ENV["WCRS_REGISTRATION_COVID_GRACE_WINDOW"].to_i
config.grace_window = ENV["WCRS_REGISTRATION_GRACE_WINDOW"].to_i
config.end_of_covid_extension = Date.new((ENV["WCRS_END_OF_COVID_EXTENSION_YEAR"]|| 2020).to_i,
(ENV["WCRS_END_OF_COVID_EXTENSION_MONTH"] || 10).to_i,
(ENV["WCRS_END_OF_COVID_EXTENSION_DAY"] || 1).to_i)

# Worldpay
config.worldpay_url = ENV["WCRS_WORLDPAY_URL"] || "https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp"
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

trait :past_renewal_window do
expires_on { Time.now.to_date - Helpers::GraceWindows.current_grace_window - 1 }
expires_on { Time.now.to_date - Rails.configuration.grace_window - 1 }
end

trait :lower_tier do
Expand Down
2 changes: 1 addition & 1 deletion spec/forms/waste_carriers_engine/base_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

module WasteCarriersEngine
RSpec.describe BaseForm, type: :model do
RSpec.describe BaseForm do
describe "#submit" do
let(:base_form) { build(:base_form, :has_required_data) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

module WasteCarriersEngine
RSpec.describe BusinessTypeForm, type: :model do
RSpec.describe BusinessTypeForm do
describe "#submit" do
context "when the form is valid" do
let(:business_type_form) { build(:business_type_form, :has_required_data) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

module WasteCarriersEngine
RSpec.describe CannotRenewTypeChangeForm, type: :model do
RSpec.describe CannotRenewTypeChangeForm do
describe "#workflow_state" do
it_behaves_like "a fixed final state",
current_state: :cannot_renew_type_change_form,
Expand Down
Loading