Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. # confirm reservation address update
  2. def test_discount_code_confirm_free_purchase
  3. # Removing the sku units assigned for publish compliance
  4. SkuUnit.delete_all
  5.  
  6. # alice comes to the site
  7. a, b = two_users_come_to_site
  8. alice_sess = a[:session]
  9. alice = a[:obj]
  10.  
  11. product = product_with_only_one_sku_available
  12. offer = new_orange_dot_sale(product)
  13. Sku.any_instance.stubs(:price).returns(Money.new(38500))
  14. ensure_one_sku_unit_available(offer, product)
  15.  
  16. # initialise number of paid orders
  17. paid_order_count = Order.count(:conditions => ["status='paid'"])
  18.  
  19. # add discount voucher for alice to cover the purchase
  20. # 398.0, offer.price + offer.shipping_fee
  21. DiscountVoucher.destroy_all
  22. DiscountVoucher.new(:user_id => alice.id, :amount => 40000, :expires_at => (Time.now + 10.days).to_s(:db)).save!
  23. alice.reload
  24.  
  25. assert_equal 1, alice.available_discount_vouchers.size
  26.  
  27. # check one sku available
  28. assert_equal 1, offer.quantity_available
  29. assert offer.available?
  30.  
  31. # visit's the latest page
  32. user_goes_to_latest(alice_sess)
  33. user_goes_to_latest_offer_page(alice_sess, offer)
  34. user_goes_to_refresh_sale(alice_sess, offer, :available)
  35. # add to cart
  36. user_clicks_on_buy_button(alice_sess, offer)
  37.  
  38. # goes to confirm
  39. alice_sess.https!
  40. alice_sess.get confirm_reservation_store_path
  41.  
  42. # CHANGE HERE
  43. # We won't get directed to the address update path because the cart was set up with a seeded stored credit card and shipping id.
  44. # This means we fail the checks that would redirect us.
  45.  
  46. ### alice_sess.assert_response :redirect
  47.  
  48. # FIXME: what about a user who wants to purchase just using a discount voucher???
  49. # alice confirms her reservation
  50. ### alice_sess.post_via_redirect confirm_reservation_address_update_store_path,
  51. ### :stored_credit_card => {
  52. ### :billing_title => 'Ms',
  53. ### :billing_first_name => 'Alice',
  54. ### :billing_last_name => 'C',
  55. ### :billing_address1 => '324 East 9th St',
  56. ### :billing_address2 => '2b',
  57. ### :billing_city => 'Tempe',
  58. ### :billing_state => 'AZ',
  59. ### :billing_zip => '10003',
  60. ### :shipping_telephone => '212-555-1234'
  61. ### }, :credit_card => credit_card_hash, :shipping_same_as_billing => '1'
  62.  
  63.  
  64.  
  65. alice_sess.assert_response :success
  66. alice_sess.assert_template 'confirm_reservation'
  67. alice_sess.assert_match(/checkout\.png/, alice_sess.response.body)
  68.  
  69. # check for discount vouchers
  70. assert_match /Applied Credits/, alice_sess.response.body
  71. # dirty check whether the total we expect is the same >> offer.price + offer.shipping_fee = 398
  72. assert_match /394.95/, alice_sess.response.body
  73. # dirty check whether the discount code is available on the page
  74. assert_match /store\/set_discount_code/, alice_sess.response.body
  75. assert_match /amount=40000/, alice_sess.response.body
  76.  
  77. # apply discount code
  78. alice_sess.xml_http_request(:post, '/store/set_discount_code/?amount=40000', :frequency => 1)
  79.  
  80. # quickly go back to confirm reservation page to verify the changes as the requests are made through ajax
  81. alice_sess.https!
  82. alice_sess.get confirm_reservation_store_path
  83. alice_sess.assert_response :success
  84. alice_sess.assert_match(/checkout\.png/, alice_sess.response.body)
  85.  
  86. # free purchase
  87. assert_match /0.00/, alice_sess.response.body
  88.  
  89. session_id = alice_sess.request.session_options[:id]
  90.  
  91. #CHANGE HERE
  92. # I don't believe there is a stored credit card in the session because the order was setup using a seeded stored credit card.
  93. # We cannot pass in another stored credit card value for the value because of the way the @preferred_credit_card is written
  94. user_places_order(alice, alice_sess)
  95. ####user_places_order(alice, alice_sess, :stored_credit_card => alice.reload.credit_cards_for_session(session_id).first.id)
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. # check thank you page
  104. assert_match /Thanks For Your Order/, alice_sess.response.body #/
  105.  
  106. # check whether status has changed to paid
  107. assert_equal paid_order_count+1, Order.count(:conditions => ["status='paid'"])
  108. assert_equal 0, alice.available_discount_vouchers.size
  109.  
  110. # check that the sku unit is marked as sold (as we weren't doing this correctly before)
  111. assert_equal 'sold', Order.find(:first, :order => "id desc").line_items.first.sku_units.first.state
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement