<%= t(".heading_#{@key_people_form.business_type}") %>
<%= t(".description_1_#{@key_people_form.business_type}") %>
- <% unless @key_people_form.can_only_have_one_key_person? %> + <% unless @key_people_form.can_only_have_one_person_in_type? %><%= t(".description_2") %>
<% end %> - <% if @key_people_form.errors[:first_name].any? %> -<%= t(".list_of_people") %>
- <% @transient_registration.keyPeople.each do |person| %> + <% @transient_registration.key_people.each do |person| %>-
<%= person.first_name %> <%= person.last_name %>
diff --git a/app/views/shared/_date_of_birth.html.erb b/app/views/shared/_date_of_birth.html.erb
new file mode 100644
index 000000000..372d3de0a
--- /dev/null
+++ b/app/views/shared/_date_of_birth.html.erb
@@ -0,0 +1,32 @@
+<% if form.errors[:date_of_birth].any? %>
++<% else %> ++<% end %> +diff --git a/app/views/shared/_person_name.html.erb b/app/views/shared/_person_name.html.erb new file mode 100644 index 000000000..e98bab22e --- /dev/null +++ b/app/views/shared/_person_name.html.erb @@ -0,0 +1,29 @@ +<% if form.errors[:first_name].any? %> +
+ <% if form.errors[:date_of_birth].any? %> + + + <% end %> + + + ++ <%= f.label :dob_day, t(".dob_day"), class: "form-label" %> + <%= f.text_field :dob_day, value: form.dob_day, class: "form-control" %> + + ++ <%= f.label :dob_month, t(".dob_month"), class: "form-label" %> + <%= f.text_field :dob_month, value: form.dob_month, class: "form-control" %> + + ++ <%= f.label :dob_year, t(".dob_year"), class: "form-label" %> + <%= f.text_field :dob_year, value: form.dob_year, class: "form-control" %> + + ++<% else %> ++<% end %> ++ +<% if form.errors[:last_name].any? %> ++ <% if form.errors[:first_name].any? %> + + + <% end %> + + <%= f.label :first_name, t(".first_name"), class: "form-label" %> + <%= f.text_field :first_name, value: form.first_name, class: "form-control" %> ++<% else %> ++<% end %> +diff --git a/config/locales/en.yml b/config/locales/en.yml index 469f9d381..4d5dc1b01 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,6 +12,12 @@ en: feedback_link: feedback feedback_url: https://www.gov.uk/done/waste-carrier-or-broker-registration shared: + date_of_birth: + date_of_birth: Date of birth + date_of_birth_hint: For example, 26 5 1976 + dob_year: Year + dob_month: Month + dob_day: Day errors: heading: A problem to fix footer: @@ -19,6 +25,9 @@ en: os_terms_footer: text: © Crown copyright and database rights 2018 Ordnance Survey 100024198. Use of this addressing data is subject to the link_text: address data terms and conditions (opens new tab) + person_name: + first_name: First name + last_name: Last name # Custom error pages invalid_reg_identifier_heading: The registration number you entered is not valid diff --git a/config/locales/forms/conviction_details_forms/en.yml b/config/locales/forms/conviction_details_forms/en.yml index d1d14e60b..aadb09a8b 100644 --- a/config/locales/forms/conviction_details_forms/en.yml +++ b/config/locales/forms/conviction_details_forms/en.yml @@ -2,13 +2,40 @@ en: conviction_details_forms: new: heading: Details of the person with a conviction - error_heading: Something is wrong + position: Job title + add_person_link: Add another person + next_button: Continue + list_of_people: You have added the following people + delete_person_link: Delete next_button: Continue activemodel: errors: models: conviction_details_form: + not_enough_people_in_type: + one: "You must add the details of at least one person" attributes: + first_name: + blank: "You must enter a first name" + too_long: "The first name must be no longer than 35 characters" + last_name: + blank: "You must enter a last name" + too_long: "The last name must be no longer than 35 characters" + position: + blank: "You must enter a position" + too_long: "The position must be no longer than 35 characters" + date_of_birth: + age_limit: "You must be 16 or older to use this service" + not_a_date: "You must enter a valid date" + day_blank: "You must enter a day" + day_integer: "The day must be a number" + day_range: "The day must be between 1 and 31" + month_blank: "You must enter a month" + month_integer: "The month must be a number" + month_range: "The month must be between 1 and 12" + year_blank: "You must enter a year" + year_integer: "The year must be a number" + year_range: "The year must be between 1900 and now" reg_identifier: invalid_format: "The registration ID is not in a valid format" no_registration: "There is no registration matching this ID" diff --git a/config/locales/forms/key_people_forms/en.yml b/config/locales/forms/key_people_forms/en.yml index f55f4a550..a06583402 100644 --- a/config/locales/forms/key_people_forms/en.yml +++ b/config/locales/forms/key_people_forms/en.yml @@ -14,13 +14,6 @@ en: description_1_partnership: Provide the name and date of birth for each partner of this business. description_1_soleTrader: Provide the name and date of birth for the owner of this business. description_2: Add their details one person at a time. If you need to add more people, select 'add another person'. - first_name: First name - last_name: Last name - date_of_birth: Date of birth - date_of_birth_hint: For example, 26 5 1976 - dob_year: Year - dob_month: Month - dob_day: Day add_person_link: Add another person next_button: Continue list_of_people: You have added the following people @@ -30,7 +23,7 @@ en: errors: models: key_people_form: - not_enough_key_people: + not_enough_people_in_type: one: "You must add the details of at least one person" other: "You must add the details of at least %{count} people" attributes: diff --git a/config/routes.rb b/config/routes.rb index ea2c8ae1d..4ea06541b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -216,6 +216,11 @@ to: "conviction_details_forms#go_back", as: "back", on: :collection + + delete "delete_person/:id", + to: "conviction_details_forms#delete_person", + as: "delete_person", + on: :collection end resources :contact_name_forms, diff --git a/spec/cassettes/company_postcode_form_modified_postcode.yml b/spec/cassettes/company_postcode_form_modified_postcode.yml index 8455c3ed2..8a938cbad 100644 --- a/spec/cassettes/company_postcode_form_modified_postcode.yml +++ b/spec/cassettes/company_postcode_form_modified_postcode.yml @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 12 Mar 2018 14:22:52 GMT + - Mon, 26 Mar 2018 15:09:22 GMT Content-Type: - application/json Content-Encoding: @@ -35,5 +35,5 @@ http_interactions: string: !binary |- H4sIAAAAAAAAAN2Y0W6bMBSGX8XimkoQgoHdkcRtkChEQFpFVS+cxG3QCI4IbKumvftMIS4QNu3CROkuIvEfw7H9n08Hk6ef0p6m8VeSSV8kTTHNsSrJUnHI0qZO4pQcpS9PEgqn9gKB0HZ9j8UfnGnkB44NwihAKJKeZSmn38tHJ4ETRr7L7jnQY76hW1IGQxVAe86CBB/zOH0t59CtkW6wUEqzfFfFVGMEjTK2oUWaZ28sxMSWHEi6JWnu0g1O4rwbjnYZLV53Lzgj1Qje7uM0PuYZzuNvxM4Ibi0sKdPYRb6jGUu2PGxxTmbsVz2c0Tec3OM46Q4ccJbHOGGiaYYMlp4TAV0GUWB7oX8P5v4yRDLoWCSDegHsgrtxLNaTIk62bPce3pfzVMnY0LodbyVnw+XiT5uub+nWRJZo9oqZD8wFmtY3derIZyn263cS6rr5Ly/xhkzoj+YAM5xZsGeO18nKGC3WCZn1VeiX3ERspENo6h+Icc0RW8wdd+FHoTi8NHiGl6FoV4/XyYgaLetGVUTSVeYbDrBGFS8Il6IqOmzAddIcrnA5ebRX4tAaa+edy9KvHq3KhhosUyRV5nBI8dpdDijV0g3V+ACKaw5UNEdgZjvuCkycCIGpfYvE0QWtc7p08+rp6vGkRk0ViZo6HGr9Vb3oW9KEjYMY15y7dwe0m7Hc3bKoI1kPesbo6tHjtgjkjKUbjrRLYzXWtBZWlW5jBYeCatwDlQk/B1RQJFLwPwFKVUzNGjfejyfdBOoBBaETrYB/C8q++ojCqLxG3p1rezOBLavnLGZ+ipb1d4cEgTcccv9S48s2OctsN7l3zZnkm5oFKzB1ke2x1Qvscuefm9C0rp7DXlfqc5shsvkZw5H4p8pelj6l/f9GpRv0BXeOB+59D63Awp0K/FzQz8GD198Au4bUzI1EMjcakrmzeg6K2/NvwFnliLMVAAA= http_version: - recorded_at: Mon, 12 Mar 2018 14:27:50 GMT + recorded_at: Mon, 26 Mar 2018 15:09:24 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/company_postcode_form_no_matches_postcode.yml b/spec/cassettes/company_postcode_form_no_matches_postcode.yml index 3d2bae0d6..b2b9376b6 100644 --- a/spec/cassettes/company_postcode_form_no_matches_postcode.yml +++ b/spec/cassettes/company_postcode_form_no_matches_postcode.yml @@ -21,7 +21,7 @@ http_interactions: message: Bad Request headers: Date: - - Mon, 12 Mar 2018 14:22:53 GMT + - Mon, 26 Mar 2018 15:09:24 GMT Content-Type: - application/json Transfer-Encoding: @@ -30,5 +30,5 @@ http_interactions: encoding: UTF-8 string: '{"error":{"message":"Parameters are not valid","statuscode":400}}' http_version: - recorded_at: Mon, 12 Mar 2018 14:27:51 GMT + recorded_at: Mon, 26 Mar 2018 15:09:25 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/company_postcode_form_valid_postcode.yml b/spec/cassettes/company_postcode_form_valid_postcode.yml index bf309cbdf..803caf92f 100644 --- a/spec/cassettes/company_postcode_form_valid_postcode.yml +++ b/spec/cassettes/company_postcode_form_valid_postcode.yml @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 12 Mar 2018 14:22:52 GMT + - Mon, 26 Mar 2018 15:09:20 GMT Content-Type: - application/json Content-Encoding: @@ -35,5 +35,5 @@ http_interactions: string: !binary |- H4sIAAAAAAAAAOWUUW+bMBDHv4rlZx6gaULWN1NQE42aypBNXdUHJziJNbCRMduqad+9x8JSIN1LlU2T9oDA/7PvfP/7iYfvuNRKfhYGX2HPdd95/sydXbrYwU1l1IlYSCVqfPWAF4TdphFFNyxZ3UEgjAiN2D1iCQnxo4Ot/tqeDtgyzZIYNlS6thudi1ZMPTQlCxAFr61UO9Am07k3aSsobez+oHn+xWzug7bRjbLmCSRY5KISKhfKxnrDC2nHcrY3utntt9yIQ4TnpVSytoZb+UUQI/jgYkWbhjR2rw0kW1U5tyKE53DY6Cde3HJZjAMVN1byAhYDKxyUsWUSJikKCH3voL4vDuqqwsfRgrpZB40scmiZ8rJLvh4q/ZQQba/6q8Vux8B+B2uz49AyNKxVt2M8sGOJplz/nH43o2S7lRsR6G/9AJgL7Zbg7ssdc92sCxG+No0fTh+ryaXrebMXoo7rI0yUZCtGYhTRm5jQ8Dw4XbjTE5x8d/7P4zQyw0GLhC0/JRTeqzQ6E1GDnG9F6nRsfxkqfwSV34cqW7DlhwixiEYfSRBHKbqLr//vP9WrlpyJqLdC9Lsx/VGUHp8B5v82jvgGAAA= http_version: - recorded_at: Mon, 12 Mar 2018 14:27:50 GMT + recorded_at: Mon, 26 Mar 2018 15:09:22 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/registration_number_form_changed_company_no.yml b/spec/cassettes/registration_number_form_changed_company_no.yml index 85585ab39..cb364d057 100644 --- a/spec/cassettes/registration_number_form_changed_company_no.yml +++ b/spec/cassettes/registration_number_form_changed_company_no.yml @@ -23,7 +23,7 @@ http_interactions: message: OK headers: Date: - - Tue, 13 Mar 2018 10:16:50 GMT + - Wed, 28 Mar 2018 06:58:26 GMT Content-Type: - application/json Content-Length: @@ -51,7 +51,7 @@ http_interactions: X-Ratelimit-Remain: - '595' X-Ratelimit-Reset: - - '1520936486' + - '1522220579' X-Ratelimit-Window: - 5m Server: @@ -62,5 +62,5 @@ http_interactions: House Woodland Road","postal_code":"CT18 8DL","address_line_2":"Lyminge"},"accounts":{"last_accounts":{"period_end_on":"2017-02-28","period_start_on":"2016-03-01","made_up_to":"2017-02-28"},"accounting_reference_date":{"day":"28","month":"02"},"overdue":false,"next_due":"2018-11-30","next_made_up_to":"2018-02-28","next_accounts":{"overdue":false,"due_on":"2018-11-30","period_end_on":"2018-02-28","period_start_on":"2017-03-01"}},"company_name":"JIM GARRAHY''S FUDGE KITCHEN LIMITED","date_of_creation":"1983-03-24","sic_codes":["10822"],"undeliverable_registered_office_address":false,"last_full_members_list_date":"2015-11-20","type":"ltd","has_been_liquidated":false,"company_number":"01709418","jurisdiction":"england-wales","has_insolvency_history":false,"etag":"079ea458cdac90941922af7f7742f1d7cdf14cd1","has_charges":true,"company_status":"active","confirmation_statement":{"next_due":"2018-12-04","next_made_up_to":"2018-11-20","overdue":false,"last_made_up_to":"2017-11-20"},"links":{"self":"/company/01709418","filing_history":"/company/01709418/filing-history","officers":"/company/01709418/officers","charges":"/company/01709418/charges","persons_with_significant_control_statements":"/company/01709418/persons-with-significant-control-statements"},"registered_office_is_in_dispute":false,"can_file":true}' http_version: - recorded_at: Tue, 13 Mar 2018 10:16:47 GMT + recorded_at: Wed, 28 Mar 2018 06:58:26 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/registration_number_form_inactive_company_no.yml b/spec/cassettes/registration_number_form_inactive_company_no.yml index 20c40eb0a..8be2c004e 100644 --- a/spec/cassettes/registration_number_form_inactive_company_no.yml +++ b/spec/cassettes/registration_number_form_inactive_company_no.yml @@ -23,7 +23,7 @@ http_interactions: message: OK headers: Date: - - Tue, 13 Mar 2018 10:16:27 GMT + - Wed, 28 Mar 2018 06:58:00 GMT Content-Type: - application/json Content-Length: @@ -51,7 +51,7 @@ http_interactions: X-Ratelimit-Remain: - '596' X-Ratelimit-Reset: - - '1520936486' + - '1522220579' X-Ratelimit-Window: - 5m Server: @@ -63,5 +63,5 @@ http_interactions: Elizabeth House","address_line_2":"54-58 High Street"},"undeliverable_registered_office_address":false,"company_name":"DIRECT SKIPS UK LTD","annual_return":{"last_made_up_to":"2014-06-11"},"jurisdiction":"england-wales","etag":"1cdef5bc2a020b3e9003b086033b64b78bcb28f6","company_status":"dissolved","has_insolvency_history":false,"has_charges":false,"links":{"self":"/company/07281919","filing_history":"/company/07281919/filing-history","officers":"/company/07281919/officers"},"date_of_cessation":"2016-01-05","can_file":false}' http_version: - recorded_at: Tue, 13 Mar 2018 10:16:23 GMT + recorded_at: Wed, 28 Mar 2018 06:58:00 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/registration_number_form_not_found_company_no.yml b/spec/cassettes/registration_number_form_not_found_company_no.yml index d480c48ec..cf45c193f 100644 --- a/spec/cassettes/registration_number_form_not_found_company_no.yml +++ b/spec/cassettes/registration_number_form_not_found_company_no.yml @@ -23,7 +23,7 @@ http_interactions: message: Not Found headers: Date: - - Tue, 13 Mar 2018 10:16:27 GMT + - Wed, 28 Mar 2018 06:58:00 GMT Content-Type: - application/json Content-Length: @@ -51,14 +51,14 @@ http_interactions: X-Ratelimit-Remain: - '597' X-Ratelimit-Reset: - - '1520936486' + - '1522220579' X-Ratelimit-Window: - 5m Server: - CompaniesHouse body: encoding: UTF-8 - string: '{"errors":[{"error":"company-profile-not-found","type":"ch:service"}]}' + string: '{"errors":[{"type":"ch:service","error":"company-profile-not-found"}]}' http_version: - recorded_at: Tue, 13 Mar 2018 10:16:23 GMT + recorded_at: Wed, 28 Mar 2018 06:58:00 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/registration_number_form_short_company_no.yml b/spec/cassettes/registration_number_form_short_company_no.yml index 89c9d08e5..800fc6445 100644 --- a/spec/cassettes/registration_number_form_short_company_no.yml +++ b/spec/cassettes/registration_number_form_short_company_no.yml @@ -23,7 +23,7 @@ http_interactions: message: OK headers: Date: - - Tue, 13 Mar 2018 10:16:26 GMT + - Wed, 28 Mar 2018 06:57:59 GMT Content-Type: - application/json Content-Length: @@ -51,7 +51,7 @@ http_interactions: X-Ratelimit-Remain: - '598' X-Ratelimit-Reset: - - '1520936486' + - '1522220579' X-Ratelimit-Window: - 5m Server: @@ -64,5 +64,5 @@ http_interactions: Wycombe","region":"Bucks"},"jurisdiction":"england-wales","type":"ltd","undeliverable_registered_office_address":false,"sic_codes":["38110","38120","38210","38220"],"accounts":{"next_due":"2018-12-29","accounting_reference_date":{"day":"29","month":"03"},"next_accounts":{"due_on":"2018-12-29","period_start_on":"2017-03-25","overdue":false,"period_end_on":"2018-03-29"},"last_accounts":{"period_end_on":"2017-03-24","type":"full","made_up_to":"2017-03-24","period_start_on":"2016-03-26"},"next_made_up_to":"2018-03-29","overdue":false},"date_of_creation":"1969-01-16","has_insolvency_history":false,"etag":"71e17f2aaec9b698b7ff73a1cbf996dc9c88b933","has_charges":true,"company_status":"active","previous_company_names":[{"name":"BIFFA LIMITED","effective_from":"1969-01-16","ceased_on":"1986-04-22"}],"confirmation_statement":{"next_due":"2019-01-18","next_made_up_to":"2019-01-04","overdue":false,"last_made_up_to":"2018-01-04"},"links":{"self":"/company/00946107","filing_history":"/company/00946107/filing-history","officers":"/company/00946107/officers","charges":"/company/00946107/charges"},"registered_office_is_in_dispute":false,"can_file":true}' http_version: - recorded_at: Tue, 13 Mar 2018 10:16:23 GMT + recorded_at: Wed, 28 Mar 2018 06:57:59 GMT recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/registration_number_form_valid_company_no.yml b/spec/cassettes/registration_number_form_valid_company_no.yml index a3ddc2b8a..4960fab2a 100644 --- a/spec/cassettes/registration_number_form_valid_company_no.yml +++ b/spec/cassettes/registration_number_form_valid_company_no.yml @@ -23,7 +23,7 @@ http_interactions: message: OK headers: Date: - - Tue, 13 Mar 2018 10:16:26 GMT + - Wed, 28 Mar 2018 06:57:59 GMT Content-Type: - application/json Content-Length: @@ -51,7 +51,7 @@ http_interactions: X-Ratelimit-Remain: - '599' X-Ratelimit-Reset: - - '1520936486' + - '1522220579' X-Ratelimit-Window: - 5m Server: @@ -61,5 +61,5 @@ http_interactions: string: '{"type":"ltd","company_name":"0800 WASTE LTD.","has_insolvency_history":false,"accounts":{"next_made_up_to":"2017-12-31","overdue":false,"next_accounts":{"period_end_on":"2017-12-31","due_on":"2018-09-30","period_start_on":"2017-01-01","overdue":false},"last_accounts":{"made_up_to":"2016-12-31","period_start_on":"2016-01-01","period_end_on":"2016-12-31"},"accounting_reference_date":{"day":"31","month":"12"},"next_due":"2018-09-30"},"undeliverable_registered_office_address":false,"etag":"d1aac62a36df9712e7ef94c383439a6fa001fa84","company_number":"09360070","registered_office_address":{"address_line_1":"21 Haslam Avenue","postal_code":"SM3 9ND","region":"Surrey","locality":"Sutton"},"jurisdiction":"england-wales","date_of_creation":"2014-12-18","company_status":"active","has_charges":false,"sic_codes":["38110"],"last_full_members_list_date":"2015-12-18","confirmation_statement":{"last_made_up_to":"2017-12-15","overdue":false,"next_made_up_to":"2018-12-15","next_due":"2018-12-29"},"links":{"self":"/company/09360070","filing_history":"/company/09360070/filing-history","officers":"/company/09360070/officers"},"registered_office_is_in_dispute":false,"can_file":true}' http_version: - recorded_at: Tue, 13 Mar 2018 10:16:23 GMT + recorded_at: Wed, 28 Mar 2018 06:57:59 GMT recorded_with: VCR 4.0.0 diff --git a/spec/factories/forms/conviction_details_form.rb b/spec/factories/forms/conviction_details_form.rb index c65e81307..1c0a4ec9b 100644 --- a/spec/factories/forms/conviction_details_form.rb +++ b/spec/factories/forms/conviction_details_form.rb @@ -1,6 +1,14 @@ FactoryBot.define do factory :conviction_details_form do trait :has_required_data do + first_name "Foo" + last_name "Bar" + position "Baz" + dob_year 2000 + dob_month 1 + dob_day 1 + date_of_birth Date.new(2000, 1, 1) + initialize_with { new(create(:transient_registration, :has_required_data, workflow_state: "conviction_details_form")) } end end diff --git a/spec/factories/forms/key_people_form.rb b/spec/factories/forms/key_people_form.rb index 2a267b914..b4ca3ab0f 100644 --- a/spec/factories/forms/key_people_form.rb +++ b/spec/factories/forms/key_people_form.rb @@ -6,7 +6,7 @@ dob_year 2000 dob_month 1 dob_day 1 - date_of_birth Date.new(2002, 1, 1) + date_of_birth Date.new(2000, 1, 1) initialize_with { new(create(:transient_registration, :has_required_data, workflow_state: "key_people_form")) } end diff --git a/spec/factories/key_person.rb b/spec/factories/key_person.rb index f754c59a8..936dcf202 100644 --- a/spec/factories/key_person.rb +++ b/spec/factories/key_person.rb @@ -7,7 +7,14 @@ dob_day 1 dob_month 1 dob_year 2000 - person_type "Relevant" + end + + trait :key do + person_type "key" + end + + trait :relevant do + person_type "relevant" end end end diff --git a/spec/forms/conviction_details_forms_spec.rb b/spec/forms/conviction_details_forms_spec.rb index 1ef94a6b2..f112a2478 100644 --- a/spec/forms/conviction_details_forms_spec.rb +++ b/spec/forms/conviction_details_forms_spec.rb @@ -2,40 +2,75 @@ RSpec.describe ConvictionDetailsForm, type: :model do describe "#submit" do + let(:conviction_details_form) { build(:conviction_details_form, :has_required_data) } + context "when the form is valid" do - let(:conviction_details_form) { build(:conviction_details_form, :has_required_data) } - let(:valid_params) { { reg_identifier: conviction_details_form.reg_identifier } } + let(:valid_params) do + { reg_identifier: conviction_details_form.reg_identifier, + first_name: conviction_details_form.first_name, + last_name: conviction_details_form.last_name, + position: conviction_details_form.position, + dob_year: conviction_details_form.dob_year, + dob_month: conviction_details_form.dob_month, + dob_day: conviction_details_form.dob_day } + end it "should submit" do expect(conviction_details_form.submit(valid_params)).to eq(true) end + + it "should set a person_type of 'relevant'" do + conviction_details_form.submit(valid_params) + expect(conviction_details_form.new_person.person_type).to eq("relevant") + end end context "when the form is not valid" do - let(:conviction_details_form) { build(:conviction_details_form, :has_required_data) } let(:invalid_params) { { reg_identifier: "foo" } } it "should not submit" do expect(conviction_details_form.submit(invalid_params)).to eq(false) end end - end - describe "#reg_identifier" do - context "when a valid transient registration exists" do - let(:transient_registration) do - create(:transient_registration, - :has_required_data, - workflow_state: "conviction_details_form") + context "when the form is blank" do + let(:blank_params) do + { reg_identifier: conviction_details_form.reg_identifier, + first_name: "", + last_name: "", + position: "", + dob_year: "", + dob_month: "", + dob_day: "" } end - # Don't use FactoryBot for this as we need to make sure it initializes with a specific object - let(:conviction_details_form) { ConvictionDetailsForm.new(transient_registration) } - context "when a reg_identifier meets the requirements" do + context "when the transient registration already has enough people with convictions" do + before(:each) do + conviction_details_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data, :relevant)]) + end + + it "should submit" do + expect(conviction_details_form.submit(blank_params)).to eq(true) + end + end + + context "when the transient registration does not have enough people with convictions" do before(:each) do - conviction_details_form.reg_identifier = transient_registration.reg_identifier + conviction_details_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data, :key)]) + end + + it "should not submit" do + expect(conviction_details_form.submit(blank_params)).to eq(false) end + end + end + end + context "when a valid transient registration exists" do + let(:conviction_details_form) { build(:conviction_details_form, :has_required_data) } + + describe "#reg_identifier" do + context "when a reg_identifier meets the requirements" do it "is valid" do expect(conviction_details_form).to be_valid end @@ -51,6 +86,244 @@ end end end + + describe "#first_name" do + context "when a first_name meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a first_name is blank" do + before(:each) do + conviction_details_form.first_name = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a first_name is too long" do + before(:each) do + conviction_details_form.first_name = "gsm2lgu3q7cg5pcs02ftc1wtpx4lt5ghmyaclhe9qg9li7ibs5ldi3w3n1pt24pbfo0666bq" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#last_name" do + context "when a last_name meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a last_name is blank" do + before(:each) do + conviction_details_form.last_name = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a last_name is too long" do + before(:each) do + conviction_details_form.last_name = "gsm2lgu3q7cg5pcs02ftc1wtpx4lt5ghmyaclhe9qg9li7ibs5ldi3w3n1pt24pbfo0666bq" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#position" do + context "when a position meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a position is blank" do + before(:each) do + conviction_details_form.position = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a position is too long" do + before(:each) do + conviction_details_form.position = "gsm2lgu3q7cg5pcs02ftc1wtpx4lt5ghmyaclhe9qg9li7ibs5ldi3w3n1pt24pbfo0666bq" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#dob_day" do + context "when a dob_day meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a dob_day is blank" do + before(:each) do + conviction_details_form.dob_day = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_day is not an integer" do + before(:each) do + conviction_details_form.dob_day = "1.5" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_day is not in the correct range" do + before(:each) do + conviction_details_form.dob_day = "42" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#dob_month" do + context "when a dob_month meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a dob_month is blank" do + before(:each) do + conviction_details_form.dob_month = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_month is not an integer" do + before(:each) do + conviction_details_form.dob_month = "9.75" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_month is not in the correct range" do + before(:each) do + conviction_details_form.dob_month = "13" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#dob_year" do + context "when a dob_year meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when a dob_year is blank" do + before(:each) do + conviction_details_form.dob_year = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_year is not an integer" do + before(:each) do + conviction_details_form.dob_year = "3.14" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a dob_year is not in the correct range" do + before(:each) do + conviction_details_form.dob_year = (Date.today + 1.year).year.to_i + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + end + + describe "#date_of_birth" do + context "when a date_of_birth meets the requirements" do + it "is valid" do + expect(conviction_details_form).to be_valid + end + end + + context "when all the date of birth fields are empty" do + before(:each) do + conviction_details_form.dob_day = "" + conviction_details_form.dob_month = "" + conviction_details_form.dob_year = "" + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when a date of birth is not a valid date" do + before(:each) do + conviction_details_form.date_of_birth = nil + end + + it "is not valid" do + expect(conviction_details_form).to_not be_valid + end + end + + context "when the date of birth is below the age limit" do + before(:each) do + conviction_details_form.date_of_birth = Date.today + end + + it "should not be valid" do + expect(conviction_details_form).to_not be_valid + end + end + end end describe "#transient_registration" do diff --git a/spec/forms/key_people_forms_spec.rb b/spec/forms/key_people_forms_spec.rb index 061f58c9d..f3a1e26c5 100644 --- a/spec/forms/key_people_forms_spec.rb +++ b/spec/forms/key_people_forms_spec.rb @@ -17,6 +17,11 @@ it "should submit" do expect(key_people_form.submit(valid_params)).to eq(true) end + + it "should set a person_type of 'key'" do + key_people_form.submit(valid_params) + expect(key_people_form.new_person.person_type).to eq("key") + end end context "when the form is not valid" do @@ -39,7 +44,7 @@ context "when the transient registration already has enough key people" do before(:each) do - key_people_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data)]) + key_people_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data, :key)]) key_people_form.business_type = "overseas" end @@ -50,7 +55,7 @@ context "when the transient registration does not have enough key people" do before(:each) do - key_people_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data)]) + key_people_form.transient_registration.update_attributes(keyPeople: [build(:key_person, :has_required_data, :key)]) key_people_form.business_type = "partnership" end @@ -67,7 +72,7 @@ create(:transient_registration, :has_required_data, business_type: "soleTrader", - keyPeople: [build(:key_person, :has_required_data)]) + keyPeople: [build(:key_person, :has_required_data, :key)]) end let(:key_people_form) { KeyPeopleForm.new(transient_registration) } diff --git a/spec/requests/conviction_details_forms_spec.rb b/spec/requests/conviction_details_forms_spec.rb index a3fdada39..750f8698b 100644 --- a/spec/requests/conviction_details_forms_spec.rb +++ b/spec/requests/conviction_details_forms_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe "ConvictionDetailsForms", type: :request do - describe "GET new_conviction_details_path" do + describe "GET new_conviction_details_form_path" do context "when a valid user is signed in" do let(:user) { create(:user) } before(:each) do @@ -56,12 +56,25 @@ context "when valid params are submitted" do let(:valid_params) { { - reg_identifier: transient_registration[:reg_identifier] + reg_identifier: transient_registration[:reg_identifier], + first_name: "Foo", + last_name: "Bar", + position: "Baz", + dob_day: "1", + dob_month: "1", + dob_year: "2000" } } + it "increases the total number of people" do + total_people_count = transient_registration.keyPeople.count + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count + 1) + end + it "updates the transient registration" do - # TODO: Add test once data is submitted through the form + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.last.first_name).to eq(valid_params[:first_name]) end it "returns a 302 response" do @@ -73,12 +86,62 @@ post conviction_details_forms_path, conviction_details_form: valid_params expect(response).to redirect_to(new_contact_name_form_path(transient_registration[:reg_identifier])) end + + context "when there is already a relevant conviction person" do + let(:relevant_conviction_person) { build(:key_person, :has_required_data, :relevant) } + + before(:each) do + transient_registration.update_attributes(keyPeople: [relevant_conviction_person]) + end + + it "increases the total number of people" do + total_people_count = transient_registration.keyPeople.count + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count + 1) + end + + it "does not replace the existing relevant conviction person" do + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.first.first_name).to eq(relevant_conviction_person.first_name) + end + end + + context "when there is already a key person" do + let(:key_person) { build(:key_person, :has_required_data, :key) } + + before(:each) do + transient_registration.update_attributes(keyPeople: [key_person]) + end + + it "increases the total number of people" do + total_people_count = transient_registration.keyPeople.count + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count + 1) + end + + it "does not replace the existing key person" do + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople.first.first_name).to eq(key_person.first_name) + end + end + + context "when the submit params say to add another" do + it "redirects to the conviction_details form" do + post conviction_details_forms_path, conviction_details_form: valid_params, commit: I18n.t("conviction_details_forms.new.add_person_link") + expect(response).to redirect_to(new_conviction_details_form_path(transient_registration[:reg_identifier])) + end + end end context "when invalid params are submitted" do let(:invalid_params) { { - reg_identifier: "foo" + reg_identifier: "foo", + first_name: "", + last_name: "", + dob_day: "31", + dob_month: "02", + dob_year: "2000" } } @@ -87,9 +150,50 @@ expect(response).to have_http_status(302) end - it "does not update the transient registration" do + it "does not increase the total number of people" do + total_people_count = transient_registration.keyPeople.count post conviction_details_forms_path, conviction_details_form: invalid_params - expect(transient_registration.reload[:reg_identifier]).to_not eq(invalid_params[:reg_identifier]) + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count) + end + + context "when there is already a key person" do + let(:existing_key_person) { build(:key_person, :has_required_data, :key) } + + before(:each) do + transient_registration.update_attributes(keyPeople: [existing_key_person]) + end + + it "does not replace the existing key person" do + post conviction_details_forms_path, conviction_details_form: invalid_params + expect(transient_registration.reload.keyPeople.first.first_name).to eq(existing_key_person.first_name) + end + end + + context "when the submit params say to add another" do + it "returns a 302 response" do + post conviction_details_forms_path, conviction_details_form: invalid_params, commit: I18n.t("conviction_details_forms.new.add_person_link") + expect(response).to have_http_status(302) + end + end + end + + context "when blank params are submitted" do + let(:blank_params) { + { + reg_identifier: "foo", + first_name: "", + last_name: "", + position: "", + dob_day: "", + dob_month: "", + dob_year: "" + } + } + + it "does not increase the total number of people" do + total_people_count = transient_registration.keyPeople.count + post conviction_details_forms_path, conviction_details_form: blank_params + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count) end end end @@ -104,12 +208,19 @@ let(:valid_params) { { - reg_identifier: transient_registration[:reg_identifier] + reg_identifier: transient_registration[:reg_identifier], + first_name: "Foo", + last_name: "Bar", + position: "Baz", + dob_day: "1", + dob_month: "1", + dob_year: "2000" } } it "does not update the transient registration" do - # TODO: Add test once data is submitted through the form + post conviction_details_forms_path, conviction_details_form: valid_params + expect(transient_registration.reload.keyPeople).to_not exist end it "returns a 302 response" do @@ -175,4 +286,59 @@ end end end + + describe "DELETE delete_person_conviction_details_forms_path" do + context "when a valid user is signed in" do + let(:user) { create(:user) } + before(:each) do + sign_in(user) + end + + context "when a valid transient registration exists" do + let(:transient_registration) do + create(:transient_registration, + :has_required_data, + account_email: user.email, + workflow_state: "conviction_details_form") + end + + context "when the registration has key people" do + let(:key_person_a) { build(:key_person, :has_required_data, :key) } + let(:key_person_b) { build(:key_person, :has_required_data, :key) } + + before(:each) do + transient_registration.update_attributes(keyPeople: [key_person_a, key_person_b]) + end + + context "when the delete person action is triggered" do + it "returns a 302 response" do + delete delete_person_conviction_details_forms_path(key_person_a[:id]), reg_identifier: transient_registration.reg_identifier + expect(response).to have_http_status(302) + end + + it "redirects to the key people form" do + delete delete_person_conviction_details_forms_path(key_person_a[:id]), reg_identifier: transient_registration.reg_identifier + expect(response).to redirect_to(new_conviction_details_form_path(transient_registration[:reg_identifier])) + end + + it "reduces the total number of people" do + total_people_count = transient_registration.keyPeople.count + delete delete_person_conviction_details_forms_path(key_person_a[:id]), reg_identifier: transient_registration.reg_identifier + expect(transient_registration.reload.keyPeople.count).to eq(total_people_count - 1) + end + + it "removes the key person" do + delete delete_person_conviction_details_forms_path(key_person_a[:id]), reg_identifier: transient_registration.reg_identifier + expect(transient_registration.reload.keyPeople.where(id: key_person_a[:id]).count).to eq(0) + end + + it "does not modify the other key people" do + delete delete_person_conviction_details_forms_path(key_person_a[:id]), reg_identifier: transient_registration.reg_identifier + expect(transient_registration.reload.keyPeople.where(id: key_person_b[:id]).count).to eq(1) + end + end + end + end + end + end end diff --git a/spec/requests/key_people_forms_spec.rb b/spec/requests/key_people_forms_spec.rb index 60d2740ef..ec1eeee0e 100644 --- a/spec/requests/key_people_forms_spec.rb +++ b/spec/requests/key_people_forms_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe "KeyPeopleForms", type: :request do - describe "GET new_key_people_path" do + describe "GET new_key_people_form_path" do context "when a valid user is signed in" do let(:user) { create(:user) } before(:each) do @@ -87,7 +87,7 @@ end context "when there is already a key person" do - let(:existing_key_person) { build(:key_person) } + let(:existing_key_person) { build(:key_person, :has_required_data, :key) } before(:each) do transient_registration.update_attributes(keyPeople: [existing_key_person]) @@ -118,6 +118,49 @@ end end + context "when there is a relevant conviction person" do + let(:relevant_conviction_person) { build(:key_person, :has_required_data, :relevant) } + + before(:each) do + transient_registration.update_attributes(keyPeople: [relevant_conviction_person]) + end + + context "when there can be multiple key people" do + it "increases the number of key people" do + key_people_count = transient_registration.keyPeople.count + post key_people_forms_path, key_people_form: valid_params + expect(transient_registration.reload.keyPeople.count).to eq(key_people_count + 1) + end + + it "does not replace the relevant conviction person" do + post key_people_forms_path, key_people_form: valid_params + expect(transient_registration.reload.keyPeople.first.first_name).to eq(relevant_conviction_person.first_name) + end + end + + context "when there can only be one key person" do + before(:each) do + transient_registration.update_attributes(business_type: "soleTrader") + end + + it "increases the number of key people" do + key_people_count = transient_registration.keyPeople.count + post key_people_forms_path, key_people_form: valid_params + expect(transient_registration.reload.keyPeople.count).to eq(key_people_count + 1) + end + + it "adds the new key person" do + post key_people_forms_path, key_people_form: valid_params + expect(transient_registration.reload.keyPeople.last.first_name).to eq(valid_params[:first_name]) + end + + it "does not replace the relevant conviction person" do + post key_people_forms_path, key_people_form: valid_params + expect(transient_registration.reload.keyPeople.first.first_name).to eq(relevant_conviction_person.first_name) + end + end + end + context "when the submit params say to add another" do it "redirects to the key_people form" do post key_people_forms_path, key_people_form: valid_params, commit: I18n.t("key_people_forms.new.add_person_link") @@ -150,7 +193,7 @@ end context "when there is already a key person" do - let(:existing_key_person) { build(:key_person) } + let(:existing_key_person) { build(:key_person, :has_required_data, :key) } before(:each) do transient_registration.update_attributes(keyPeople: [existing_key_person]) @@ -307,8 +350,8 @@ end context "when the registration has key people" do - let(:key_person_a) { build(:key_person, :has_required_data) } - let(:key_person_b) { build(:key_person, :has_required_data) } + let(:key_person_a) { build(:key_person, :has_required_data, :key) } + let(:key_person_b) { build(:key_person, :has_required_data, :key) } before(:each) do transient_registration.update_attributes(keyPeople: [key_person_a, key_person_b])+ <% if form.errors[:last_name].any? %> + + + <% end %> + + <%= f.label :last_name, t(".last_name"), class: "form-label" %> + <%= f.text_field :last_name, value: form.last_name, class: "form-control" %> +