Documentation
¶
Index ¶
- Variables
- func BuildAddonForTesting(t *testing.T, period productcatalog.EffectivePeriod, ...) addon.CreateAddonInput
- func BuildTestPlan(t *testing.T) *testPlanbuilder
- func CreateAddonForSubscription(t *testing.T, deps *SubscriptionDependencies, subID models.NamespacedID, ...) subscriptionaddon.SubscriptionAddon
- func CreateMultiInstanceAddonForSubscription(t *testing.T, deps *SubscriptionDependencies, subID models.NamespacedID, ...) subscriptionaddon.SubscriptionAddon
- func CreatePlanWithAddon(t *testing.T, deps SubscriptionDependencies, planInp plan.CreatePlanInput, ...) (subscription.Plan, addon.Addon)
- func CreateSubscriptionFromPlan(t *testing.T, deps *SubscriptionDependencies, plan subscription.Plan, ...) subscription.SubscriptionView
- func GetEntitlementTemplateUsagePeriod(t *testing.T, et productcatalog.EntitlementTemplate) *datetime.ISODuration
- func GetExampleAddonInput(t *testing.T, effectivePeriod productcatalog.EffectivePeriod) addon.CreateAddonInput
- func GetExamplePlanInput(t *testing.T) plan.CreatePlanInput
- func NewCustomerAdapter(t *testing.T, dbDeps *DBDeps) *testCustomerRepo
- func NewCustomerService(t *testing.T, dbDeps *DBDeps) customer.Service
- func NewPlanHelper(planService plan.Service) *planHelper
- func NewSubscriptionItemRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionItemRepo
- func NewSubscriptionPhaseRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionPhaseRepo
- func NewSubscriptionRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionRepo
- func NewTestAddonService(svc addon.Service) *testAddonService
- func NewTestFeatureConnector(conn feature.FeatureConnector) *testFeatureConnector
- func SpecsEqual(t *testing.T, s1, s2 subscription.SubscriptionSpec)
- func SubscriptionAddonsEqual(t *testing.T, a1, a2 subscriptionaddon.SubscriptionAddon)
- func ValidateSpecAndView(t *testing.T, expected subscription.SubscriptionSpec, ...)
- type DBDeps
- type MockService
- func (s *MockService) Cancel(ctx context.Context, subscriptionID models.NamespacedID, ...) (subscription.Subscription, error)
- func (s *MockService) Continue(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
- func (s *MockService) Create(ctx context.Context, namespace string, spec subscription.SubscriptionSpec) (subscription.Subscription, error)
- func (s *MockService) Delete(ctx context.Context, subscriptionID models.NamespacedID) error
- func (s *MockService) Get(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
- func (s *MockService) GetAllForCustomerSince(ctx context.Context, customerID models.NamespacedID, at time.Time) ([]subscription.Subscription, error)
- func (s *MockService) GetView(ctx context.Context, subscriptionID models.NamespacedID) (subscription.SubscriptionView, error)
- func (s *MockService) List(ctx context.Context, params subscription.ListSubscriptionsInput) (subscription.SubscriptionList, error)
- func (s *MockService) RegisterValidator(validator subscription.SubscriptionValidator) error
- func (s *MockService) Update(ctx context.Context, subscriptionID models.NamespacedID, ...) (subscription.Subscription, error)
- type MockWorkflowService
- func (s *MockWorkflowService) ChangeToPlan(ctx context.Context, subscriptionID models.NamespacedID, ...) (current subscription.Subscription, new subscription.SubscriptionView, ...)
- func (s *MockWorkflowService) CreateFromPlan(ctx context.Context, inp subscriptionworkflow.CreateSubscriptionWorkflowInput, ...) (subscription.SubscriptionView, error)
- func (s *MockWorkflowService) EditRunning(ctx context.Context, subscriptionID models.NamespacedID, ...) (subscription.SubscriptionView, error)
- type SubscriptionDependencies
- type TestPatch
- func (p *TestPatch) ApplyTo(s *subscription.SubscriptionSpec, c subscription.ApplyContext) error
- func (p *TestPatch) MarshalJSON() ([]byte, error)
- func (p *TestPatch) Op() subscription.PatchOperation
- func (p *TestPatch) Path() subscription.SpecPath
- func (p *TestPatch) UnmarshalJSON(data []byte) error
- func (p *TestPatch) Validate() error
- func (p *TestPatch) Value() any
- func (p *TestPatch) ValueAsAny() any
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ExampleFeatureKey = "test-feature-1" ExampleFeatureKey2 = "test-feature-2" ExampleFeatureKey3 = "test-feature-3" ExampleFeatureMeterSlug = "meter1" )
View Source
var ( ExamplePriceAmount int64 = 100 ExampleRateCard1 productcatalog.UsageBasedRateCard = productcatalog.UsageBasedRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: ExampleFeatureKey, Name: "Rate Card 1", Description: lo.ToPtr("Rate Card 1 Description"), FeatureKey: lo.ToPtr(ExampleFeatureKey), FeatureID: nil, EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.MeteredEntitlementTemplate{ IssueAfterReset: lo.ToPtr(100.0), UsagePeriod: ISOMonth, }), TaxConfig: &productcatalog.TaxConfig{ Stripe: &productcatalog.StripeTaxConfig{ Code: "txcd_10000000", }, }, Price: productcatalog.NewPriceFrom(productcatalog.UnitPrice{ Amount: alpacadecimal.NewFromInt(ExamplePriceAmount), }), }, BillingCadence: ISOMonth, } ExampleRateCard2 productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: "rate-card-2", Name: "Rate Card 2", Description: lo.ToPtr("Rate Card 2 Description"), FeatureKey: nil, FeatureID: nil, Price: productcatalog.NewPriceFrom(productcatalog.FlatPrice{ Amount: alpacadecimal.NewFromInt(int64(0)), PaymentTerm: productcatalog.InAdvancePaymentTerm, }), }, BillingCadence: &ISOMonth, } ExampleRateCard3ForAddons productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: ExampleFeatureKey2, Name: "Rate Card 3 for Addons", Description: lo.ToPtr("Rate Card 3 Description"), FeatureKey: lo.ToPtr(ExampleFeatureKey2), FeatureID: nil, EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.MeteredEntitlementTemplate{ IssueAfterReset: lo.ToPtr(100.0), UsagePeriod: ISOMonth, }), TaxConfig: &productcatalog.TaxConfig{ Stripe: &productcatalog.StripeTaxConfig{ Code: "txcd_10000000", }, }, Price: productcatalog.NewPriceFrom(productcatalog.FlatPrice{ Amount: alpacadecimal.NewFromInt(ExamplePriceAmount), PaymentTerm: productcatalog.InAdvancePaymentTerm, }), }, BillingCadence: &ISOMonth, } // Has a boolean entitlement ExampleRateCard4ForAddons productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: ExampleFeatureKey, Name: "Rate Card 4 for Addons", Description: lo.ToPtr("Rate Card 4 Description"), FeatureKey: lo.ToPtr(ExampleFeatureKey), FeatureID: nil, EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.BooleanEntitlementTemplate{}), }, BillingCadence: &ISOMonth, } // DOES NOT have a boolean entitlement ExampleRateCard5ForAddons productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: ExampleFeatureKey, Name: "Rate Card 5 for Addons", Description: lo.ToPtr("Rate Card 5 Description"), FeatureKey: lo.ToPtr(ExampleFeatureKey), FeatureID: nil, EntitlementTemplate: nil, }, BillingCadence: &ISOMonth, } ExampleRateCardWithDiscounts productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Key: ExampleFeatureKey, Name: "Rate Card 1", Description: lo.ToPtr("Rate Card 1 Description"), FeatureKey: lo.ToPtr(ExampleFeatureKey), FeatureID: nil, EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.MeteredEntitlementTemplate{ IssueAfterReset: lo.ToPtr(100.0), UsagePeriod: ISOMonth, }), TaxConfig: &productcatalog.TaxConfig{ Stripe: &productcatalog.StripeTaxConfig{ Code: "txcd_10000000", }, }, Price: productcatalog.NewPriceFrom(productcatalog.UnitPrice{ Amount: alpacadecimal.NewFromInt(ExamplePriceAmount), }), Discounts: productcatalog.Discounts{ Percentage: &productcatalog.PercentageDiscount{ Percentage: models.NewPercentage(10), }, }, }, BillingCadence: &ISOMonth, } )
View Source
var ExampleAddonRateCard1 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 1", Description: lo.ToPtr("Test Addon Rate Card 1 Description"), Key: ExampleFeatureKey, FeatureKey: lo.ToPtr(ExampleFeatureKey), }, BillingCadence: &ISOMonth, }
View Source
var ExampleAddonRateCard2 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 2", Description: lo.ToPtr("Test Addon Rate Card 2 Description"), Key: "addon-rc-key-2", }, BillingCadence: &ISOMonth, }
View Source
var ExampleAddonRateCard3 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 3", Description: lo.ToPtr("Test Addon Rate Card 3 Description"), Key: ExampleFeatureKey3, FeatureKey: lo.ToPtr(ExampleFeatureKey3), EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.BooleanEntitlementTemplate{}), Price: productcatalog.NewPriceFrom(productcatalog.FlatPrice{ Amount: alpacadecimal.NewFromInt(100), PaymentTerm: productcatalog.InAdvancePaymentTerm, }), }, BillingCadence: &ISOMonth, }
Adds a bool entitlement and a 100 flat price without feature
View Source
var ExampleAddonRateCard4 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 4", Description: lo.ToPtr("Test Addon Rate Card 4 Description"), Key: ExampleFeatureKey2, FeatureKey: lo.ToPtr(ExampleFeatureKey2), Price: productcatalog.NewPriceFrom(productcatalog.FlatPrice{ Amount: alpacadecimal.NewFromInt(100), PaymentTerm: productcatalog.InAdvancePaymentTerm, }), }, BillingCadence: &ISOMonth, }
Adds a 100 flat price to ExampleFeatureKey2
View Source
var ExampleAddonRateCard5 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 5", Description: lo.ToPtr("Test Addon Rate Card 5 Description"), Key: ExampleFeatureKey, FeatureKey: lo.ToPtr(ExampleFeatureKey), EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.MeteredEntitlementTemplate{ IssueAfterReset: lo.ToPtr(50.0), UsagePeriod: ISOMonth, }), }, BillingCadence: &ISOMonth, }
Adds 50 usage to ExampleFeatureKey
View Source
var ExampleAddonRateCard6 = productcatalog.FlatFeeRateCard{ RateCardMeta: productcatalog.RateCardMeta{ Name: "Test Addon Rate Card 6", Description: lo.ToPtr("Test Addon Rate Card 6 Description"), Key: ExampleFeatureKey, FeatureKey: lo.ToPtr(ExampleFeatureKey), EntitlementTemplate: productcatalog.NewEntitlementTemplateFrom(productcatalog.BooleanEntitlementTemplate{}), }, BillingCadence: &ISOMonth, }
Adds a boolean entitlement to ExampleFeatureKey
View Source
var ExampleCreateCustomerInput customer.CreateCustomerInput = customer.CreateCustomerInput{ Namespace: ExampleNamespace, CustomerMutate: customer.CustomerMutate{ Name: ExampleCustomerEntity.Name, PrimaryEmail: ExampleCustomerEntity.PrimaryEmail, Currency: ExampleCustomerEntity.Currency, UsageAttribution: ExampleCustomerEntity.UsageAttribution, }, }
View Source
var ExampleCustomerEntity customer.Customer = customer.Customer{ ManagedResource: models.ManagedResource{ Name: "John Doe", }, PrimaryEmail: lo.ToPtr("mail@me.uk"), Currency: lo.ToPtr(currencyx.Code("USD")), UsageAttribution: customer.CustomerUsageAttribution{ SubjectKeys: []string{"john-doe"}, }, }
View Source
var ExampleFeature = feature.CreateFeatureInputs{ Name: "Example Feature", Key: ExampleFeatureKey, Namespace: ExampleNamespace, MeterSlug: lo.ToPtr(ExampleFeatureMeterSlug), }
View Source
var ExampleFeature2 = feature.CreateFeatureInputs{ Name: "Example Feature 2", Key: ExampleFeatureKey2, Namespace: ExampleNamespace, MeterSlug: lo.ToPtr(ExampleFeatureMeterSlug), }
View Source
var ExampleFeature3 = feature.CreateFeatureInputs{ Name: "Example Feature 3", Key: ExampleFeatureKey3, Namespace: ExampleNamespace, MeterSlug: lo.ToPtr(ExampleFeatureMeterSlug), }
View Source
var ExampleNamespace = "test-namespace"
View Source
var ISOMonth, _ = datetime.ISODurationString("P1M").Parse()
Functions ¶
func BuildAddonForTesting ¶
func BuildAddonForTesting(t *testing.T, period productcatalog.EffectivePeriod, typ productcatalog.AddonInstanceType, rcs ...productcatalog.RateCard) addon.CreateAddonInput
func BuildTestPlan ¶
func CreateAddonForSubscription ¶
func CreateAddonForSubscription(t *testing.T, deps *SubscriptionDependencies, subID models.NamespacedID, addonID models.NamespacedID, cadence models.CadencedModel) subscriptionaddon.SubscriptionAddon
func CreateMultiInstanceAddonForSubscription ¶
func CreateMultiInstanceAddonForSubscription(t *testing.T, deps *SubscriptionDependencies, subID models.NamespacedID, addonID models.NamespacedID, quants []subscriptionaddon.CreateSubscriptionAddonQuantityInput) subscriptionaddon.SubscriptionAddon
For most cases, use the workflow service instead!
func CreatePlanWithAddon ¶
func CreatePlanWithAddon( t *testing.T, deps SubscriptionDependencies, planInp plan.CreatePlanInput, addonInp addon.CreateAddonInput, ) (subscription.Plan, addon.Addon)
func CreateSubscriptionFromPlan ¶
func CreateSubscriptionFromPlan(t *testing.T, deps *SubscriptionDependencies, plan subscription.Plan, startAt time.Time) subscription.SubscriptionView
func GetEntitlementTemplateUsagePeriod ¶
func GetEntitlementTemplateUsagePeriod(t *testing.T, et productcatalog.EntitlementTemplate) *datetime.ISODuration
func GetExampleAddonInput ¶
func GetExampleAddonInput(t *testing.T, effectivePeriod productcatalog.EffectivePeriod) addon.CreateAddonInput
func GetExamplePlanInput ¶
func GetExamplePlanInput(t *testing.T) plan.CreatePlanInput
func NewCustomerAdapter ¶
func NewPlanHelper ¶
func NewSubscriptionItemRepo ¶
func NewSubscriptionRepo ¶
func NewTestAddonService ¶
func NewTestFeatureConnector ¶
func NewTestFeatureConnector(conn feature.FeatureConnector) *testFeatureConnector
func SpecsEqual ¶
func SpecsEqual(t *testing.T, s1, s2 subscription.SubscriptionSpec)
func SubscriptionAddonsEqual ¶
func SubscriptionAddonsEqual(t *testing.T, a1, a2 subscriptionaddon.SubscriptionAddon)
func ValidateSpecAndView ¶
func ValidateSpecAndView(t *testing.T, expected subscription.SubscriptionSpec, found subscription.SubscriptionView)
Ensures the created view matches the input spec
Types ¶
type DBDeps ¶
type DBDeps struct {
DBClient *db.Client
EntDriver *entdriver.EntPostgresDriver
PGDriver *pgdriver.Driver
}
func SetupDBDeps ¶
type MockService ¶
type MockService struct {
CreateFn func(ctx context.Context, namespace string, spec subscription.SubscriptionSpec) (subscription.Subscription, error)
UpdateFn func(ctx context.Context, subscriptionID models.NamespacedID, target subscription.SubscriptionSpec) (subscription.Subscription, error)
DeleteFn func(ctx context.Context, subscriptionID models.NamespacedID) error
CancelFn func(ctx context.Context, subscriptionID models.NamespacedID, at subscription.Timing) (subscription.Subscription, error)
ContinueFn func(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
GetFn func(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
GetViewFn func(ctx context.Context, subscriptionID models.NamespacedID) (subscription.SubscriptionView, error)
ListFn func(ctx context.Context, params subscription.ListSubscriptionsInput) (subscription.SubscriptionList, error)
GetAllForCustomerSinceFn func(ctx context.Context, customerID models.NamespacedID, at time.Time) ([]subscription.Subscription, error)
Validators []subscription.SubscriptionValidator
}
func (*MockService) Cancel ¶
func (s *MockService) Cancel(ctx context.Context, subscriptionID models.NamespacedID, at subscription.Timing) (subscription.Subscription, error)
func (*MockService) Continue ¶
func (s *MockService) Continue(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
func (*MockService) Create ¶
func (s *MockService) Create(ctx context.Context, namespace string, spec subscription.SubscriptionSpec) (subscription.Subscription, error)
func (*MockService) Delete ¶
func (s *MockService) Delete(ctx context.Context, subscriptionID models.NamespacedID) error
func (*MockService) Get ¶
func (s *MockService) Get(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)
func (*MockService) GetAllForCustomerSince ¶
func (s *MockService) GetAllForCustomerSince(ctx context.Context, customerID models.NamespacedID, at time.Time) ([]subscription.Subscription, error)
func (*MockService) GetView ¶
func (s *MockService) GetView(ctx context.Context, subscriptionID models.NamespacedID) (subscription.SubscriptionView, error)
func (*MockService) List ¶
func (s *MockService) List(ctx context.Context, params subscription.ListSubscriptionsInput) (subscription.SubscriptionList, error)
func (*MockService) RegisterValidator ¶
func (s *MockService) RegisterValidator(validator subscription.SubscriptionValidator) error
func (*MockService) Update ¶
func (s *MockService) Update(ctx context.Context, subscriptionID models.NamespacedID, target subscription.SubscriptionSpec) (subscription.Subscription, error)
type MockWorkflowService ¶
type MockWorkflowService struct {
CreateFromPlanFn func(ctx context.Context, inp subscriptionworkflow.CreateSubscriptionWorkflowInput, plan subscription.Plan) (subscription.SubscriptionView, error)
EditRunningFn func(ctx context.Context, subscriptionID models.NamespacedID, customizations []subscription.Patch) (subscription.SubscriptionView, error)
ChangeToPlanFn func(ctx context.Context, subscriptionID models.NamespacedID, inp subscriptionworkflow.ChangeSubscriptionWorkflowInput, plan subscription.Plan) (current subscription.Subscription, new subscription.SubscriptionView, err error)
}
func (*MockWorkflowService) ChangeToPlan ¶
func (s *MockWorkflowService) ChangeToPlan(ctx context.Context, subscriptionID models.NamespacedID, inp subscriptionworkflow.ChangeSubscriptionWorkflowInput, plan subscription.Plan) (current subscription.Subscription, new subscription.SubscriptionView, err error)
func (*MockWorkflowService) CreateFromPlan ¶
func (s *MockWorkflowService) CreateFromPlan(ctx context.Context, inp subscriptionworkflow.CreateSubscriptionWorkflowInput, plan subscription.Plan) (subscription.SubscriptionView, error)
func (*MockWorkflowService) EditRunning ¶
func (s *MockWorkflowService) EditRunning(ctx context.Context, subscriptionID models.NamespacedID, customizations []subscription.Patch) (subscription.SubscriptionView, error)
type SubscriptionDependencies ¶
type SubscriptionDependencies struct {
ItemRepo subscription.SubscriptionItemRepository
CustomerAdapter *testCustomerRepo
CustomerService customer.Service
FeatureConnector *testFeatureConnector
MeterService meter.Service
MockStreamingConnector *streamingtestutils.MockStreamingConnector
EntitlementAdapter subscription.EntitlementAdapter
PlanHelper *planHelper
PlanService plan.Service
DBDeps *DBDeps
EntitlementRegistry *registry.Entitlement
SubscriptionService subscription.Service
WorkflowService subscriptionworkflow.Service
SubscriptionAddonService subscriptionaddon.Service
AddonService *testAddonService
PlanAddonService planaddon.Service
}
func NewService ¶
func NewService(t *testing.T, dbDeps *DBDeps) SubscriptionDependencies
type TestPatch ¶
type TestPatch struct {
PatchValue any
PatchOperation subscription.PatchOperation
PatchPath subscription.SpecPath
ApplyToFn func(s *subscription.SubscriptionSpec, c subscription.ApplyContext) error
ValdiateFn func() error
}
func (*TestPatch) ApplyTo ¶
func (p *TestPatch) ApplyTo(s *subscription.SubscriptionSpec, c subscription.ApplyContext) error
func (*TestPatch) MarshalJSON ¶
func (*TestPatch) Op ¶
func (p *TestPatch) Op() subscription.PatchOperation
func (*TestPatch) Path ¶
func (p *TestPatch) Path() subscription.SpecPath
func (*TestPatch) UnmarshalJSON ¶
func (*TestPatch) ValueAsAny ¶
Click to show internal directories.
Click to hide internal directories.