osem-fcy/spec/support/external_request.rb

51 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Mock external requests to youtube
require 'webmock/rspec'
driver_urls = Webdrivers::Common.subclasses.map do |driver|
Addressable::URI.parse(driver.base_url).host
end
WebMock.disable_net_connect!(allow_localhost: true, allow: [*driver_urls, /stripe.com/])
RSpec.configure do |config|
config.before(:each) do
mock_commercial_request
2021-02-23 22:11:37 -08:00
mock_image_request
end
end
def mock_commercial_request
response = {
2018-11-13 18:01:49 -08:00
author_name: 'Confreaks',
html: '<iframe width="560" height="315" frameborder="0" allowfullscreen></iframe>',
thumbnail_width: 480,
thumbnail_url: '/images/rails.png',
provider_name: 'YouTube',
width: 459,
type: 'video',
provider_url: 'http://www.youtube.com/',
version: '1.0',
thumbnail_height: 360,
2018-11-13 18:01:49 -08:00
title: 'RailsConf 2014 - Closing Keynote by Aaron Patterson',
author_url: 'https://www.youtube.com/user/Confreaks',
height: 344
}
2017-04-06 23:19:58 -04:00
WebMock.stub_request(:get, /.*youtube.*/)
.to_return(status: 200, body: response.to_json, headers: {})
end
2021-02-23 22:11:37 -08:00
def mock_image_request
WebMock.stub_request(:post, "https://api.cloudinary.com/v1_1/snapcon/image/destroy").
with(
body: {},
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip, deflate',
'Content-Length'=>'111',
'Content-Type'=>'application/x-www-form-urlencoded',
'Host'=>'api.cloudinary.com',
'User-Agent'=>'CloudinaryRuby/1.11.1'
}).
to_return(status: 200, body: {}.to_json, headers: {})
end