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

Improve input validation on Enterprise fees page #9960

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/controllers/admin/enterprise_fees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def check_enterprise_fee_input
:preferred_flat_percent, :preferred_amount,
:preferred_first_item, :preferred_additional_item,
:preferred_minimal_amount, :preferred_normal_amount,
:preferred_discount_amount, :preferred_per_unit
:preferred_discount_amount, :preferred_per_unit, :preferred_max_items, :preffered_currency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preffered_currency

I think there is a typo on preffered

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and the comments. I'll work on it 👍

)

next unless enterprise_fees
Expand Down
45 changes: 45 additions & 0 deletions spec/system/admin/enterprise_fees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,49 @@
options: ['First Distributor', 'Second Distributor'])
end
end

it "for enterprise fees FLEXIBLE RATE calculator should validate all fields and keep information when submission of form validation fails" do
# Given an enterprise
e = create(:supplier_enterprise, name: 'Feedme')

# Go to the enterprise fees page
login_as_admin_and_visit admin_enterprise_fees_path

# Fill in the fields for a new enterprise fee and click update
select 'Feedme', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Hello!'
select 'GST', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flexible Rate', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'

# See my fee and fields for the calculator and a success flash message
expect(page).to have_content "Your enterprise fees have been updated."
expect(page).to have_content "MAX ITEMS:"
expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_max_items"

# Fill in the calculator fields and click update
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_first_item',
with: "22.00"
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_additional_item',
with: "25.00"
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_max_items',
with: "10"
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_currency',
with: "AUD"
click_button 'Update'

# Then I should see the flash success message
expect(flash_message).to eq('Your enterprise fees have been updated.')

# Update the max input field with invalid input
expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_max_items"
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_max_items',
with: "invalid input"
click_button 'Update'

# Should return a flas error message and updated information should be kept
expect(flash_message).to eq('Invalid input. Please use only numbers. For example: 10, 5.5, -20')
expect(page).to have_selector 'input[value="10"]'
end
end