Skip to content

Commit

Permalink
feat: add is_match_valid and has_alerts filters to get_matches method
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPB committed Jan 23, 2025
1 parent 8b090f2 commit 48da7de
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/factiva/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,14 @@ def get_profile(profile_id:)
.value_or { |error| raise RequestError.new(error) }
end

def get_matches(case_id:, offset: 0, limit: 100)
url = matches_url(case_id, offset: offset, limit: limit)
def get_matches(case_id:, offset: 0, limit: 100, has_alerts: "any", is_match_valid: "any")
url = matches_url(
case_id,
offset: offset,
limit: limit,
has_alerts: has_alerts,
is_match_valid: is_match_valid
)

# If the request fails auth is reset and the request retried
get(url)
Expand Down Expand Up @@ -429,8 +435,12 @@ def profile_url(profile_id)
make_url("riskentities/profiles/#{profile_id}")
end

def matches_url(case_id, offset:, limit:)
make_url("risk-entity-screening-cases/#{case_id}/matches?page[offset]=#{offset}&page[limit]=#{limit}")
def matches_url(case_id, offset:, limit:, has_alerts:, is_match_valid:)
make_url(
"risk-entity-screening-cases/#{case_id}/matches?" \
"page[offset]=#{offset}&page[limit]=#{limit}&" \
"filter[has_alerts]=#{has_alerts}&filter[is_match_valid]=#{is_match_valid}"
)
end

def log_decision_url(case_id, match_id)
Expand Down
16 changes: 16 additions & 0 deletions spec/factiva/monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ module Factiva
expect(result["data"][1]["attributes"]["matches"][0]["is_match_valid"]).to be_truthy
expect(result["data"][1]["attributes"]["matches"][0]).to eq(valid_match)
end

context "when filtering by valid matches", vcr: "monitoring/matches_has_alerts" do
# at the moment of recording this VCR, there are 2 matches with alerts
let(:match_attributes) { result["data"].first["attributes"]["matches"] }
let(:result) { subject.get_matches(**sample_data, has_alerts: true) }

it "authenticates and returns matches with alerts" do
result

expect(result["data"].size).to eq(2)
expect(match_attributes.first["has_alerts"]).to be_truthy
expect(match_attributes.first["is_match_valid"]).to be_truthy
expect(match_attributes.last["has_alerts"]).to be_truthy
expect(match_attributes.last["is_match_valid"]).to be_truthy
end
end
end

context "Factiva connection timed out", vcr: "monitoring/authentication_only" do
Expand Down
2 changes: 1 addition & 1 deletion spec/vcr/monitoring/matches.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 48da7de

Please sign in to comment.