From 370196e9d7454e56b40cb36f1f8e665de2e31b08 Mon Sep 17 00:00:00 2001 From: Adeyemi Adunola <30475043+Kennyinspire@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:57:28 +0100 Subject: [PATCH] add strict match to ruby sdk (#69) * add strict match to ruby sdk * update changelog file * increase test coverage * make strict_match key optional --- CHANGELOG.md | 4 +++ examples/aml_check.rb | 1 + lib/smile-identity-core/aml_check.rb | 2 ++ spec/smile-identity-core/aml_check_spec.rb | 38 ++++++++++++++++++++-- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbef786..566a49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [2.2.4] - 2024-06-10 +### Added +- Enhanced `strict_match` functionality in AML + ### Changed - Linted the project with internal RuboCop rules diff --git a/examples/aml_check.rb b/examples/aml_check.rb index be68b00..732c1cb 100644 --- a/examples/aml_check.rb +++ b/examples/aml_check.rb @@ -19,6 +19,7 @@ countries: ['US'], birth_year: '1984', # yyyy search_existing_user: false, + strict_match: true, # optional - default is true } # Submit the job diff --git a/lib/smile-identity-core/aml_check.rb b/lib/smile-identity-core/aml_check.rb index 59c2065..23c95e0 100644 --- a/lib/smile-identity-core/aml_check.rb +++ b/lib/smile-identity-core/aml_check.rb @@ -33,6 +33,7 @@ def initialize(partner_id, api_key, sid_server) # @option opts [Array] :countries An array that takes the customer’s known nationalities in 2-character # (ISO 3166-1 alpha-2) format e.g. Nigeria is NG, Kenya is KE, etc # @option opts [boolean] :search_existing_user If you intend to re-use the name and year of birth + # @option opts [boolean] :strict_match If you want to perform a strict match on the serach criteria. # of a user’s previous KYC job # @option opts [Hash] :optional_info Any optional data, this will be returned # in partner_params. @@ -51,6 +52,7 @@ def symbolize_keys(params) def build_payload @payload = generate_signature @payload.merge!(@params) + @payload[:strict_match] = true unless @params.key?(:strict_match) add_partner_info add_sdk_info @payload diff --git a/spec/smile-identity-core/aml_check_spec.rb b/spec/smile-identity-core/aml_check_spec.rb index 8b3f0d1..e04c429 100644 --- a/spec/smile-identity-core/aml_check_spec.rb +++ b/spec/smile-identity-core/aml_check_spec.rb @@ -15,6 +15,7 @@ full_name: 'John Leo Doe', birth_year: '1984', search_existing_user: false, + strict_match: true, } end @@ -102,6 +103,7 @@ ResultCode: '1030', ResultText: 'Found on list', signature: '...', + StrictMatch: true, timestamp: '2023-02-17T16:24:16.835Z', }.to_json end @@ -160,7 +162,7 @@ expect(JSON.parse(setup_response).keys).to match_array(%w[ SmileJobID PartnerParams people ResultText ResultCode Actions - signature timestamp no_of_persons_found + signature StrictMatch timestamp no_of_persons_found ]) end @@ -176,7 +178,7 @@ expect(JSON.parse(setup_response).keys).to match_array(%w[ SmileJobID PartnerParams people ResultText ResultCode Actions - signature timestamp no_of_persons_found + signature StrictMatch timestamp no_of_persons_found ]) end end @@ -201,6 +203,7 @@ countries: payload[:countries], search_existing_user: payload[:search_existing_user], birth_year: payload[:birth_year], + strict_match: payload[:strict_match], source_sdk: SmileIdentityCore::SOURCE_SDK, source_sdk_version: SmileIdentityCore::VERSION, }) @@ -224,10 +227,41 @@ full_name: payload[:full_name], countries: payload[:countries], birth_year: payload[:birth_year], + strict_match: payload[:strict_match], source_sdk: SmileIdentityCore::SOURCE_SDK, source_sdk_version: SmileIdentityCore::VERSION, }) end + + it 'returns a hash formatted for the request when strict_match is false' do + payload[:strict_match] = false + connection.instance_variable_set(:@params, payload) + + signature = { signature: Base64.strict_encode64('signature'), timestamp: Time.now.to_s } + allow(connection).to receive(:generate_signature).and_return(signature) + parsed_response = connection.send(:build_payload) + expect(parsed_response[:strict_match]).to be false + end + + it 'returns a hash formatted for the request when strict_match is true' do + payload[:strict_match] = true + connection.instance_variable_set(:@params, payload) + + signature = { signature: Base64.strict_encode64('signature'), timestamp: Time.now.to_s } + allow(connection).to receive(:generate_signature).and_return(signature) + parsed_response = connection.send(:build_payload) + expect(parsed_response[:strict_match]).to be true + end + + it 'returns a hash formatted for the request when strict_match is not provided (default value)' do + payload.delete(:strict_match) + connection.instance_variable_set(:@params, payload) + + signature = { signature: Base64.strict_encode64('signature'), timestamp: Time.now.to_s } + allow(connection).to receive(:generate_signature).and_return(signature) + parsed_response = connection.send(:build_payload) + expect(parsed_response[:strict_match]).to be true + end end it 'successfully submits a job' do