collection_listing_test.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. require 'test_helper'
  2. class CollectionListingTest < Test::Unit::TestCase
  3. def test_get_collection_listings
  4. fake("collection_listings", method: :get, status: 201, body: load_fixture('collection_listings'))
  5. collection_listings = ShopifyAPI::CollectionListing.find(:all)
  6. assert_equal(1, collection_listings.count)
  7. assert_equal(1, collection_listings.first.collection_id)
  8. assert_equal('Home page', collection_listings.first.title)
  9. end
  10. def test_get_collection_listing
  11. fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
  12. collection_listing = ShopifyAPI::CollectionListing.find(1)
  13. assert_equal(1, collection_listing.collection_id)
  14. assert_equal('Home page', collection_listing.title)
  15. end
  16. def test_get_collection_listing_reload
  17. fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
  18. collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
  19. collection_listing.reload
  20. assert_equal(1, collection_listing.collection_id)
  21. assert_equal('Home page', collection_listing.title)
  22. end
  23. def test_get_collection_listing_product_ids
  24. fake(
  25. "collection_listings/1/product_ids",
  26. method: :get,
  27. status: 201,
  28. body: load_fixture('collection_listing_product_ids')
  29. )
  30. collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
  31. assert_equal([1, 2], collection_listing.product_ids)
  32. end
  33. def test_get_collection_listing_product_ids_multi_page_with_cursor
  34. version = ShopifyAPI::ApiVersion.find_version('2019-07')
  35. ShopifyAPI::Base.api_version = version.to_s
  36. collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
  37. url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-07/collection_listings/1/product_ids.json"
  38. next_page_info = "notarealpageinfobutthatsokay"
  39. next_page_url = "#{url}?page_info=#{next_page_info}"
  40. link_header = "<#{next_page_url}>; rel=\"next\""
  41. fake(
  42. "collection_listings/1/product_ids",
  43. method: :get,
  44. status: 201,
  45. url: url,
  46. body: load_fixture('collection_listing_product_ids'),
  47. link: link_header,
  48. )
  49. product_ids = collection_listing.product_ids
  50. assert_equal([1, 2], product_ids)
  51. assert(product_ids.next_page?)
  52. fake(
  53. "collection_listings/1/product_ids",
  54. method: :get,
  55. status: 201,
  56. url: next_page_url,
  57. body: load_fixture('collection_listing_product_ids2'),
  58. link: link_header,
  59. )
  60. next_page = product_ids.fetch_next_page
  61. assert_equal([3, 4], next_page)
  62. end
  63. end