Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # confirm reservation address update
- def test_discount_code_confirm_free_purchase
- # Removing the sku units assigned for publish compliance
- SkuUnit.delete_all
- # alice comes to the site
- a, b = two_users_come_to_site
- alice_sess = a[:session]
- alice = a[:obj]
- product = product_with_only_one_sku_available
- offer = new_orange_dot_sale(product)
- Sku.any_instance.stubs(:price).returns(Money.new(38500))
- ensure_one_sku_unit_available(offer, product)
- # initialise number of paid orders
- paid_order_count = Order.count(:conditions => ["status='paid'"])
- # add discount voucher for alice to cover the purchase
- # 398.0, offer.price + offer.shipping_fee
- DiscountVoucher.destroy_all
- DiscountVoucher.new(:user_id => alice.id, :amount => 40000, :expires_at => (Time.now + 10.days).to_s(:db)).save!
- alice.reload
- assert_equal 1, alice.available_discount_vouchers.size
- # check one sku available
- assert_equal 1, offer.quantity_available
- assert offer.available?
- # visit's the latest page
- user_goes_to_latest(alice_sess)
- user_goes_to_latest_offer_page(alice_sess, offer)
- user_goes_to_refresh_sale(alice_sess, offer, :available)
- # add to cart
- user_clicks_on_buy_button(alice_sess, offer)
- # goes to confirm
- alice_sess.https!
- alice_sess.get confirm_reservation_store_path
- # CHANGE HERE
- # 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.
- # This means we fail the checks that would redirect us.
- ### alice_sess.assert_response :redirect
- # FIXME: what about a user who wants to purchase just using a discount voucher???
- # alice confirms her reservation
- ### alice_sess.post_via_redirect confirm_reservation_address_update_store_path,
- ### :stored_credit_card => {
- ### :billing_title => 'Ms',
- ### :billing_first_name => 'Alice',
- ### :billing_last_name => 'C',
- ### :billing_address1 => '324 East 9th St',
- ### :billing_address2 => '2b',
- ### :billing_city => 'Tempe',
- ### :billing_state => 'AZ',
- ### :billing_zip => '10003',
- ### :shipping_telephone => '212-555-1234'
- ### }, :credit_card => credit_card_hash, :shipping_same_as_billing => '1'
- alice_sess.assert_response :success
- alice_sess.assert_template 'confirm_reservation'
- alice_sess.assert_match(/checkout\.png/, alice_sess.response.body)
- # check for discount vouchers
- assert_match /Applied Credits/, alice_sess.response.body
- # dirty check whether the total we expect is the same >> offer.price + offer.shipping_fee = 398
- assert_match /394.95/, alice_sess.response.body
- # dirty check whether the discount code is available on the page
- assert_match /store\/set_discount_code/, alice_sess.response.body
- assert_match /amount=40000/, alice_sess.response.body
- # apply discount code
- alice_sess.xml_http_request(:post, '/store/set_discount_code/?amount=40000', :frequency => 1)
- # quickly go back to confirm reservation page to verify the changes as the requests are made through ajax
- alice_sess.https!
- alice_sess.get confirm_reservation_store_path
- alice_sess.assert_response :success
- alice_sess.assert_match(/checkout\.png/, alice_sess.response.body)
- # free purchase
- assert_match /0.00/, alice_sess.response.body
- session_id = alice_sess.request.session_options[:id]
- #CHANGE HERE
- # I don't believe there is a stored credit card in the session because the order was setup using a seeded stored credit card.
- # We cannot pass in another stored credit card value for the value because of the way the @preferred_credit_card is written
- user_places_order(alice, alice_sess)
- ####user_places_order(alice, alice_sess, :stored_credit_card => alice.reload.credit_cards_for_session(session_id).first.id)
- # check thank you page
- assert_match /Thanks For Your Order/, alice_sess.response.body #/
- # check whether status has changed to paid
- assert_equal paid_order_count+1, Order.count(:conditions => ["status='paid'"])
- assert_equal 0, alice.available_discount_vouchers.size
- # check that the sku unit is marked as sold (as we weren't doing this correctly before)
- assert_equal 'sold', Order.find(:first, :order => "id desc").line_items.first.sku_units.first.state
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement