Skip to content

Commit

Permalink
tests refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
olegphenomenon committed Oct 13, 2021
1 parent d0d1869 commit 8c5a1a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions app/services/create_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
require 'json'

class CreateDomain < ApiConnector
SSL_OPTIONS = {
client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])),
client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD'])
}.freeze
if Rails.env.test?
SSL_OPTIONS = nil.freeze
else
SSL_OPTIONS = {
client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])),
client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD'])
}.freeze
end

def initialize(username:, password:)
super
Expand Down
2 changes: 1 addition & 1 deletion spec/services/api_connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
allow(body).to receive(:body).and_return(response)

api_connector = ApiConnector.new(username: "mock", password: "username")
allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}).and_return(Faraday)
allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}, ssl: nil).and_return(Faraday)

allow(Faraday).to receive(:send).with(:get).and_return(body)

Expand Down
3 changes: 2 additions & 1 deletion spec/services/create_domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
allow(@api_connector).to receive(:request).with(url: @api_connector.domain_endpoint,
headers: @api_connector.headers,
method: :post,
params: payload).and_return(@response_successful)
params: payload,
ssl: nil).and_return(@response_successful)

response = @api_connector.create_domain
expect(response["code"]).to eq("1000")
Expand Down

0 comments on commit 8c5a1a4

Please sign in to comment.