i have a system test where i'm doing some things s...
# support
e
i have a system test where i'm doing some things such as
Copy code
Spree::Order.create!(user: @contract.initiated_to_user)
    product = Spree::Product.all.first
    line_item = Spree::LineItem.create!(order: order, product: product, price: 100, quantity: 1)
    order.next!
    order.complete!
and it seems to be nondeterministic as to whether the line item's
item_total_before_tax
has a value of
100
... is there a better way to create an order and add a line item, and then complete the order? i have removed a few steps to simplify
Copy code
base.remove_checkout_step :address
        base.remove_checkout_step :delivery
i'm not sure if there is a script out there somewhere which creates and then completes an order, i'd start there if that existed. i did see the order walkthrough which is similar but it uses factories, which isn't appropriate here
a
You'll probably want to use
OrderContents
to add the item to the order instead of trying to create the line item directly. (https://github.com/solidusio/solidus/blob/main/core/app/models/spree/order_contents.rb) Something like:
Copy code
order.contents.add(product.variants.first)
order.contents.advance # Will call next until it can't anymore.
order.complete!
It might not exactly fit your needs, because it expects to be provided address and shipment details, but it could be a good source for seeing how completed orders can be created programatically outside of tests.
🙌 1