Skip to content

Commit

Permalink
Added "no_hit" option for sanction check status.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Popineau committed Jan 27, 2025
1 parent d1fc381 commit b121202
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions models/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (c Case) GetMetadata() CaseMetadata {
}
}

func (c CaseStatus) IsFinalized() bool {
return c == CaseDiscarded || c == CaseResolved
}

type CaseMetadata struct {
Id string
CreatedAt time.Time
Expand Down
9 changes: 9 additions & 0 deletions models/sanction_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type SanctionCheckStatus int

const (
SanctionStatusConfirmedHit SanctionCheckStatus = iota
SanctionStatusNoHit
SanctionStatusInReview
SanctionStatusError
SanctionStatusUnknown
Expand All @@ -18,6 +19,8 @@ func SanctionCheckStatusFrom(s string) SanctionCheckStatus {
switch s {
case "confirmed_hit":
return SanctionStatusConfirmedHit
case "no_hit":
return SanctionStatusNoHit
case "in_review":
return SanctionStatusInReview
case "error":
Expand All @@ -31,6 +34,8 @@ func (scs SanctionCheckStatus) String() string {
switch scs {
case SanctionStatusConfirmedHit:
return "confirmed_hit"
case SanctionStatusNoHit:
return "no_hit"
case SanctionStatusInReview:
return "in_review"
case SanctionStatusError:
Expand All @@ -40,6 +45,10 @@ func (scs SanctionCheckStatus) String() string {
return "unknown"
}

func (scs SanctionCheckStatus) IsFinalized() bool {
return scs == SanctionStatusConfirmedHit || scs == SanctionStatusNoHit
}

type SanctionCheck struct {
Id string
DecisionId string
Expand Down
2 changes: 1 addition & 1 deletion repositories/migrations/20250120101100_sanction_check.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ create table sanction_checks (
id uuid default uuid_generate_v4(),
decision_id uuid not null,

status text check (status in ('confirmed_hit', 'in_review', 'error')) default 'in_review',
status text check (status in ('confirmed_hit', 'no_hit', 'in_review', 'error')) default 'in_review',
search_input jsonb,
search_datasets text[],
search_threshold integer,
Expand Down
4 changes: 1 addition & 3 deletions usecases/sanction_check_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ func (uc SanctionCheckUsecase) enforceCanRefineSanctionCheck(ctx context.Context
return models.Decision{}, models.SanctionCheck{}, errors.Wrap(models.NotFoundError,
"this sanction check is not linked to a case")
}
if (decision[0].Case.Status != models.CaseOpen && decision[0].Case.Status !=
models.CaseInvestigating) || (sanctionCheck.Status != models.SanctionStatusInReview &&
sanctionCheck.Status != models.SanctionStatusError) {
if decision[0].Case.Status.IsFinalized() || sanctionCheck.Status.IsFinalized() {
return models.Decision{}, models.SanctionCheck{},
errors.Wrap(models.NotFoundError, "this sanction is not pending review")
}
Expand Down
3 changes: 2 additions & 1 deletion usecases/sanction_check_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/checkmarble/marble-backend/models"
"github.com/checkmarble/marble-backend/repositories"
"github.com/checkmarble/marble-backend/repositories/dbmodels"
"github.com/checkmarble/marble-backend/usecases/executor_factory"
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestGetSanctionCheckOnDecision(t *testing.T) {

assert.NoError(t, exec.Mock.ExpectationsWereMet())
assert.NoError(t, err)
assert.Equal(t, mockSc.Status, sc.Status)
assert.Equal(t, models.SanctionCheckStatusFrom(mockSc.Status), sc.Status)
assert.Len(t, sc.Matches, 3)
assert.Equal(t, mockScMatch.Status, sc.Matches[0].Status)
assert.Equal(t, mockScMatch.CommentCount, sc.Matches[0].CommentCount)
Expand Down

0 comments on commit b121202

Please sign in to comment.