Skip to content

Commit

Permalink
Added sanction check config name to sanction check output.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Feb 17, 2025
1 parent 08a758f commit 57c9691
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
24 changes: 16 additions & 8 deletions dto/sanction_check_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ var (
)

type SanctionCheckDto struct {
Id string `json:"id"`
Status string `json:"status"`
Request SanctionCheckRequestDto `json:"request"`
Partial bool `json:"partial"`
Count int `json:"count"`
IsManual bool `json:"is_manual"`
RequestedBy *string `json:"requested_by,omitempty"`
Matches []SanctionCheckMatchDto `json:"matches"`
Id string `json:"id"`
Config SanctionCheckConfigRefDto `json:"config"`
Status string `json:"status"`
Request SanctionCheckRequestDto `json:"request"`
Partial bool `json:"partial"`
Count int `json:"count"`
IsManual bool `json:"is_manual"`
RequestedBy *string `json:"requested_by,omitempty"`
Matches []SanctionCheckMatchDto `json:"matches"`
}

type SanctionCheckConfigRefDto struct {
Name string `json:"name"`
}

type SanctionCheckRequestDto struct {
Expand All @@ -36,6 +41,9 @@ type SanctionCheckRequestDto struct {
func AdaptSanctionCheckDto(m models.SanctionCheckWithMatches) SanctionCheckDto {
sanctionCheck := SanctionCheckDto{
Id: m.Id,
Config: SanctionCheckConfigRefDto{
Name: m.Config.Name,
},
Request: SanctionCheckRequestDto{
Datasets: m.Datasets,
Limit: m.OrgConfig.MatchLimit,
Expand Down
4 changes: 4 additions & 0 deletions models/sanction_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type SanctionCheck struct {
Id string
DecisionId string
Status SanctionCheckStatus
Config SanctionCheckConfigRef
Datasets []string
SearchInput json.RawMessage
OrgConfig OrganizationOpenSanctionsConfig
Expand All @@ -106,6 +107,9 @@ type SanctionCheck struct {
UpdatedAt time.Time
}

type SanctionCheckConfigRef struct {
Name string
}
type SanctionCheckWithMatches struct {
SanctionCheck
Matches []SanctionCheckMatch
Expand Down
10 changes: 10 additions & 0 deletions usecases/sanction_check_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,20 @@ func (uc SanctionCheckUsecase) ListSanctionChecks(ctx context.Context, decisionI
return nil, err
}

scc, err := uc.sanctionCheckConfigRepository.GetSanctionCheckConfig(ctx,
uc.executorFactory.NewExecutor(), decisions[0].ScenarioIterationId)
if err != nil {
return nil, err
}

matchIds := set.New[string](0)
matchIdToMatch := make(map[string]*models.SanctionCheckMatch)

for sidx, sc := range scs {
scs[sidx].Config = models.SanctionCheckConfigRef{
Name: scc.Name,
}

for midx, match := range sc.Matches {
matchIds.Insert(match.Id)
matchIdToMatch[match.Id] = &scs[sidx].Matches[midx]
Expand Down
42 changes: 34 additions & 8 deletions usecases/sanction_check_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,38 @@ func buildSanctionCheckUsecaseMock() (SanctionCheckUsecase, executor_factory.Exe
txFac := executor_factory.NewTransactionFactoryStub(exec)

uc := SanctionCheckUsecase{
enforceSecurityDecision: enforceSecurity,
enforceSecurityCase: enforceSecurity,
organizationRepository: mock,
externalRepository: mock,
inboxReader: mock,
repository: &repositories.MarbleDbRepository{},
executorFactory: exec,
transactionFactory: txFac,
enforceSecurityDecision: enforceSecurity,
enforceSecurityCase: enforceSecurity,
organizationRepository: mock,
externalRepository: mock,
inboxReader: mock,
repository: &repositories.MarbleDbRepository{},
sanctionCheckConfigRepository: &repositories.MarbleDbRepository{},
executorFactory: exec,
transactionFactory: txFac,
}

return uc, exec
}

func TestListSanctionChecksOnDecision(t *testing.T) {
uc, exec := buildSanctionCheckUsecaseMock()

sccRow, mockSccRow := utils.FakeStruct[dbmodels.DBSanctionCheckConfigs](
ops.WithCustomFieldProvider("TriggerRule", func() (interface{}, error) {
return []byte(`{}`), nil
}),
ops.WithCustomFieldProvider("Query", func() (interface{}, error) {
return &dbmodels.DBSanctionCheckConfigQuery{
Name: []byte(`{}`),
Label: []byte(`{}`),
}, nil
}),
ops.WithCustomFieldProvider("CounterpartyIdExpr", func() (interface{}, error) {
return []byte(`{}`), nil
}),
)

mockSc, mockScRow := utils.FakeStruct[dbmodels.DBSanctionCheckWithMatches](
ops.WithRandomMapAndSliceMinSize(1), ops.WithRandomMapAndSliceMaxSize(1))

Expand All @@ -62,6 +79,14 @@ func TestListSanctionChecksOnDecision(t *testing.T) {
AddRow(mockScRow...),
)

exec.Mock.
ExpectQuery(`SELECT id, .+ FROM sanction_check_configs WHERE scenario_iteration_id = \$1`).
WithArgs("").
WillReturnRows(
pgxmock.NewRows(dbmodels.SanctionCheckConfigColumnList).
AddRow(mockSccRow...),
)

exec.Mock.ExpectQuery(`SELECT .* FROM sanction_check_match_comments WHERE sanction_check_match_id = ANY\(\$1\)`).
WithArgs(pgxmock.AnyArg()).
WillReturnRows(
Expand All @@ -79,6 +104,7 @@ func TestListSanctionChecksOnDecision(t *testing.T) {
assert.Equal(t, models.SanctionCheckMatchStatusFrom(scs[0].Matches[0].Status.String()), models.SanctionMatchStatusUnknown)
assert.Len(t, scs[0].Matches[0].Comments, 4)
assert.Equal(t, scs[0].Matches[0].Comments[0].Comment, mockComments[0].Comment)
assert.Equal(t, scs[0].Config.Name, sccRow.Name)
}

func TestUpdateMatchStatus(t *testing.T) {
Expand Down

0 comments on commit 57c9691

Please sign in to comment.