shopify_api_test.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'test_helper'
  2. class ShopifyApiTest < Test::Unit::TestCase
  3. context "Session" do
  4. should "not be valid without a url" do
  5. session = ShopifyAPI::Session.new(nil, "any-token")
  6. assert_not session.valid?
  7. end
  8. should "not be valid without token" do
  9. session = ShopifyAPI::Session.new("testshop.myshopify.com")
  10. assert_not session.valid?
  11. end
  12. should "be valid with any token and any url" do
  13. session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
  14. assert session.valid?
  15. end
  16. should "not raise error without params" do
  17. assert_nothing_raised do
  18. session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
  19. end
  20. end
  21. should "raise error if params passed but signature omitted" do
  22. assert_raises(RuntimeError) do
  23. session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token", {'foo' => 'bar'})
  24. end
  25. end
  26. should "setup api_key and secret for all sessions" do
  27. ShopifyAPI::Session.setup(:api_key => "My test key", :secret => "My test secret")
  28. assert_equal "My test key", ShopifyAPI::Session.api_key
  29. assert_equal "My test secret", ShopifyAPI::Session.secret
  30. end
  31. should "use 'https' protocol by default for all sessions" do
  32. assert_equal 'https', ShopifyAPI::Session.protocol
  33. end
  34. should "#temp reset ShopifyAPI::Base.site to original value" do
  35. ShopifyAPI::Base.site = 'http://www.original.com'
  36. ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret")
  37. assigned_site = nil
  38. ShopifyAPI::Session.temp("testshop.myshopify.com", "any-token") {
  39. assigned_site = ShopifyAPI::Base.site
  40. }
  41. assert_equal 'https://key:e56d5793b869753d87cf03ceb6bb5dfc@testshop.myshopify.com/admin', assigned_site.to_s
  42. assert_equal 'http://www.original.com', ShopifyAPI::Base.site.to_s
  43. end
  44. end
  45. end