Skip to content

Commit

Permalink
enforce under three question on cloned notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyevil committed Oct 24, 2023
1 parent 350ce51 commit 60a7d2d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cosmetics-web/app/helpers/draft_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
5 changes: 5 additions & 0 deletions cosmetics-web/app/validators/accept_and_submit_validator.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
1 change: 1 addition & 0 deletions cosmetics-web/spec/factories/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 60a7d2d

Please sign in to comment.