File size: 1,928 Bytes
16cdcb7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package subscriptiontestutils
import (
"context"
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
"github.com/openmeterio/openmeter/openmeter/productcatalog"
"github.com/openmeterio/openmeter/openmeter/productcatalog/plan"
plansubscription "github.com/openmeterio/openmeter/openmeter/productcatalog/subscription"
"github.com/openmeterio/openmeter/openmeter/subscription"
"github.com/openmeterio/openmeter/openmeter/testutils"
"github.com/openmeterio/openmeter/pkg/clock"
"github.com/openmeterio/openmeter/pkg/datetime"
)
func GetExamplePlanInput(t *testing.T) plan.CreatePlanInput {
b := BuildTestPlanInput(t)
b.AddPhase(lo.ToPtr(datetime.MustParseDuration(t, "P1M")), ExampleRateCard1.Clone())
b.AddPhase(lo.ToPtr(datetime.MustParseDuration(t, "P2M")), ExampleRateCard1.Clone(), ExampleRateCard2.Clone(), ExampleRateCard3ForAddons.Clone())
b.AddPhase(nil, ExampleRateCard1.Clone(), ExampleRateCard3ForAddons.Clone())
return b.Build()
}
// PlanHelper simply creates and returns a plan
type planHelper struct {
planService plan.Service
}
func NewPlanHelper(planService plan.Service) *planHelper {
return &planHelper{
planService: planService,
}
}
func (h *planHelper) CreatePlan(t *testing.T, input plan.CreatePlanInput) subscription.Plan {
t.Helper()
ctx := context.Background()
p, err := h.planService.CreatePlan(ctx, input)
require.Nil(t, err)
require.NotNil(t, p)
p, err = h.planService.PublishPlan(ctx, plan.PublishPlanInput{
NamespacedID: p.NamespacedID,
EffectivePeriod: productcatalog.EffectivePeriod{
EffectiveFrom: lo.ToPtr(clock.Now()),
EffectiveTo: lo.ToPtr(testutils.GetRFC3339Time(t, "2030-01-01T00:00:00Z")),
},
})
require.Nil(t, err)
require.NotNil(t, p)
require.Nilf(t, p.DeletedAt, "plan %s should not be deleted", p.NamespacedID.ID)
return &plansubscription.Plan{
Plan: p.AsProductCatalogPlan(),
Ref: &p.NamespacedID,
}
}
|