Skip to content

Commit

Permalink
Specify the desired token for evaluating risk assessments and improve…
Browse files Browse the repository at this point in the history
…ment tests
  • Loading branch information
lucaswilliamgomes committed Aug 24, 2024
1 parent 2be2231 commit 482fecf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
incognia_api (1.1.0)
incognia_api (1.2.0)
faraday (~> 1.10)
faraday_middleware (~> 1.2)

Expand Down
9 changes: 6 additions & 3 deletions lib/incognia_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def initialize(client_id:, client_secret:)
host: "https://api.incognia.com/api")
end

def register_signup(address: nil, **opts)
def register_signup(request_token: nil, address: nil, **opts)
params = {}
params.merge!({ request_token: request_token }) if request_token
params.merge!(opts)
params.merge!(address&.to_hash) if address

Expand All @@ -29,11 +30,12 @@ def register_signup(address: nil, **opts)
SignupAssessment.from_hash(response.body) if response.success?
end

def register_login(account_id:, **opts)
def register_login(account_id:, request_token: nil, **opts)
params = {
type: :login,
account_id: account_id
}
params.merge!({ request_token: request_token }) if request_token
params.merge!(opts)

response = connection.request(
Expand Down Expand Up @@ -66,8 +68,9 @@ def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil,
response.success?
end

def register_payment(account_id:, **opts)
def register_payment(account_id:, request_token: nil, **opts)
params = { account_id: account_id, type: :payment }
params.merge!({ request_token: request_token }) if request_token
params.merge!(opts)

response = connection.request(
Expand Down
118 changes: 71 additions & 47 deletions spec/incognia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,34 @@ module Incognia
end

context "HTTP request" do
it "hits the endpoint with request_token" do
stub_token_request
shared_examples_for 'receiving one of the required tokens' do |token_name|
let(:token_value) { SecureRandom.uuid }

stub = stub_signup_request
stub.with(
body: { request_token: request_token },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)
it "hits the endpoint with #{token_name}" do
stub_token_request

api.register_signup(request_token: request_token)
stub = stub_signup_request
stub.with(
body: { token_name => token_value },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

expect(stub).to have_been_made.once
api.register_signup(token_name => token_value)

expect(stub).to have_been_made.once
end
end

it_behaves_like 'receiving one of the required tokens', :request_token
it_behaves_like 'receiving one of the required tokens', :installation_id
it_behaves_like 'receiving one of the required tokens', :session_token

it "hits the endpoint with request_token and address_line" do
stub_token_request

stub = stub_signup_request
stub.with(
stub = stub_signup_request.with(
body: { request_token: request_token, address_line: line_format },
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
Expand Down Expand Up @@ -154,7 +161,6 @@ module Incognia
end
end
end

end

describe "#register_login" do
Expand All @@ -177,27 +183,36 @@ module Incognia
end

context "HTTP request" do
it "hits the endpoint with request_token and account_id" do
stub_token_request
shared_examples_for 'receiving one of the required tokens with account_id' do |token_name|
let(:token_value) { SecureRandom.uuid }

stub = stub_login_request.with(
body: {
type: 'login',
request_token: request_token, account_id: account_id
},
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)
it "hits the endpoint with #{token_name} and account_id" do
stub_token_request

api.register_login(
request_token: request_token,
account_id: account_id
)
stub = stub_login_request.with(
body: {
type: 'login',
account_id: account_id,
token_name => token_value
},
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

expect(stub).to have_been_made.once
api.register_login(
account_id: account_id,
token_name => token_value
)

expect(stub).to have_been_made.once
end
end

it_behaves_like 'receiving one of the required tokens with account_id', :request_token
it_behaves_like 'receiving one of the required tokens with account_id', :installation_id
it_behaves_like 'receiving one of the required tokens with account_id', :session_token

context 'when receiving any other optional arguments' do
shared_examples_for 'receiving optional args' do |optional_arguments|
it "hits the endpoint also with #{optional_arguments}" do
Expand Down Expand Up @@ -258,27 +273,36 @@ module Incognia
end

context "HTTP request" do
it "hits the endpoint with request_token and account_id" do
stub_token_request
shared_examples_for 'receiving one of the required tokens with account_id' do |token_name|
let(:token_value) { SecureRandom.uuid }

stub = stub_payment_request.with(
body: {
type: 'payment',
request_token: request_token, account_id: account_id
},
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)
it "hits the endpoint with #{token_name} and account_id" do
stub_token_request

api.register_payment(
request_token: request_token,
account_id: account_id
)
stub = stub_payment_request.with(
body: {
type: 'payment',
account_id: account_id,
token_name => token_value
},
headers: {
'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/
}
)

expect(stub).to have_been_made.once
api.register_payment(
account_id: account_id,
token_name => token_value
)

expect(stub).to have_been_made.once
end
end

it_behaves_like 'receiving one of the required tokens with account_id', :request_token
it_behaves_like 'receiving one of the required tokens with account_id', :installation_id
it_behaves_like 'receiving one of the required tokens with account_id', :session_token

context 'when receiving any other optional arguments' do
shared_examples_for 'receiving optional args' do |optional_arguments|
it "hits the endpoint also with #{optional_arguments}" do
Expand All @@ -305,7 +329,7 @@ module Incognia
end
end

it_behaves_like 'receiving optional args', 'external_id', 'payment request', 'aaa' do
it_behaves_like 'receiving optional args', 'external_id' do
let(:opts) { { external_id: 'external-id' } }
end
it_behaves_like 'receiving optional args', 'payment_value' do
Expand Down

0 comments on commit 482fecf

Please sign in to comment.