fulfillment_test.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'test_helper'
  2. class FulFillmentTest < Test::Unit::TestCase
  3. def setup
  4. super
  5. fake "orders/450789469/fulfillments/255858046", :method => :get, :body => load_fixture('fulfillment')
  6. end
  7. context "Fulfillment" do
  8. context "#complete" do
  9. should "be able to complete fulfillment" do
  10. fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
  11. success = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
  12. success['fulfillment']['status'] = 'success'
  13. fake "orders/450789469/fulfillments/255858046/complete", :method => :post, :body => ActiveSupport::JSON.encode(success)
  14. assert_equal 'pending', fulfillment.status
  15. assert fulfillment.complete
  16. assert_equal 'success', fulfillment.status
  17. end
  18. end
  19. context "#cancel" do
  20. should "be able to cancel fulfillment" do
  21. fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
  22. cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
  23. cancelled['fulfillment']['status'] = 'cancelled'
  24. fake "orders/450789469/fulfillments/255858046/cancel", :method => :post, :body => ActiveSupport::JSON.encode(cancelled)
  25. assert_equal 'pending', fulfillment.status
  26. assert fulfillment.cancel
  27. assert_equal 'cancelled', fulfillment.status
  28. end
  29. end
  30. context "#open" do
  31. should "be able to open a fulfillment" do
  32. fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
  33. open_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
  34. open_fulfillment['fulfillment']['status'] = 'open'
  35. fake "orders/450789469/fulfillments/255858046/open", :method => :post, :body => ActiveSupport::JSON.encode(open_fulfillment)
  36. assert_equal 'pending', fulfillment.status
  37. assert fulfillment.open
  38. assert_equal 'open', fulfillment.status
  39. end
  40. end
  41. context "#find" do
  42. should "be able to find fulfillment" do
  43. fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
  44. assert_equal 255858046, fulfillment.id
  45. assert_equal 450789469, fulfillment.order_id
  46. end
  47. end
  48. end
  49. end