| package usagebased |
|
|
| import ( |
| "testing" |
|
|
| "github.com/alpacahq/alpacadecimal" |
| "github.com/stretchr/testify/require" |
|
|
| "github.com/openmeterio/openmeter/openmeter/productcatalog" |
| ) |
|
|
| |
| |
| |
| |
| func TestOverridableIntentGetEffectiveUnitConfig(t *testing.T) { |
| unitConfig := &productcatalog.UnitConfig{ |
| Operation: productcatalog.UnitConfigOperationDivide, |
| ConversionFactor: alpacadecimal.NewFromInt(1000), |
| Rounding: productcatalog.UnitConfigRoundingModeCeiling, |
| } |
|
|
| base := Intent{ |
| IntentMutableFields: IntentMutableFields{ |
| Price: *productcatalog.NewPriceFrom(productcatalog.UnitPrice{Amount: alpacadecimal.NewFromInt(1)}), |
| UnitConfig: unitConfig, |
| }, |
| FeatureKey: "f", |
| } |
|
|
| oi := base.AsOverridableIntent() |
|
|
| t.Run("override with an unrelated edit inherits the base unit_config", func(t *testing.T) { |
| |
| |
| overrideFields := oi.GetEffectiveIntent().IntentMutableFields |
| overrideFields.Name = "unrelated override edit" |
|
|
| withOverride := NewOverridableIntent(base, &overrideFields) |
|
|
| got := withOverride.GetEffectiveUnitConfig() |
| require.NotNil(t, got, "unrelated override must not drop the base unit_config") |
| require.True(t, unitConfig.Equal(got)) |
| }) |
|
|
| t.Run("explicit nil on the override is a cleared state, not inherited", func(t *testing.T) { |
| clearedFields := oi.GetEffectiveIntent().IntentMutableFields |
| clearedFields.UnitConfig = nil |
|
|
| cleared := NewOverridableIntent(base, &clearedFields) |
| require.Nil(t, cleared.GetEffectiveUnitConfig()) |
| }) |
| } |
|
|