Skip to content

Commit

Permalink
Simplify rspec
Browse files Browse the repository at this point in the history
* Use TestInventory instead of distribution endpoint in rspec
* Use build(:line_item) instead of as_json merge
  • Loading branch information
jimmyli97 committed Jul 23, 2024
1 parent dfaa0e7 commit ba5af77
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions spec/requests/donations_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,14 @@
original_quantity = 100
original_source = Donation::SOURCES[:manufacturer]
original_date = DateTime.new(2024)
donation = create(:manufacturer_donation, issued_at: original_date, organization: organization, storage_location: storage_location, source: original_source)
add_item_donation = donation.as_json.merge({
line_items_attributes: {
"0": { item_id: item.id, quantity: original_quantity },
"1": { item_id: item_to_delete.id, quantity: 1 }
}
})

put donation_path(id: donation.id, donation: add_item_donation)
donation = build(:manufacturer_donation, issued_at: original_date, organization: organization, storage_location: storage_location, source: original_source)
donation.line_items << build(:line_item, item: item, quantity: original_quantity)
donation.line_items << build(:line_item, item: item_to_delete, quantity: 1)

distribution = {
storage_location_id: storage_location.id,
partner_id: create(:partner).id,
delivery_method: :delivery,
line_items_attributes: {
"0": { item_id: item.id, quantity: 90 }
}
}
DonationCreateService.call(donation)

post distributions_path(distribution: distribution, format: :turbo_stream)
# simulate distribution by setting item inventory to 10
TestInventory.create_inventory(organization, { storage_location.id => { item.id => 10, extra_item.id => 1 } })

edited_source = Donation::SOURCES[:product_drive]
edited_source_drive_name = "Test Product Drive"
Expand Down

0 comments on commit ba5af77

Please sign in to comment.