article_test.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. class ArticleTest < Test::Unit::TestCase
  4. def test_create_article
  5. fake("blogs/1008414260/articles", method: :post, body: load_fixture('article'))
  6. article = ShopifyAPI::Article.new(blog_id: 1008414260)
  7. article.save
  8. assert_equal("First Post", article.title)
  9. end
  10. def test_get_article
  11. fake("articles/6242736", method: :get, body: load_fixture('article'))
  12. article = ShopifyAPI::Article.find(6242736)
  13. assert_equal("First Post", article.title)
  14. assert_equal(1008414260, article.blog_id)
  15. end
  16. def test_get_articles
  17. fake("articles", method: :get, body: load_fixture('articles'))
  18. articles = ShopifyAPI::Article.all
  19. assert_equal(3, articles.length)
  20. assert_equal(1008414260, articles.first.blog_id)
  21. end
  22. def test_get_articles_namespaced
  23. fake("blogs/1008414260/articles", method: :get, body: load_fixture('articles'))
  24. articles = ShopifyAPI::Article.find(:all, params: { blog_id: 1008414260 })
  25. assert_equal(3, articles.length)
  26. assert_equal(1008414260, articles.first.blog_id)
  27. end
  28. def test_get_article_namespaced
  29. fake("blogs/1008414260/articles/6242736", method: :get, body: load_fixture('article'))
  30. article = ShopifyAPI::Article.find(6242736, params: { blog_id: 1008414260 })
  31. assert_equal("First Post", article.title)
  32. assert_equal(1008414260, article.blog_id)
  33. end
  34. def test_get_authors
  35. fake("articles/authors", method: :get, body: load_fixture('authors'))
  36. authors = ShopifyAPI::Article.authors
  37. assert_equal("Shopify", authors.first)
  38. assert_equal("development shop", authors.last)
  39. end
  40. def test_get_authors_for_blog_id
  41. fake("blogs/1008414260/articles/authors", method: :get, body: load_fixture('authors'))
  42. authors = ShopifyAPI::Article.authors(blog_id: 1008414260)
  43. assert_equal(3, authors.length)
  44. end
  45. def test_get_tags
  46. fake("articles/tags", method: :get, body: load_fixture('tags'))
  47. tags = ShopifyAPI::Article.tags
  48. assert_equal("consequuntur", tags.first)
  49. assert_equal("repellendus", tags.last)
  50. end
  51. def test_get_tags_for_blog_id
  52. fake("blogs/1008414260/articles/tags", method: :get, body: load_fixture('tags'))
  53. tags = ShopifyAPI::Article.tags(blog_id: 1008414260)
  54. assert_equal("consequuntur", tags.first)
  55. assert_equal("repellendus", tags.last)
  56. end
  57. def test_get_popular_tags
  58. fake("articles/tags.json?limit=1&popular=1", extension: false, method: :get, body: load_fixture('tags'))
  59. tags = ShopifyAPI::Article.tags(popular: 1, limit: 1)
  60. assert_equal(3, tags.length)
  61. end
  62. end