module Workarea module Storefront decorate CopyingGuestOrderIntegrationTest, with: :flow_io do def test_using_new_data order = Order.desc(:created_at).first # Setup to conform with complete_checkout expectations Shipping::Service.destroy_all delete storefront.cart_item_path(order.items.first) create_tax_category( name: 'Sales Tax', code: '001', rates: [{ percentage: 0.07, country: 'US', region: 'PA' }] ) @product = create_product( name: 'Integration Product', variants: [ { sku: 'SKU1', regular: 6.to_m, tax_code: '001', on_sale: true, sale: 5.to_m } ] ) shipping_service = create_shipping_service( carrier: 'UPS', name: 'Ground', service_code: '03', tax_code: '001', rates: [{ price: 7.to_m }] ) complete_checkout assert_equal(2, Order.count) order.reload shipping = Shipping.where(order_id: order.id).first payment = Payment.find(order.id) assert_not_equal(order, @original) assert_not_equal(shipping, @original_shipping) assert_not_equal(payment, @original_payment) assert(order.placed?) assert_equal('bcrouse@workarea.com', order.email) assert_equal('127.0.0.1', order.ip_address) assert(order.user_activity_id.present?) assert_equal(admin_user.id.to_s, order.checkout_by_id) assert_equal(1, order.items.length) assert_equal(product.id, order.items.first.product_id) assert_equal(product.skus.first, order.items.first.sku) assert_equal(2, order.items.first.quantity) assert(order.items.first.product_attributes.present?) assert_equal(10.to_m, order.items.first.total_price) assert_equal(1, order.items.first.price_adjustments.length) assert_equal(10.to_m, order.items.first.price_adjustments.first.amount) assert_equal(10.to_m, order.subtotal_price) assert_equal(7.to_m, order.shipping_total) assert_equal(1.19.to_m, order.tax_total) assert_equal(18.19.to_m, order.total_price) assert_equal(3, shipping.price_adjustments.length) assert_equal(7.to_m, shipping.price_adjustments.first.amount) assert_equal(0.7.to_m, shipping.price_adjustments.second.amount) assert_equal(0.49.to_m, shipping.price_adjustments.third.amount) assert_equal(7.to_m, shipping.shipping_total) assert_equal(1.19.to_m, shipping.tax_total) assert_equal('Ben', shipping.address.first_name) assert_equal('Crouse', shipping.address.last_name) assert_equal('22 S. 3rd St.', shipping.address.street) assert_equal('Philadelphia', shipping.address.city) assert_equal('PA', shipping.address.region) assert_equal('19106', shipping.address.postal_code) assert_equal(Country['US'], shipping.address.country) assert_equal('2159251800', shipping.address.phone_number) assert_equal('UPS', shipping.shipping_service.carrier) assert_equal('Ground', shipping.shipping_service.name) assert_equal('03', shipping.shipping_service.service_code) assert_equal('001', shipping.shipping_service.tax_code) payment = Payment.find(order.id) assert_equal('Ben', payment.address.first_name) assert_equal('Crouse', payment.address.last_name) assert_equal('12 N. 3rd St.', payment.address.street) assert_equal('Philadelphia', payment.address.city) assert_equal('PA', payment.address.region) assert_equal('19106', payment.address.postal_code) assert_equal(Country['US'], payment.address.country) assert_equal('2159251800', payment.address.phone_number) assert_equal('Test Card', payment.credit_card.issuer) assert_equal('XXXX-XXXX-XXXX-1', payment.credit_card.display_number) assert_equal(1, payment.credit_card.month) assert_equal(2023, payment.credit_card.year) refute(payment.credit_card.token.blank?) assert(payment.credit_card.saved_card_id.blank?) assert_equal(1, payment.credit_card.transactions.length) assert_equal(18.19.to_m, payment.credit_card.transactions.first.amount) refute(payment.credit_card.transactions.first.response.blank?) end end end end