Class: InstantQuote::Adapters::Fake
- Inherits:
-
InstantQuote::Adapter
- Object
- InstantQuote::Adapter
- InstantQuote::Adapters::Fake
- Defined in:
- lib/instant_quote/adapters/fake.rb
Constant Summary
Constants inherited from InstantQuote::Adapter
InstantQuote::Adapter::DEFAULT_ADDITIONAL_FIELDS
Instance Method Summary collapse
-
#get_approval(_state_key, _connection) ⇒ Object
TODO: what should we do here?.
-
#get_link(connection) ⇒ Object
The link is always the same.
- #get_preapproval(params, _connection) ⇒ Object
- #get_quote(params, _connection) ⇒ Object
-
#get_status(_application_id, connection) ⇒ Object
Get the status for a given application ID rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Methods inherited from InstantQuote::Adapter
accept_offer, #accept_offer, additional_fields, get_approval, get_link, get_preapproval, get_quote, get_status
Instance Method Details
#get_approval(_state_key, _connection) ⇒ Object
TODO: what should we do here?
74 75 76 |
# File 'lib/instant_quote/adapters/fake.rb', line 74 def get_approval(_state_key, _connection) true end |
#get_link(connection) ⇒ Object
The link is always the same
148 149 150 151 152 |
# File 'lib/instant_quote/adapters/fake.rb', line 148 def get_link(connection) id = connection.external_id "https://fake.com/link/#{id}" end |
#get_preapproval(params, _connection) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/instant_quote/adapters/fake.rb', line 78 def get_preapproval(params, _connection) response = OpenStruct.new(success?: true, error_description: '') return response if params[:with_preapproval] == 'no' if params[:with_preapproval] == 'yes_decline' response[:success?] = false response.error_description = 'preapproval is declined' end response end |
#get_quote(params, _connection) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/instant_quote/adapters/fake.rb', line 91 def get_quote(params, _connection) if params[:desired_status] == 'error_on_get_quote' response = OpenStruct.new( body: { errorMessage: 'Error on get_quote that raises an exception' }, error: '501 error_on_get_quote' ) raise_error(response) end # Returns a random identifier SecureRandom.hex(3) end |
#get_status(_application_id, connection) ⇒ Object
Get the status for a given application ID rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/instant_quote/adapters/fake.rb', line 107 def get_status(_application_id, connection) status = connection.extra_info['desired_status'] if status == 'error_on_get_status' response = OpenStruct.new( body: { errorMessage: 'Error on get_status that raises an exception' }, error: '502 error_on_get_status' ) raise_error(response) unless response.success? end response = OpenStruct.new( body: { latest_approval_request: { status: status, approved: { interval: rand(10..30), duration: rand(10..30), max_credit: rand(1000..8000), monthly_interest_rate: rand(0..1.0).round(2) } }, credit_decision: { status: status, sweep: 10, loan_amount: rand(1000..8000), funded_amount: rand(1000..8000), fee: rand(100..800), monthly_interest_rate: rand(0..1.0).round(2), monthly_card_interest_rate: rand(0..1.0).round(2), amount: rand(1000..8000) } } ) DecisionParsers::Fake.new(response.body) end |