mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Changing format of changes object in standing order placement job
This commit is contained in:
@@ -38,11 +38,10 @@ class StandingOrderPlacementJob
|
||||
|
||||
def cap_quantity_and_store_changes(order)
|
||||
insufficient_stock_lines = order.insufficient_stock_lines
|
||||
return [] unless insufficient_stock_lines.present?
|
||||
insufficient_stock_lines.map do |line_item|
|
||||
quantity_was = line_item.quantity
|
||||
return {} unless insufficient_stock_lines.present?
|
||||
insufficient_stock_lines.each_with_object({}) do |line_item, changes|
|
||||
changes[line_item.id] = line_item.quantity
|
||||
line_item.cap_quantity_at_stock!
|
||||
{ line_item: line_item, quantity_was: quantity_was }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -49,10 +49,8 @@ describe StandingOrderPlacementJob do
|
||||
expect(line_item1.reload.quantity).to be 3 # not capped
|
||||
expect(line_item2.reload.quantity).to be 2 # capped
|
||||
expect(line_item3.reload.quantity).to be 0 # capped
|
||||
expect(changes).to eq [
|
||||
{ line_item: line_item2, quantity_was: 3},
|
||||
{ line_item: line_item3, quantity_was: 3}
|
||||
]
|
||||
expect(changes[line_item2.id]).to be 3
|
||||
expect(changes[line_item3.id]).to be 3
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user