From 60a7d2dee11f830e05dc7cafd9ffbe89de84e21c Mon Sep 17 00:00:00 2001 From: Chris Gannon Date: Tue, 24 Oct 2023 13:35:15 +0100 Subject: [PATCH] enforce under three question on cloned notifications --- cosmetics-web/app/helpers/draft_helper.rb | 2 ++ .../helpers/responsible_persons/notifications_helper.rb | 7 +++++++ .../app/validators/accept_and_submit_validator.rb | 5 +++++ cosmetics-web/spec/factories/notification.rb | 1 + .../responsible_persons/notifications_helper_spec.rb | 8 ++++---- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cosmetics-web/app/helpers/draft_helper.rb b/cosmetics-web/app/helpers/draft_helper.rb index e80e3f8df4..bacd8527b8 100644 --- a/cosmetics-web/app/helpers/draft_helper.rb +++ b/cosmetics-web/app/helpers/draft_helper.rb @@ -47,6 +47,8 @@ def product_badge(notification) if notification.state_lower_than?(NotificationStateConcern::READY_FOR_NANOMATERIALS) in_progress_badge(id, :product) + elsif notification.under_three_years.nil? + in_progress_badge(id, :product) else complete_badge(id, :product) end diff --git a/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb b/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb index d47a817a59..08ce46526f 100644 --- a/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb +++ b/cosmetics-web/app/helpers/responsible_persons/notifications_helper.rb @@ -77,6 +77,13 @@ def notification_summary_product_rows(notification) actions: notification_step_action(notification, :under_three_years), } end, + if notification.under_three_years.nil? + { + key: { text: "For children under 3" }, + value: { text: "Not answered" }, + actions: notification_step_action(notification, :under_three_years), + } + end, { key: { text: "Number of items" }, value: { text: notification.components.length }, diff --git a/cosmetics-web/app/validators/accept_and_submit_validator.rb b/cosmetics-web/app/validators/accept_and_submit_validator.rb index 6e84135d27..377be61502 100644 --- a/cosmetics-web/app/validators/accept_and_submit_validator.rb +++ b/cosmetics-web/app/validators/accept_and_submit_validator.rb @@ -1,10 +1,15 @@ class AcceptAndSubmitValidator < ActiveModel::Validator def validate(notification) + validate_notification(notification) validate_nano_materials(notification) validate_image_uploads(notification) validate_ingredients(notification) end + def validate_notification(notification) + notification.errors.add :under_three_years, "You have not confirmed if the product is intended to be used on children under 3 years old" if notification.under_three_years.nil? + end + def validate_nano_materials(notification) missing_nano_materials = notification.missing_nano_materials if missing_nano_materials.present? diff --git a/cosmetics-web/spec/factories/notification.rb b/cosmetics-web/spec/factories/notification.rb index 7468b49f17..5019b8258e 100644 --- a/cosmetics-web/spec/factories/notification.rb +++ b/cosmetics-web/spec/factories/notification.rb @@ -3,6 +3,7 @@ responsible_person sequence(:product_name) { |n| "Product #{n}" } cpnp_reference { nil } + under_three_years { true } factory :draft_notification do state { NotificationStateConcern::COMPONENTS_COMPLETE } diff --git a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb index 943ba2e31b..e0a60de1a2 100644 --- a/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb +++ b/cosmetics-web/spec/helpers/responsible_persons/notifications_helper_spec.rb @@ -162,9 +162,9 @@ end describe "for children under 3" do - it "not included when not available for the notification" do + it "included when not available for the notification" do notification.under_three_years = nil - expect(summary_product_rows).not_to include(hash_including(key: { text: "For children under 3" })) + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "Not answered" } })) end it "included when notification product is for children under 3" do @@ -277,9 +277,9 @@ end describe "for children under 3" do - it "not included when not available for the notification" do + it "included when not available for the notification" do notification.under_three_years = nil - expect(summary_product_rows).not_to include(hash_including(key: { text: "For children under 3" })) + expect(summary_product_rows).to include(hash_including({ key: { text: "For children under 3" }, value: { text: "Not answered" }, actions: { items: [hash_including({ href: "#{product_href}/under_three_years" })] } })) end it "included when notification product is for children under 3" do