subscriptiontestutils

package
v1.0.0-beta.205 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2025 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ExampleRateCard1 productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{
		RateCardMeta: productcatalog.RateCardMeta{
			Key:         ExampleFeatureKey,
			Name:        "Rate Card 1",
			Description: lo.ToPtr("Rate Card 1 Description"),
			Feature: &feature.Feature{
				Key: ExampleFeatureKey,
			},
			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(int64(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"),
			Feature:     nil,
			Price: productcatalog.NewPriceFrom(productcatalog.FlatPrice{
				Amount:      alpacadecimal.NewFromInt(int64(0)),
				PaymentTerm: productcatalog.InAdvancePaymentTerm,
			}),
		},
		BillingCadence: &ISOMonth,
	}
	ExamplePriceAmount int = 100

	ExampleRateCardWithDiscounts productcatalog.FlatFeeRateCard = productcatalog.FlatFeeRateCard{
		RateCardMeta: productcatalog.RateCardMeta{
			Key:         ExampleFeatureKey,
			Name:        "Rate Card 1",
			Description: lo.ToPtr("Rate Card 1 Description"),
			Feature: &feature.Feature{
				Key: ExampleFeatureKey,
			},
			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(int64(ExamplePriceAmount)),
			}),
			Discounts: productcatalog.Discounts{
				productcatalog.NewDiscountFrom(productcatalog.PercentageDiscount{
					Percentage: models.NewPercentage(10),
				}),
			},
		},
		BillingCadence: &ISOMonth,
	}
)
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 ExampleFeatureKey = "test-feature-1"
View Source
var ExampleFeatureMeterSlug = "meter1"
View Source
var ExampleNamespace = "test-namespace"
View Source
var ISOMonth, _ = isodate.String("P1M").Parse()

Functions

func GetEntitlementTemplateUsagePeriod

func GetEntitlementTemplateUsagePeriod(t *testing.T, et productcatalog.EntitlementTemplate) *isodate.Period

func GetExamplePlanInput

func GetExamplePlanInput(t *testing.T) plan.CreatePlanInput

func NewCustomerAdapter

func NewCustomerAdapter(t *testing.T, dbDeps *DBDeps) *testCustomerRepo

func NewCustomerService

func NewCustomerService(t *testing.T, dbDeps *DBDeps) customer.Service

func NewPlanHelper

func NewPlanHelper(planService plan.Service) *planHelper

func NewSubscriptionItemRepo

func NewSubscriptionItemRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionItemRepo

func NewSubscriptionPhaseRepo

func NewSubscriptionPhaseRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionPhaseRepo

func NewSubscriptionRepo

func NewSubscriptionRepo(t *testing.T, dbDeps *DBDeps) testSubscriptionRepo

func NewTestFeatureConnector

func NewTestFeatureConnector(conn feature.FeatureConnector) *testFeatureConnector

func SpecsEqual

func SpecsEqual(t *testing.T, s1, s2 subscription.SubscriptionSpec)

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

func SetupDBDeps(t *testing.T) *DBDeps

func (*DBDeps) Cleanup

func (d *DBDeps) Cleanup(t *testing.T)

type ExposedServiceDeps

type ExposedServiceDeps struct {
	ItemRepo            subscription.SubscriptionItemRepository
	CustomerAdapter     *testCustomerRepo
	CustomerService     customer.Service
	FeatureConnector    *testFeatureConnector
	EntitlementAdapter  subscription.EntitlementAdapter
	PlanHelper          *planHelper
	PlanService         plan.Service
	DBDeps              *DBDeps
	EntitlementRegistry *registry.Entitlement
}

func NewService

func NewService(t *testing.T, dbDeps *DBDeps) (services, ExposedServiceDeps)

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 (*MockService) Continue

func (s *MockService) Continue(ctx context.Context, subscriptionID models.NamespacedID) (subscription.Subscription, error)

func (*MockService) Create

func (*MockService) Delete

func (s *MockService) Delete(ctx context.Context, subscriptionID models.NamespacedID) error

func (*MockService) Get

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) RegisterValidator

func (s *MockService) RegisterValidator(validator subscription.SubscriptionValidator) error

func (*MockService) Update

type MockWorkflowService

type MockWorkflowService struct {
	CreateFromPlanFn func(ctx context.Context, inp subscription.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 subscription.ChangeSubscriptionWorkflowInput, plan subscription.Plan) (current subscription.Subscription, new subscription.SubscriptionView, err error)
}

func (*MockWorkflowService) EditRunning

func (s *MockWorkflowService) EditRunning(ctx context.Context, subscriptionID models.NamespacedID, customizations []subscription.Patch) (subscription.SubscriptionView, error)

type TestPatch

type TestPatch struct {
	PatchValue     any
	PatchOperation subscription.PatchOperation
	PatchPath      subscription.PatchPath

	ApplyToFn  func(s *subscription.SubscriptionSpec, c subscription.ApplyContext) error
	ValdiateFn func() error
}

func (*TestPatch) ApplyTo

func (*TestPatch) MarshalJSON

func (p *TestPatch) MarshalJSON() ([]byte, error)

func (*TestPatch) Op

func (*TestPatch) Path

func (p *TestPatch) Path() subscription.PatchPath

func (*TestPatch) UnmarshalJSON

func (p *TestPatch) UnmarshalJSON(data []byte) error

func (*TestPatch) Validate

func (p *TestPatch) Validate() error

func (*TestPatch) Value

func (p *TestPatch) Value() any

func (*TestPatch) ValueAsAny

func (p *TestPatch) ValueAsAny() any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL