File size: 2,989 Bytes
1c4c66b | 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | package testutils
import (
"context"
"github.com/openmeterio/openmeter/openmeter/billing"
)
var _ billing.LineEngine = NoopLineEngine{}
// NoopLineEngine is a test helper intended for embedding in line-engine fakes.
// It intentionally does not implement billing.LineCalculator.
type NoopLineEngine struct {
EngineType billing.LineEngineType
}
func (e NoopLineEngine) GetLineEngineType() billing.LineEngineType {
if e.EngineType == "" {
panic("engine type is required")
}
return e.EngineType
}
func (NoopLineEngine) IsLineBillableAsOf(context.Context, billing.IsLineBillableAsOfInput) (bool, error) {
return true, nil
}
func (NoopLineEngine) SplitGatheringLine(_ context.Context, input billing.SplitGatheringLineInput) (billing.SplitGatheringLineResult, error) {
return billing.SplitGatheringLineResult{
PreSplitAtLine: input.Line,
}, nil
}
func (NoopLineEngine) BuildStandardInvoiceLines(_ context.Context, input billing.BuildStandardInvoiceLinesInput) (billing.StandardLines, error) {
return input.GatheringLines.ToStandardLines(input.Invoice.ID)
}
func (NoopLineEngine) BuildStandardLinesForGatheringPreview(_ context.Context, input billing.BuildStandardInvoiceLinesInput) (billing.StandardLines, error) {
return input.GatheringLines.ToStandardLines(input.Invoice.ID)
}
func (NoopLineEngine) OnStandardInvoiceCreated(_ context.Context, input billing.OnStandardInvoiceCreatedInput) (billing.StandardLines, error) {
return input.Lines, nil
}
func (NoopLineEngine) OnCollectionCompleted(_ context.Context, input billing.OnCollectionCompletedInput) (billing.StandardLines, error) {
return input.Lines, nil
}
func (NoopLineEngine) ValidateMutableInvoiceLineEditViaAPI(_ context.Context, input billing.OnMutableInvoiceUpdateInput) error {
return input.Validate()
}
func (NoopLineEngine) OnMutableInvoiceLinesEditedViaAPI(_ context.Context, input billing.OnMutableInvoiceUpdateInput) (billing.OnMutableInvoiceUpdateResult, error) {
updatedLines := make([]billing.GenericInvoiceLine, 0, len(input.Updated))
for _, override := range input.Updated {
line, err := override.ChangesToApply.Apply(override.ExistingLine)
if err != nil {
return billing.OnMutableInvoiceUpdateResult{}, err
}
updatedLines = append(updatedLines, line)
}
return billing.OnMutableInvoiceUpdateResult{
CreatedLines: input.Created,
UpdatedLines: updatedLines,
}, nil
}
func (NoopLineEngine) OnMutableStandardLinesDeletedBySystem(context.Context, billing.OnMutableStandardLinesDeletedInput) error {
return nil
}
func (NoopLineEngine) OnUnsupportedCreditNote(context.Context, billing.OnUnsupportedCreditNoteInput) error {
return nil
}
func (NoopLineEngine) OnInvoiceIssued(context.Context, billing.OnInvoiceIssuedInput) error {
return nil
}
func (NoopLineEngine) OnPaymentAuthorized(context.Context, billing.OnPaymentAuthorizedInput) error {
return nil
}
func (NoopLineEngine) OnPaymentSettled(context.Context, billing.OnPaymentSettledInput) error {
return nil
}
|