application_charge_test.rb 2.7 KB

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