Skip to content

Commit

Permalink
Merge pull request #49 from companieshouse/feature/SAN-230-penalty-re…
Browse files Browse the repository at this point in the history
…ason

SAN-230 Add reason to Penalties / Payment endpoints for Penalty summary and Penalty paid screens
  • Loading branch information
rbull-ch authored Feb 14, 2025
2 parents 56a3e44 + 1f2d2f4 commit 2fd8ffd
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 111 deletions.
8 changes: 4 additions & 4 deletions assets/penalty_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ details:
ResourceKind: "late-filing-penalty#late-filing-penalty"
ProductType: "late-filing-penalty"
EmailReceivedAppId: "penalty-payment-api.penalty_payment_received_email"
EmailFilingDesc: "Late filing of accounts"
EmailMsgType: "penalty_payment_received_email"
EmailFilingDesc: "Late filing of accounts"
EmailMsgType: "penalty_payment_received_email"
C1:
Description: "Sanctions Penalty Payment"
DescriptionId: "penalty-sanctions"
ResourceKind: "penalty#sanctions"
ProductType: "penalty-sanctions"
EmailReceivedAppId: "penalty-payment-api.penalty_payment_received_email"
EmailFilingDesc: "Sanctions Penalty Payment"
EmailMsgType: "penalty_payment_received_email"
EmailFilingDesc: "Failure to file a confirmation statement"
EmailMsgType: "penalty_payment_received_email"
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ require (
github.com/companieshouse/go-sdk-manager v0.1.12
github.com/companieshouse/go-session-handler v0.1.5
github.com/companieshouse/gofigure v0.1.4
github.com/companieshouse/penalty-payment-api-core v1.0.8
github.com/companieshouse/penalty-payment-api-core v1.1.2
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.0
github.com/jarcoal/httpmock v1.0.4
github.com/pkg/errors v0.9.1
github.com/smartystreets/goconvey v1.7.2
go.mongodb.org/mongo-driver v1.10.2
gopkg.in/go-playground/validator.v9 v9.31.0
Expand Down Expand Up @@ -45,7 +46,6 @@ require (
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
Expand Down
60 changes: 2 additions & 58 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func buildTransactionListItemFromE5Transaction(e5Transaction *e5.Transaction, al
transactionListItem.OriginalAmount = e5Transaction.Amount
transactionListItem.Outstanding = e5Transaction.OutstandingAmount
transactionListItem.Type = getTransactionType(e5Transaction, allowedTransactionsMap)
transactionListItem.Reason = getReason(e5Transaction)

return transactionListItem, nil
}
Expand All @@ -74,3 +75,12 @@ func getTransactionType(e5Transaction *e5.Transaction, allowedTransactionsMap *m
return types.Other.String()
}
}

func getReason(transaction *e5.Transaction) string {
if transaction.CompanyCode == utils.LateFilingPenalty {
return "Late filing of accounts"
} else if transaction.CompanyCode == utils.Sanctions && (transaction.TransactionSubType == "S1" && transaction.TypeDescription == "CS01") {
return "Failure to file a confirmation statement"
}
return "Penalty"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package private

import (
"errors"
"testing"

"github.com/companieshouse/penalty-payment-api-core/models"
"github.com/companieshouse/penalty-payment-api/config"
"github.com/companieshouse/penalty-payment-api/e5"
"testing"

. "github.com/smartystreets/goconvey/convey"
)
Expand Down Expand Up @@ -85,3 +86,52 @@ func TestUnitGenerateTransactionListFromE5Response(t *testing.T) {
So(transactionList, ShouldNotBeNil)
})
}

func TestUnit_getReason(t *testing.T) {
Convey("Get reason", t, func() {
type args struct {
transaction *e5.Transaction
}
testCases := []struct {
name string
args args
want string
}{
{
name: "Late filing of accounts",
args: args{transaction: &e5.Transaction{
CompanyCode: "LP",
TransactionType: "1",
TransactionSubType: "Other",
}},
want: "Late filing of accounts",
},
{
name: "Failure to file a confirmation statement",
args: args{transaction: &e5.Transaction{
CompanyCode: "C1",
TransactionType: "1",
TransactionSubType: "S1",
TypeDescription: "CS01",
}},
want: "Failure to file a confirmation statement",
},
{
name: "Penalty",
args: args{transaction: &e5.Transaction{
CompanyCode: "C1",
TransactionType: "1",
TransactionSubType: "S1",
}},
want: "Penalty",
},
}
for _, tc := range testCases {
Convey(tc.name, func() {
got := getReason(tc.args.transaction)

So(got, ShouldEqual, tc.want)
})
}
})
}
1 change: 1 addition & 0 deletions issuer_gateway/private/match_penalty.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func MatchPenalty(referenceTransactions []models.TransactionListItem,
MadeUpDate: transaction.MadeUpDate,
IsDCA: transaction.IsDCA,
IsPaid: transaction.IsPaid,
Reason: transaction.Reason,
}
matchedPenalties = append(matchedPenalties, matchedPenalty)
} else {
Expand Down
32 changes: 18 additions & 14 deletions issuer_gateway/private/match_penalty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestUnitMatchPenalty(t *testing.T) {
TransactionID: "121",
Type: "penalty",
Amount: 150,
Reason: "Failure to file a confirmation statement",
},
}
matchedPenalties := []models.TransactionItem{
Expand All @@ -23,6 +24,7 @@ func TestUnitMatchPenalty(t *testing.T) {
Amount: 150,
Type: "penalty",
MadeUpDate: "2017-06-30",
Reason: "Failure to file a confirmation statement",
IsDCA: false,
IsPaid: false,
},
Expand All @@ -32,27 +34,28 @@ func TestUnitMatchPenalty(t *testing.T) {
TransactionID string
Type string
MadeUpDate string
Reason string
IsDCA bool
IsPaid bool
OriginalAmount float64
Outstanding float64
WantMatched []models.TransactionItem
WantError error
}{
{TransactionID: "120", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 150,
IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionDoesNotExist},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 200,
IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionIsPartPaid},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 150,
IsDCA: false, IsPaid: true, WantMatched: nil, WantError: ErrTransactionIsPaid},
{TransactionID: "121", Outstanding: 100, Type: "other", MadeUpDate: "2017-06-30", OriginalAmount: 100,
IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionNotPayable},
{TransactionID: "121", Outstanding: 100, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 100,
IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionAmountMismatch},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 150,
IsDCA: true, IsPaid: false, WantMatched: nil, WantError: ErrTransactionDCA},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", OriginalAmount: 150,
IsDCA: false, IsPaid: false, WantMatched: matchedPenalties, WantError: nil},
{TransactionID: "120", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 150, IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionDoesNotExist},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 200, IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionIsPartPaid},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 150, IsDCA: false, IsPaid: true, WantMatched: nil, WantError: ErrTransactionIsPaid},
{TransactionID: "121", Outstanding: 100, Type: "other", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 100, IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionNotPayable},
{TransactionID: "121", Outstanding: 100, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 100, IsDCA: false, IsPaid: false, WantMatched: nil, WantError: ErrTransactionAmountMismatch},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 150, IsDCA: true, IsPaid: false, WantMatched: nil, WantError: ErrTransactionDCA},
{TransactionID: "121", Outstanding: 150, Type: "penalty", MadeUpDate: "2017-06-30", Reason: "Failure to file a confirmation statement",
OriginalAmount: 150, IsDCA: false, IsPaid: false, WantMatched: matchedPenalties, WantError: nil},
}

Convey("matchPenalty works correctly for different scenarios", t, func() {
Expand All @@ -66,6 +69,7 @@ func TestUnitMatchPenalty(t *testing.T) {
IsDCA: testCase.IsDCA,
IsPaid: testCase.IsPaid,
MadeUpDate: testCase.MadeUpDate,
Reason: testCase.Reason,
},
}
matched, err := MatchPenalty(refTransactions, transactionsToMatch, companyNumber)
Expand Down
Loading

0 comments on commit 2fd8ffd

Please sign in to comment.