session_test.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'test_helper'
  2. class SessionTest < 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 "setup api_key and secret for all sessions" do
  22. ShopifyAPI::Session.setup(:api_key => "My test key", :secret => "My test secret")
  23. assert_equal "My test key", ShopifyAPI::Session.api_key
  24. assert_equal "My test secret", ShopifyAPI::Session.secret
  25. end
  26. should "use 'https' protocol by default for all sessions" do
  27. assert_equal 'https', ShopifyAPI::Session.protocol
  28. end
  29. should "#temp reset ShopifyAPI::Base.site to original value" do
  30. ShopifyAPI::Base.site = 'http://www.original.com'
  31. ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret")
  32. assigned_site = nil
  33. ShopifyAPI::Session.temp("testshop.myshopify.com", "any-token") {
  34. assigned_site = ShopifyAPI::Base.site
  35. }
  36. assert_equal 'https://:any-token@testshop.myshopify.com/admin', assigned_site.to_s
  37. assert_equal 'http://www.original.com', ShopifyAPI::Base.site.to_s
  38. end
  39. should "return site for session" do
  40. session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
  41. assert_equal "https://:any-token@testshop.myshopify.com/admin", session.site
  42. end
  43. end
  44. end