application_charge_test.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. require 'test_helper'
  2. class ApplicationChargeTest < Test::Unit::TestCase
  3. def test_application_charge_create
  4. fake "application_charges", :method => :post, :status => 201, :body => load_fixture('application_charge')
  5. charge = ShopifyAPI::ApplicationCharge.create(
  6. name: "iPod Cleaning",
  7. price: 5.00,
  8. return_url: "http://google.com"
  9. )
  10. assert_equal 'https://this-is-my-test-shop.myshopify.com/admin/charges/803742/confirm_application_charge?signature=BAhpA55DDA%3D%3D--55b44e274e438c619be4631c804abcbcb6ee915a', charge.confirmation_url
  11. end
  12. def test_get_application_charge
  13. fake "application_charges/803742", :method => :get, :status => 201, :body => load_fixture('application_charge')
  14. charge = ShopifyAPI::ApplicationCharge.find(803742)
  15. assert_equal "iPod Cleaning", charge.name
  16. end
  17. def test_list_application_charges
  18. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  19. charges = ShopifyAPI::ApplicationCharge.find(:all)
  20. assert_equal 4, charges.size
  21. assert_equal "iPhone Case", charges.last.name
  22. end
  23. def test_list_pending_application_charges
  24. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  25. pending_charges = ShopifyAPI::ApplicationCharge.pending
  26. assert_equal 1, pending_charges.size
  27. assert_equal "Screen Replacement", pending_charges.first.name
  28. end
  29. def test_list_expired_application_charges
  30. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  31. expired_charges = ShopifyAPI::ApplicationCharge.expired
  32. assert_equal 1, expired_charges.size
  33. assert_equal "iPod Cleaning", expired_charges.first.name
  34. end
  35. def test_list_accepted_application_charges
  36. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  37. accepted_charges = ShopifyAPI::ApplicationCharge.accepted
  38. assert_equal 1, accepted_charges.size
  39. assert_equal "iPhone Case", accepted_charges.first.name
  40. end
  41. def test_list_declined_application_charges
  42. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  43. declined_charges = ShopifyAPI::ApplicationCharge.declined
  44. assert_equal 1, declined_charges.size
  45. assert_equal "Magic Mouse", declined_charges.first.name
  46. end
  47. def test_activate_application_charge
  48. fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
  49. fake "application_charges/803740/activate", :method => :post, :status => 200, :body => "{}"
  50. charge = ShopifyAPI::ApplicationCharge.accepted
  51. assert charge.last.activate
  52. end
  53. end