test/access/favorite_test.rb in access-2.0.48 vs test/access/favorite_test.rb in access-2.0.49

- old
+ new

@@ -1,27 +1,29 @@ require './test/test_helper' class FavoriteTest < Minitest::Test - def self.setup_favorites - VCR.use_cassette('favorite one of everything') do - @offer = Access::Offer.search(member_key: 'API_TEST', access_token: 'token_without_filters_with_program_offers', query: '_exists_:program_keys', all_offers: 'true').offers.first + def setup_favorites + VCR.use_cassette('favorite/one_of_everything') do + @offer = Access::Offer.search(member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'], query: '_exists_:program_keys', all_offers: 'true').offers.first # make sure there is a member that exists first - Access::Redeem.redeem_offer(@offer.offer_key, @offer.redemption_methods.first, member_key: "API_TEST", access_timeout: 10) + Access::Redeem.redeem_offer(@offer.offer_key, @offer.redemption_methods.first, member_key: "API_TEST", access_timeout: 10, access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'], first_name: 'q', last_name: 'a') # make sure there is an offer favorited first - Access::Favorite.create_offer @offer.offer_key, member_key: 'API_TEST' - Access::Favorite.create_location @offer.location.location_key, member_key: 'API_TEST' - Access::Favorite.create_store @offer.store.store_key, member_key: 'API_TEST' + Access::Favorite.create_offer @offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + Access::Favorite.create_location @offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + Access::Favorite.create_store @offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] end @offer end - @@offer = FavoriteTest.setup_favorites + def setup + @@offer ||= setup_favorites + end def test_favorite_search - VCR.use_cassette('favorite search') do - request = Access::Favorite.search member_key: 'API_TEST' + VCR.use_cassette('favorite/search') do + request = Access::Favorite.search member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert request.success assert_kind_of Access::FavoriteResponse, request assert_kind_of Array, request.favorites assert request.favorites.map(&:favorite_type).uniq.count > 1, 'it should have more than one favorite type (offers/stores/locations)' assert_kind_of Access::Favorite, request.favorites.first @@ -32,144 +34,149 @@ favorite = Access::Favorite.new favorite_type: 'location', favorited_date: Time.now, location: {location_key: 123} assert_equal favorite.resource, favorite.location end def test_favorite_search_with_bad_member - VCR.use_cassette('favorite search bad member') do - request = Access::Favorite.search member_key: 'API_TEST_FAVORITE_BAD_MEMBER' + VCR.use_cassette('favorite/search_bad_member') do + request = Access::Favorite.search member_key: 'API_TEST_FAVORITE_BAD_MEMBER', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] refute request.success assert_kind_of Access::FavoriteResponse, request assert_empty request.favorites end end def test_favorite_search_with_no_favorites # TODO refactor after fav api update - VCR.use_cassette('favorite search no favorites') do - request = Access::Favorite.search member_key: 'API_TEST_FAVORITE_NO_FAVORITES' + VCR.use_cassette('favorite/search_no_favorites') do + request = Access::Favorite.search member_key: 'API_TEST_FAVORITE_NO_FAVORITES', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] refute request.success assert_kind_of Access::FavoriteResponse, request assert_empty request.favorites end end def test_favorite_search_offers - VCR.use_cassette('favorite search offers') do - request = Access::Favorite.search_offers member_key: 'ALD12345' + VCR.use_cassette('favorite/search_offers') do + request = Access::Favorite.search_offers member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_offer_response(request) end end def test_favorite_search_locations - VCR.use_cassette('favorite search locations') do - request = Access::Favorite.search_locations member_key: 'ALD12345' + VCR.use_cassette('favorite/search_locations') do + request = Access::Favorite.search_locations member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_location_response(request) end end def test_favorite_search_stores - VCR.use_cassette('favorite search stores') do - request = Access::Favorite.search_stores member_key: 'ALD12345' + VCR.use_cassette('favorite/search_stores') do + request = Access::Favorite.search_stores member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_store_response(request) end end def test_favorite_find - VCR.use_cassette('favorite find generic with offer') do - Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST' + VCR.use_cassette('favorite/find_generic_with_offer') do + Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + request = Access::Favorite.find @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_offer_response(request) end end def test_favorite_find_offer - VCR.use_cassette('favorite find offer') do - Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find_offer @@offer.offer_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/find_offer') do + Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + request = Access::Favorite.find_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_offer_response(request) end end def test_favorite_find_location - VCR.use_cassette('favorite find location') do - Access::Favorite.create_location @@offer.location.location_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find_location @@offer.location.location_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/find_location') do + Access::Favorite.create_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + request = Access::Favorite.find_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_location_response(request) end end def test_favorite_find_store - VCR.use_cassette('favorite find store') do - Access::Favorite.create_store @@offer.store.store_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find_store @@offer.store.store_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/find_store') do + + Access::Favorite.create_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + request = Access::Favorite.find_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_store_response(request) end end def test_favorite_create - VCR.use_cassette('favorite create generic with offer') do - request = Access::Favorite.create @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST' + VCR.use_cassette('favorite/create_generic_with_offer') do + request = Access::Favorite.create @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_offer_response(request) end end def test_favorite_create_offer - VCR.use_cassette('favorite create offer') do - request = Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/create_offer') do + request = Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_offer_response(request) end end def test_favorite_create_location - VCR.use_cassette('favorite create location') do - request = Access::Favorite.create_location @@offer.location.location_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/create_location') do + request = Access::Favorite.create_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_location_response(request) end end def test_favorite_create_store - VCR.use_cassette('favorite create store') do - request = Access::Favorite.create_store @@offer.store.store_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/create_store') do + request = Access::Favorite.create_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert_good_favorite_store_response(request) end end def test_favorite_delete - VCR.use_cassette('favorite delete generic with offer') do - request = Access::Favorite.delete @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST' + VCR.use_cassette('favorite/delete_generic_with_offer') do + request = Access::Favorite.delete @@offer.offer_key, favorite_type: 'offers', member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert request.success assert_kind_of Access::FavoriteResponse, request + # remake it after + Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] end end def test_favorite_delete_offer - VCR.use_cassette('favorite delete offer') do - Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.delete_offer @@offer.offer_key, member_key: 'API_TEST' + VCR.use_cassette('favorite/delete_offer') do + Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] # create it first, in case it was deleted + request = Access::Favorite.delete_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] assert request.success assert_kind_of Access::FavoriteResponse, request + Access::Favorite.create_offer @@offer.offer_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] end end def test_favorite_delete_location - VCR.use_cassette('favorite delete location') do - Access::Favorite.delete_location @@offer.location.location_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find_location @@offer.location.location_key, member_key: 'API_TEST' - refute request.success + VCR.use_cassette('favorite/delete_location') do + Access::Favorite.delete_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] # create it first, in case it was deleted + request = Access::Favorite.find_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + assert request.success assert_kind_of Access::FavoriteResponse, request + Access::Favorite.create_location @@offer.location.location_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] end end def test_favorite_delete_store - VCR.use_cassette('favorite delete store') do - Access::Favorite.delete_store @@offer.store.store_key, member_key: 'API_TEST' # create it first, in case it was deleted - request = Access::Favorite.find_store @@offer.store.store_key, member_key: 'API_TEST' - refute request.success + VCR.use_cassette('favorite/delete_store') do + Access::Favorite.delete_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] # create it first, in case it was deleted + request = Access::Favorite.find_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] + assert request.success assert_kind_of Access::FavoriteResponse, request + Access::Favorite.create_store @@offer.store.store_key, member_key: 'API_TEST', access_token: ENV['TOKEN_WITHOUT_FILTERS_WITH_PROGRAM_OFFERS'] end end - def assert_good_favorite_offer_response(request) assert request.success assert_kind_of Access::FavoriteResponse, request assert_kind_of Array, request.favorites