Skip to content

Commit

Permalink
fix(#4134): inconsistent request behavior
Browse files Browse the repository at this point in the history
Fixes #4134

Individual requests and Quantity requests are very similar
but have small differences in behavior:
- Quantity requests allow comment only requests
- Quantity requests filter out blank lines

This PR will unify the behavior so both Individual and Quantity requests
will act like Quantity requests.
  • Loading branch information
elasticspoon committed Feb 29, 2024
1 parent 37f4a62 commit f72eef8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,4 @@ DEPENDENCIES
webmock (~> 3.23)

BUNDLED WITH
2.5.4
2.5.6
3 changes: 2 additions & 1 deletion app/services/partners/family_request_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def valid?
end

def item_requests_attributes
@item_requests_attributes ||= family_requests_attributes.map do |fr_attr|
@item_requests_attributes ||= family_requests_attributes.filter_map do |fr_attr|
next if fr_attr[:item_id].blank? && fr_attr[:person_count].blank?
{
item_id: fr_attr[:item_id],
quantity: convert_person_count_to_item_quantity(item_id: fr_attr[:item_id], person_count: fr_attr[:person_count])&.to_i,
Expand Down
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@
t.integer "organization_id"
t.datetime "issued_at", precision: nil
t.string "agency_rep"
t.integer "state", default: 5, null: false
t.boolean "reminder_email_enabled", default: false, null: false
t.integer "state", default: 5, null: false
t.integer "delivery_method", default: 0, null: false
t.decimal "shipping_cost", precision: 8, scale: 2
t.index ["organization_id"], name: "index_distributions_on_organization_id"
Expand Down Expand Up @@ -840,7 +840,8 @@
end

create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.string "item_type"
t.string "{:null=>false}"
t.bigint "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
Expand Down
78 changes: 76 additions & 2 deletions spec/system/partners/managing_requests_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,57 @@
visit new_partners_individuals_request_path
end

context 'WHEN they create a request inproperly' do
context 'WHEN they create a request inproperly by not inputting anything' do
before do
click_button 'Submit Essentials Request'
end

it 'should show an error message with the instructions ' do
expect(page).to have_content('Oops! Something went wrong with your Request')
expect(page).to have_content('Ensure each line item has a item selected AND a quantity greater than 0.')
expect(page).to have_content('Still need help? Submit a support ticket here and we will do our best to follow up with you via email.')
end
end

context 'WHEN they create a request with only a comment' do
before do
fill_in 'Comments', with: Faker::Lorem.paragraph
end

it 'should be created without any issue' do
expect { click_button 'Submit Essentials Request' }.to change { Request.count }.by(1)

expect(current_path).to eq(partners_request_path(Request.last.id))
expect(page).to have_content('Request has been successfully created!')
expect(page).to have_content("#{partner.organization.name} should have received the request.")
end
end

context 'WHEN they create a request with blank lines' do
before do
fill_in 'Comments', with: Faker::Lorem.paragraph

# fill in an item
click_link 'Add Another Item'
item = partner_user.partner.organization.valid_items.sample
last_row = find_all('tr').last
last_row.find('option', text: item[:name], exact_text: true).select_option
last_row.find_all('.form-control').last.fill_in(with: 1)

# Trigger another row but keep it empty. It should still be valid!
click_link 'Add Another Item'
end

it 'should be created without any issue' do
expect { click_button 'Submit Essentials Request' }.to change { Request.count }.by(1)

expect(current_path).to eq(partners_request_path(Request.last.id))
expect(page).to have_content('Request has been successfully created!')
expect(page).to have_content("#{partner.organization.name} should have received the request.")
end
end

context 'WHEN they create a request completely empty request' do
before do
click_button 'Submit Essentials Request'
end
Expand Down Expand Up @@ -142,7 +192,7 @@
visit new_partners_request_path
end

context 'WHEN they create a request inproperly by not inputting anything' do
context 'WHEN they create a request completely empty request' do
before do
click_button 'Submit Essentials Request'
end
Expand All @@ -168,6 +218,30 @@
end
end

context 'WHEN they create a request with blank lines' do
before do
fill_in 'Comments', with: Faker::Lorem.paragraph

# fill in an item
click_link 'Add Another Item'
item = partner_user.partner.organization.valid_items.sample
last_row = find_all('tr').last
last_row.find('option', text: item[:name], exact_text: true).select_option
last_row.find_all('.form-control').last.fill_in(with: 1)

# Trigger another row but keep it empty. It should still be valid!
click_link 'Add Another Item'
end

it 'should be created without any issue' do
expect { click_button 'Submit Essentials Request' }.to change { Request.count }.by(1)

expect(current_path).to eq(partners_request_path(Request.last.id))
expect(page).to have_content('Request has been successfully created!')
expect(page).to have_content("#{partner.organization.name} should have received the request.")
end
end

context 'WHEN they create a request properly' do
let(:items_to_select) { partner_user.partner.organization.valid_items.sample(3) }
let(:item_details) do
Expand Down

0 comments on commit f72eef8

Please sign in to comment.