Last active
October 27, 2020 16:38
-
-
Save aarkerio/9f407c857a8387e42716b1f7f11ce460 to your computer and use it in GitHub Desktop.
Shopify request test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'rails_helper' | |
RSpec.describe 'ShopsController', type: :request do | |
def login(shop) | |
OmniAuth.config.test_mode = true | |
OmniAuth.config.add_mock(:shopify, provider: 'shopify', uid: shop.myshopify_domain, | |
credentials: { token: shop.api_token }) | |
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:shopify] | |
get "/auth/shopify/callback?shop=#{shop.myshopify_domain}" | |
follow_redirect! | |
stubbed_session = ShopifyAPI::Session.new(shop.myshopify_domain, shop.api_token) | |
expect(ShopifyApp::SessionRepository).to receive(:retrieve).and_return(stubbed_session) | |
@request.session[:shopify] = shop.id | |
@request.session[:shop_id] = shop.id | |
@request.session[:shopify_id] = shop.shopify_id | |
end | |
let(:product) { FactoryBot.build_list :product, 5, :with_img } | |
let(:shop) { FactoryBot.build :shop } | |
let(:plan) { FactoryBot.build :plan } | |
let(:subscription) { FactoryBot.create :subscription, shop: shop, plan: plan } | |
let(:offer) { FactoryBot.create :simple_offer, shop: shop } | |
let(:daily_stats) { FactoryBot.create_list :daily_stat, 5, shop: shop, offer: offer } | |
describe 'GET#product_search' do | |
it 'returns a successful 200 response for listing action do' do | |
VCR.use_cassette('shop-webhook-setup-6040205', record: :new_episodes) do | |
new_subscrip = subscription | |
login(new_subscrip.shop) | |
get product_search_path, { params: { shop: { query: 'bik' } } } | |
expect(response).to be_successful | |
json = JSON.parse(response.body) | |
expect(json.length).to eq(5) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment