Skip to content

Commit

Permalink
add strict match to ruby sdk (#69)
Browse files Browse the repository at this point in the history
* add strict match to ruby sdk

* update changelog file

* increase test coverage

* make strict_match key optional
  • Loading branch information
Kennyinspire committed Jun 12, 2024
1 parent 56e9036 commit 370196e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/aml_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
countries: ['US'],
birth_year: '1984', # yyyy
search_existing_user: false,
strict_match: true, # optional - default is true
}

# Submit the job
Expand Down
2 changes: 2 additions & 0 deletions lib/smile-identity-core/aml_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
38 changes: 36 additions & 2 deletions spec/smile-identity-core/aml_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
full_name: 'John Leo Doe',
birth_year: '1984',
search_existing_user: false,
strict_match: true,
}
end

Expand Down Expand Up @@ -102,6 +103,7 @@
ResultCode: '1030',
ResultText: 'Found on list',
signature: '...',
StrictMatch: true,
timestamp: '2023-02-17T16:24:16.835Z',
}.to_json
end
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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,
})
Expand All @@ -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
Expand Down

0 comments on commit 370196e

Please sign in to comment.