Skip to content

Commit 476c4e0

Browse files
committed
test: moved the find ratecard by key util to the helpers
1 parent 99c1e93 commit 476c4e0

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

e2e/plans_v3_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -603,36 +603,3 @@ func TestV3PlanReadTranslatesV1DynamicAndPackagePrices(t *testing.T) {
603603
assert.Equal(t, apiv3.BillingUnitConfigRoundingModeCeiling, *pkgRC.UnitConfig.Rounding)
604604
})
605605
}
606-
607-
// findRateCardByKey looks up a rate card by key across all phases of a plan.
608-
// Fails the test if no match is found.
609-
func findRateCardByKey(t *testing.T, plan *apiv3.BillingPlan, key string) *apiv3.BillingRateCard {
610-
t.Helper()
611-
612-
for i := range plan.Phases {
613-
for j := range plan.Phases[i].RateCards {
614-
rc := &plan.Phases[i].RateCards[j]
615-
if rc.Key == key {
616-
return rc
617-
}
618-
}
619-
}
620-
621-
require.FailNow(t, "rate card not found", "key=%s", key)
622-
return nil
623-
}
624-
625-
// assertUnitPriceAmount asserts the rate card's price discriminates as "unit"
626-
// and carries the given amount. Used to verify the synthesized unit price that
627-
// replaces v1 dynamic and package prices on the v3 read path.
628-
func assertUnitPriceAmount(t *testing.T, rc *apiv3.BillingRateCard, want string) {
629-
t.Helper()
630-
631-
disc, err := rc.Price.Discriminator()
632-
require.NoError(t, err)
633-
require.Equal(t, "unit", disc, "expected synthesized unit price")
634-
635-
unit, err := rc.Price.AsBillingPriceUnit()
636-
require.NoError(t, err)
637-
assert.Equal(t, want, unit.Amount)
638-
}

e2e/v3helpers_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,36 @@ func assertInvalidParameterRule(t *testing.T, problem *v3Problem, rule string) {
512512
}
513513
assert.Failf(t, "invalid parameter rule not found", "expected %q, got %v", rule, rules)
514514
}
515+
516+
// findRateCardByKey looks up a rate card by key across all phases of a plan.
517+
// Fails the test if no match is found.
518+
func findRateCardByKey(t *testing.T, plan *apiv3.BillingPlan, key string) *apiv3.BillingRateCard {
519+
t.Helper()
520+
521+
for i := range plan.Phases {
522+
for j := range plan.Phases[i].RateCards {
523+
rc := &plan.Phases[i].RateCards[j]
524+
if rc.Key == key {
525+
return rc
526+
}
527+
}
528+
}
529+
530+
require.FailNow(t, "rate card not found", "key=%s", key)
531+
return nil
532+
}
533+
534+
// assertUnitPriceAmount asserts the rate card's price discriminates as "unit"
535+
// and carries the given amount. Used to verify the synthesized unit price that
536+
// replaces v1 dynamic and package prices on the v3 read path.
537+
func assertUnitPriceAmount(t *testing.T, rc *apiv3.BillingRateCard, want string) {
538+
t.Helper()
539+
540+
disc, err := rc.Price.Discriminator()
541+
require.NoError(t, err)
542+
require.Equal(t, "unit", disc, "expected synthesized unit price")
543+
544+
unit, err := rc.Price.AsBillingPriceUnit()
545+
require.NoError(t, err)
546+
assert.Equal(t, want, unit.Amount)
547+
}

0 commit comments

Comments
 (0)