@@ -450,6 +450,78 @@ func TestPostgresAdapter(t *testing.T) {
450450 })
451451}
452452
453+ func TestListAddonsExcludeUnitConfig (t * testing.T ) {
454+ ctx := context .Background ()
455+
456+ env := pctestutils .NewTestEnv (t )
457+ t .Cleanup (func () { env .Close (t ) })
458+ env .DBSchemaMigrate (t )
459+
460+ namespace := pctestutils .NewTestNamespace (t )
461+
462+ require .NoError (t , env .Meter .ReplaceMeters (ctx , pctestutils .NewTestMeters (t , namespace )),
463+ "replacing meters must not fail" )
464+ meters , err := env .Meter .ListMeters (ctx , meter.ListMetersParams {
465+ Page : pagination.Page {PageSize : 1000 , PageNumber : 1 },
466+ Namespace : namespace ,
467+ })
468+ require .NoError (t , err , "listing meters must not fail" )
469+ require .NotEmpty (t , meters .Items , "list of meters must not be empty" )
470+
471+ feat , err := env .Feature .CreateFeature (ctx , pctestutils .NewTestFeatureFromMeter (t , & meters .Items [0 ]))
472+ require .NoError (t , err , "creating feature must not fail" )
473+
474+ // Plain add-on: flat rate card, no unit_config → v1-representable.
475+ plainInput := pctestutils .NewTestAddon (t , namespace , & productcatalog.FlatFeeRateCard {
476+ RateCardMeta : productcatalog.RateCardMeta {Key : "flat" , Name : "Flat" },
477+ })
478+ plainInput .Addon .Key = "plain"
479+ _ , err = env .AddonRepository .CreateAddon (ctx , plainInput )
480+ require .NoError (t , err , "creating plain add-on must not fail" )
481+
482+ // unit_config add-on: usage-based rate card carrying a unit_config → not v1-representable.
483+ ucInput := pctestutils .NewTestAddon (t , namespace , & productcatalog.UsageBasedRateCard {
484+ RateCardMeta : productcatalog.RateCardMeta {
485+ Key : feat .Key ,
486+ Name : "UC RateCard" ,
487+ FeatureKey : lo .ToPtr (feat .Key ),
488+ FeatureID : lo .ToPtr (feat .ID ),
489+ Price : productcatalog .NewPriceFrom (productcatalog.UnitPrice {Amount : decimal .NewFromInt (1 )}),
490+ UnitConfig : & productcatalog.UnitConfig {
491+ Operation : productcatalog .UnitConfigOperationDivide ,
492+ ConversionFactor : decimal .NewFromInt (1000 ),
493+ },
494+ },
495+ BillingCadence : MonthPeriod ,
496+ })
497+ ucInput .Addon .Key = "with-uc"
498+ _ , err = env .AddonRepository .CreateAddon (ctx , ucInput )
499+ require .NoError (t , err , "creating unit_config add-on must not fail" )
500+
501+ t .Run ("included when ExcludeUnitConfig is false" , func (t * testing.T ) {
502+ list , err := env .AddonRepository .ListAddons (ctx , addon.ListAddonsInput {
503+ Namespaces : []string {namespace },
504+ })
505+ require .NoError (t , err , "listing add-ons must not fail" )
506+
507+ keys := lo .Map (list .Items , func (a addon.Addon , _ int ) string { return a .Key })
508+ require .ElementsMatch (t , []string {"plain" , "with-uc" }, keys )
509+ require .Equal (t , 2 , list .TotalCount , "TotalCount must count both add-ons" )
510+ })
511+
512+ t .Run ("excluded when ExcludeUnitConfig is true, TotalCount stays consistent" , func (t * testing.T ) {
513+ list , err := env .AddonRepository .ListAddons (ctx , addon.ListAddonsInput {
514+ Namespaces : []string {namespace },
515+ ExcludeUnitConfig : true ,
516+ })
517+ require .NoError (t , err , "listing add-ons must not fail" )
518+
519+ keys := lo .Map (list .Items , func (a addon.Addon , _ int ) string { return a .Key })
520+ require .ElementsMatch (t , []string {"plain" }, keys )
521+ require .Equal (t , 1 , list .TotalCount , "TotalCount must exclude the unit_config add-on, not just the page slice" )
522+ })
523+ }
524+
453525// TestFromPlanRateCardRowMapsUnitConfig guards the cross-package mapper used when an
454526// add-on is loaded with expanded linked plans
455527// (FromAddonRow → FromPlanAddonRow → FromPlanRow → FromPlanPhaseRow → FromPlanRateCardRow).
0 commit comments