Skip to content

Commit

Permalink
Registrations with matches can't finish renewal immediately
Browse files Browse the repository at this point in the history
If a business or a key person gets a positive or unknown match, don't renew that registration immediately, regardless of payment method. Instead, send the user to the "renewal application received" page. A member of staff can then check the matched result and confirm or reject the renewal in the back office.
  • Loading branch information
irisfaraway committed Jun 25, 2018
1 parent 9928a57 commit f69ca0d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
18 changes: 17 additions & 1 deletion app/models/concerns/can_have_registration_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,23 @@ def relevant_people
end

def conviction_check_required?
declared_convictions == true
return true if declared_convictions == true
business_has_matching_or_unknown_conviction? || key_person_has_matching_or_unknown_conviction?
end

def business_has_matching_or_unknown_conviction?
return true unless convictionSearchResult.present?
return false if convictionSearchResult.match_result == "NO"
true
end

def key_person_has_matching_or_unknown_conviction?
return true unless keyPeople.present?

conviction_search_results = keyPeople.map(&:convictionSearchResult)
match_results = conviction_search_results.map(&:match_result)

match_results.include?("YES") || match_results.include?("UNKNOWN")
end
end
end
11 changes: 11 additions & 0 deletions spec/factories/conviction_search_result.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
FactoryBot.define do
factory :convictionSearchResult do
trait :match_result_yes do
match_result "YES"
end

trait :match_result_no do
match_result "NO"
end

trait :match_result_unknown do
match_result "UNKNOWN"
end
end
end
8 changes: 8 additions & 0 deletions spec/factories/key_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@
# Initialise with attributes so we can set the date of birth
initialize_with { new(attributes) }
end

trait :matched_conviction_search_result do
convictionSearchResult { build(:convictionSearchResult, :match_result_yes) }
end

trait :unmatched_conviction_search_result do
convictionSearchResult { build(:convictionSearchResult, :match_result_no) }
end
end
end
8 changes: 6 additions & 2 deletions spec/factories/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

trait :has_key_people do
keyPeople do
[build(:key_person, :has_required_data, :main),
build(:key_person, :has_required_data, :relevant)]
[build(:key_person, :has_required_data, :unmatched_conviction_search_result, :main),
build(:key_person, :has_required_data, :unmatched_conviction_search_result, :relevant)]
end
end

Expand All @@ -35,6 +35,10 @@
end
end

trait :has_conviction_search_result do
convictionSearchResult { build(:convictionSearchResult, :match_result_no) }
end

# Overseas registrations

trait :has_required_overseas_data do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
let(:transient_registration) do
create(:transient_registration,
:has_required_data,
:has_conviction_search_result,
:has_key_people,
workflow_state: "worldpay_form")
end

Expand All @@ -16,8 +18,26 @@
context "when there are no convictions" do
before(:each) { transient_registration.declared_convictions = false }

it "changes to :renewal_complete_form after the 'next' event" do
expect(transient_registration).to transition_from(:worldpay_form).to(:renewal_complete_form).on_event(:next)
context "when the convictionSearchResults have no matches" do
it "changes to :renewal_complete_form after the 'next' event" do
expect(transient_registration).to transition_from(:worldpay_form).to(:renewal_complete_form).on_event(:next)
end
end

context "when the convictionSearchResult has a match" do
before(:each) { transient_registration.convictionSearchResult = build(:convictionSearchResult, :match_result_yes) }

it "changes to :renewal_received_form after the 'next' event" do
expect(transient_registration).to transition_from(:worldpay_form).to(:renewal_received_form).on_event(:next)
end
end

context "when a keyPerson's convictionSearchResult has a match" do
before(:each) { transient_registration.keyPeople << build(:key_person, :main, :matched_conviction_search_result) }

it "changes to :renewal_received_form after the 'next' event" do
expect(transient_registration).to transition_from(:worldpay_form).to(:renewal_received_form).on_event(:next)
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/requests/worldpay_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
create(:transient_registration,
:has_required_data,
:has_addresses,
:has_conviction_search_result,
:has_key_people,
account_email: user.email,
workflow_state: "worldpay_form")
end
Expand Down

0 comments on commit f69ca0d

Please sign in to comment.