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

4134 fix inconsistent request behavior #4146

Merged
Merged
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 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
2 changes: 1 addition & 1 deletion 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
82 changes: 78 additions & 4 deletions spec/system/partners/managing_requests_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
expect(page.all('select[name="partners_family_request[items_attributes][0][item_id]"] option').map(&:text)).to eq(expected_items)
end

context 'WHEN they create a request inproperly' do
context 'WHEN they create a request improperly' do
before {
click_button 'Submit Essentials Request'
click_link 'Add Another Item'
Expand All @@ -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 improperly 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 @@ -123,7 +173,7 @@
expect(page.all('select[name="request[item_requests_attributes][0][item_id]"] option').map(&:text)).to eq(expected_items)
end

context 'WHEN they create a request inproperly' do
context 'WHEN they create a request improperly' do
before {
click_button 'Submit Essentials Request'
click_link 'Add Another Item'
Expand All @@ -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
Loading