99 "github.com/stretchr/testify/require"
1010
1111 api "github.com/openmeterio/openmeter/api/client/go"
12- apiv3 "github.com/openmeterio/openmeter/api/v3"
12+ v3sdk "github.com/openmeterio/openmeter/api/v3/client "
1313)
1414
1515const unitConfigNotRepresentableCode = "unit_config_not_representable"
@@ -33,88 +33,86 @@ func TestV1ReadSurfaceExcludesUnitConfig(t *testing.T) {
3333 ucPlanKey := "ucread_uc_plan_" + uniq
3434 plainPlanKey := "ucread_plain_plan_" + uniq
3535
36- var ucPlan * apiv3. BillingPlan
37- var plainPlan * apiv3. BillingPlan
36+ var ucPlan * v3sdk. Plan
37+ var plainPlan * v3sdk. Plan
3838
3939 // given:
4040 // - a unit_config plan (usage-based rate card, divide-by-1000 ceiling) and a plain plan, both
4141 // authored and published via v3 (v1 cannot author unit_config).
4242 runRequired (t , "creates a unit_config plan and a plain plan" , func (t * testing.T ) {
43- status , meter , problem := c .CreateMeter (apiv3 .CreateMeterRequest {
43+ meter , err := c .Meters . Create ( t . Context (), v3sdk .CreateMeterRequest {
4444 Key : meterKey ,
4545 Name : "UC Read Meter " + uniq ,
46- Aggregation : apiv3 .MeterAggregationSum ,
46+ Aggregation : v3sdk .MeterAggregationSum ,
4747 EventType : eventType ,
4848 ValueProperty : lo .ToPtr ("$.value" ),
4949 })
50- require . Equal ( t , http .StatusCreated , status , "problem: %+v" , problem )
50+ c . requireStatus ( http .StatusCreated , err )
5151 require .NotNil (t , meter )
5252
53- status , feature , problem := c .CreateFeature (apiv3 .CreateFeatureRequest {
53+ feature , err := c .Features . Create ( t . Context (), v3sdk .CreateFeatureRequest {
5454 Key : featureKey ,
5555 Name : "UC Read Feature " + uniq ,
56- Meter : & apiv3. FeatureMeterReference { Id : meter .Id },
56+ Meter : & v3sdk. FeatureMeterReferenceInput { ID : meter .ID },
5757 })
58- require . Equal ( t , http .StatusCreated , status , "problem: %+v" , problem )
58+ c . requireStatus ( http .StatusCreated , err )
5959 require .NotNil (t , feature )
6060
61- cadence := apiv3 .ISO8601Duration ("P1M" )
62- term := apiv3 .BillingPricePaymentTermInArrears
63- price := apiv3.BillingPrice {}
64- require .NoError (t , price .FromBillingPriceUnit (apiv3.BillingPriceUnit {
65- Type : apiv3 .BillingPriceUnitTypeUnit ,
61+ cadence := "P1M"
62+ term := v3sdk .PricePaymentTermInArrears
63+ price := lo .Must (v3sdk .PriceFromPriceUnit (v3sdk.PriceUnit {
6664 Amount : "0.10" ,
6765 }))
68- ucRateCard := apiv3. BillingRateCard {
66+ ucRateCard := v3sdk. RateCardInput {
6967 Key : feature .Key ,
7068 Name : "UC Read Rate Card " + uniq ,
7169 Price : price ,
7270 BillingCadence : & cadence ,
7371 PaymentTerm : & term ,
74- Feature : & apiv3 .FeatureReference {Id : feature .Id },
75- UnitConfig : & apiv3. BillingUnitConfig {
76- Operation : apiv3 . BillingUnitConfigOperationDivide ,
72+ Feature : & v3sdk .FeatureReference {ID : feature .ID },
73+ UnitConfig : & v3sdk. UnitConfig {
74+ Operation : v3sdk . UnitConfigOperationDivide ,
7775 ConversionFactor : "1000" ,
78- Rounding : lo .ToPtr (apiv3 . BillingUnitConfigRoundingModeCeiling ),
79- Precision : lo .ToPtr (0 ),
76+ Rounding : lo .ToPtr (v3sdk . UnitConfigRoundingModeCeiling ),
77+ Precision : lo .ToPtr (int64 ( 0 ) ),
8078 },
8179 }
8280
83- status , createdUC , problem := c .CreatePlan (apiv3 .CreatePlanRequest {
81+ createdUC , err := c .Plans . Create ( t . Context (), v3sdk .CreatePlanRequest {
8482 Key : ucPlanKey ,
8583 Name : "UC Read Plan " + uniq ,
8684 Currency : "USD" ,
87- BillingCadence : apiv3 . ISO8601Duration ( "P1M" ) ,
88- Phases : []apiv3. BillingPlanPhase {{
85+ BillingCadence : "P1M" ,
86+ Phases : []v3sdk. PlanPhaseInput {{
8987 Key : "phase_1" ,
9088 Name : "UC Phase" ,
91- RateCards : []apiv3. BillingRateCard {ucRateCard },
89+ RateCards : []v3sdk. RateCardInput {ucRateCard },
9290 }},
9391 })
94- require . Equal ( t , http .StatusCreated , status , "problem: %+v" , problem )
92+ c . requireStatus ( http .StatusCreated , err )
9593 require .NotNil (t , createdUC )
96- status , ucPlan , problem = c .PublishPlan ( createdUC .Id )
97- require . Equal ( t , http .StatusOK , status , "problem: %+v" , problem )
94+ ucPlan , err = c .Plans . Publish ( t . Context (), createdUC .ID )
95+ c . requireStatus ( http .StatusOK , err )
9896 require .NotNil (t , ucPlan )
9997
100- status , createdPlain , problem := c .CreatePlan (apiv3 .CreatePlanRequest {
98+ createdPlain , err := c .Plans . Create ( t . Context (), v3sdk .CreatePlanRequest {
10199 Key : plainPlanKey ,
102100 Name : "Plain Read Plan " + uniq ,
103101 Currency : "USD" ,
104- BillingCadence : apiv3 . ISO8601Duration ( "P1M" ) ,
105- Phases : []apiv3. BillingPlanPhase {validPlanPhase ("plain_phase" , true /* isLast */ )},
102+ BillingCadence : "P1M" ,
103+ Phases : []v3sdk. PlanPhaseInput {validPlanPhase ("plain_phase" , true /* isLast */ )},
106104 })
107- require . Equal ( t , http .StatusCreated , status , "problem: %+v" , problem )
105+ c . requireStatus ( http .StatusCreated , err )
108106 require .NotNil (t , createdPlain )
109- status , plainPlan , problem = c .PublishPlan ( createdPlain .Id )
110- require . Equal ( t , http .StatusOK , status , "problem: %+v" , problem )
107+ plainPlan , err = c .Plans . Publish ( t . Context (), createdPlain .ID )
108+ c . requireStatus ( http .StatusOK , err )
111109 require .NotNil (t , plainPlan )
112110 })
113111
114112 // then:
115113 // - v1 GET on the unit_config plan is rejected with the typed code (not a silently-stripped 200).
116114 runRequired (t , "v1 plan GET rejects the unit_config plan" , func (t * testing.T ) {
117- resp , err := v1 .GetPlanWithResponse (t .Context (), ucPlan .Id , nil )
115+ resp , err := v1 .GetPlanWithResponse (t .Context (), ucPlan .ID , nil )
118116 require .NoError (t , err )
119117 require .Equal (t , http .StatusBadRequest , resp .StatusCode (), "body: %s" , string (resp .Body ))
120118 require .NotNil (t , resp .ApplicationproblemJSON400 )
@@ -124,7 +122,7 @@ func TestV1ReadSurfaceExcludesUnitConfig(t *testing.T) {
124122 // and:
125123 // - the plain plan is still gettable via v1 (the exclusion is content-derived, not a blanket block).
126124 runRequired (t , "v1 plan GET returns the plain plan" , func (t * testing.T ) {
127- resp , err := v1 .GetPlanWithResponse (t .Context (), plainPlan .Id , nil )
125+ resp , err := v1 .GetPlanWithResponse (t .Context (), plainPlan .ID , nil )
128126 require .NoError (t , err )
129127 require .Equal (t , http .StatusOK , resp .StatusCode (), "body: %s" , string (resp .Body ))
130128 require .NotNil (t , resp .JSON200 )
0 commit comments