Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Last active October 27, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarkerio/9f407c857a8387e42716b1f7f11ce460 to your computer and use it in GitHub Desktop.
Save aarkerio/9f407c857a8387e42716b1f7f11ce460 to your computer and use it in GitHub Desktop.
Shopify request test
# 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