checkouts_test.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. class CheckoutsTest < Test::Unit::TestCase
  4. def setup
  5. super
  6. @expected_checkouts = JSON.parse(load_fixture('checkouts'))['checkouts']
  7. @expected_checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
  8. end
  9. test ":create creates a checkout" do
  10. fake 'checkouts', method: :post, status: 201, body: load_fixture('checkout')
  11. checkout = ShopifyAPI::Checkout.create
  12. assert_equal @expected_checkout_id, checkout.id
  13. end
  14. test "get all checkouts indexed by token" do
  15. fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
  16. checkouts = ShopifyAPI::Checkout.all
  17. assert_equal @expected_checkout_id, checkouts.first.id
  18. assert_equal @expected_checkouts.size, checkouts.size
  19. end
  20. test ":complete completes a checkout" do
  21. fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
  22. checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
  23. fake "checkouts/#{@expected_checkout_id}/complete", method: :post, status: 200, body: load_fixture('checkouts')
  24. checkout.complete
  25. end
  26. test ":ready? returns true when status is 201" do
  27. fake "checkouts/#{@expected_checkout_id}", method: :get, status: 201, body: load_fixture('checkout')
  28. checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
  29. assert_predicate checkout, :ready?
  30. end
  31. test ":ready? returns false when status is 202" do
  32. fake "checkouts/#{@expected_checkout_id}", method: :get, status: 202, body: load_fixture('checkout')
  33. checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
  34. refute_predicate checkout, :ready?
  35. end
  36. test ":payments returns payments for a checkout" do
  37. fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
  38. checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
  39. fake "checkouts/#{@expected_checkout_id}/payments", method: :get, status: 202, body: load_fixture('payments')
  40. assert_equal 10.00, checkout.payments.first.amount
  41. end
  42. test ":shipping_rates returns shipping rates for a checkout" do
  43. fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
  44. checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
  45. fake("checkouts/#{@expected_checkout_id}/shipping_rates",
  46. method: :get,
  47. status: 202,
  48. body: load_fixture('shipping_rates'))
  49. assert_equal "canada_post-INT.TP.BOGUS-4.00", checkout.shipping_rates.first.id
  50. end
  51. end