Skip to content

Commit 3446aee

Browse files
authored
refactor: migrate current-account callers from NewMoneyFromInstrument to NewAmountFromInstrument (#2118)
Remove the two test-only callers of the deprecated NewMoneyFromInstrument function. The ValidCurrency and NonCurrencyDimension test cases are superseded by the existing TestNewAmountFromInstrument_AllDimensions suite which covers all dimension types. Strengthen the deprecation notice on NewMoneyFromInstrument to document that all callers have been migrated and the function is a candidate for removal. Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent e34bb05 commit 3446aee

2 files changed

Lines changed: 3 additions & 13 deletions

File tree

services/current-account/domain/quantity.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ var NewMoney = func(currencyCode string, amountMinorUnits int64) (Amount, error)
8989
// NewMoneyFromInstrument creates an Amount from persisted instrument_code + dimension and minor-unit amount.
9090
// Returns ErrInvalidCurrency if dimension is not "CURRENCY".
9191
//
92-
// Deprecated: Use NewAmountFromInstrument for new code which supports all dimensions.
92+
// Deprecated: Use NewAmountFromInstrument instead. NewMoneyFromInstrument rejects non-CURRENCY
93+
// dimensions (e.g. ENERGY, CARBON, COMPUTE) and hard-codes precision=2. All callers have been
94+
// migrated to NewAmountFromInstrument. This function will be removed in a future release.
9395
var NewMoneyFromInstrument = func(instrumentCode, dimension string, amountMinorUnits int64) (Amount, error) {
9496
if strings.ToUpper(dimension) != quantity.DimensionCurrency {
9597
return Amount{}, ErrInvalidCurrency

services/current-account/domain/quantity_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,6 @@ func TestNewAmountFromInstrument_InvalidDimension_ReturnsError(t *testing.T) {
295295
// (not ErrInstrumentMismatch which is for arithmetic on different instruments)
296296
}
297297

298-
func TestNewMoneyFromInstrument_ValidCurrency(t *testing.T) {
299-
m, err := NewMoneyFromInstrument("GBP", "CURRENCY", 5000)
300-
assert.NoError(t, err)
301-
assert.Equal(t, "GBP", m.InstrumentCode())
302-
assert.Equal(t, int64(5000), toMinorUnits(m))
303-
}
304-
305-
func TestNewMoneyFromInstrument_NonCurrencyDimension(t *testing.T) {
306-
_, err := NewMoneyFromInstrument("KWH", "ENERGY", 100)
307-
assert.ErrorIs(t, err, ErrInvalidCurrency)
308-
}
309-
310298
func TestZeroMoney_ValidCurrency(t *testing.T) {
311299
m, err := ZeroMoney("GBP")
312300
assert.NoError(t, err)

0 commit comments

Comments
 (0)