Skip to content

Commit 1886e79

Browse files
committed
fix: testcases
1 parent 976dc64 commit 1886e79

3 files changed

Lines changed: 38 additions & 96 deletions

File tree

test/app/stripe/invoice_test.go

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,6 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
301301
Customer: customerEntity.GetID(),
302302
Currency: currencyx.Code(currency.USD),
303303
Lines: []*billing.Line{
304-
{
305-
// Covered case: standalone flat line
306-
LineBase: billing.LineBase{
307-
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
308-
Name: "Fee",
309-
}),
310-
Period: billing.Period{Start: periodStart, End: periodEnd},
311-
InvoiceAt: periodEnd,
312-
ManagedBy: billing.ManuallyManagedLine,
313-
Type: billing.InvoiceLineTypeFee,
314-
},
315-
FlatFee: &billing.FlatFeeLine{
316-
PerUnitAmount: alpacadecimal.NewFromFloat(100),
317-
PaymentTerm: productcatalog.InArrearsPaymentTerm,
318-
Quantity: alpacadecimal.NewFromFloat(1),
319-
Category: billing.FlatFeeCategoryRegular,
320-
},
321-
},
322304
{
323305
// Covered case: Discount caused by maximum amount
324306
LineBase: billing.LineBase{
@@ -459,7 +441,7 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
459441
},
460442
)
461443
s.NoError(err)
462-
s.Len(pendingLines.Lines, 6)
444+
s.Len(pendingLines.Lines, 5)
463445
})
464446

465447
clock.FreezeTime(periodEnd.Add(time.Minute))
@@ -572,19 +554,6 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
572554
}
573555

574556
expectedInvoiceAddLines := []*stripe.InvoiceItemParams{
575-
{
576-
Amount: lo.ToPtr(int64(10000)),
577-
Description: lo.ToPtr("Fee"),
578-
Customer: lo.ToPtr(customerData.StripeCustomerID),
579-
Period: &stripe.InvoiceItemPeriodParams{
580-
Start: lo.ToPtr(expectedPeriodStartUnix),
581-
End: lo.ToPtr(expectedPeriodEndUnix),
582-
},
583-
Metadata: map[string]string{
584-
"om_line_id": getLineID("Fee"),
585-
"om_line_type": "line",
586-
},
587-
},
588557
{
589558
Amount: lo.ToPtr(int64(7725)),
590559
Description: lo.ToPtr("UBP - AI Usecase: usage in period (103,000,025 x $0.000001)"),
@@ -780,7 +749,7 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
780749
s.NoError(err)
781750

782751
// Remove a line item.
783-
lineToRemove := getLine("Fee")
752+
lineToRemove := getLine("UBP - FLAT per any usage")
784753
s.NotNil(lineToRemove, "line ID to remove is not found")
785754

786755
// Find the stripe line ID to remove.
@@ -796,7 +765,7 @@ func (s *StripeInvoiceTestSuite) TestComplexInvoice() {
796765

797766
s.NotEmpty(stripeLineIDToRemove, "stripe line ID to remove is empty")
798767

799-
ok = updateInvoice.Lines.RemoveByID(lineToRemove.ID)
768+
ok = updateInvoice.Lines.RemoveByID(*lineToRemove.ParentLineID)
800769
s.True(ok, "failed to remove line item")
801770

802771
// To simulate the update, we will update the external ID of the invoice.

test/billing/invoice_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -643,30 +643,21 @@ func (s *InvoicingTestSuite) TestCreateInvoice() {
643643
Customer: customerEntity.GetID(),
644644
Currency: currencyx.Code(currency.USD),
645645
Lines: []*billing.Line{
646-
{
647-
LineBase: billing.LineBase{
648-
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
649-
Name: "Test item1",
650-
Namespace: namespace,
651-
}),
652-
Period: billing.Period{Start: periodStart, End: periodEnd},
646+
billing.NewFlatFeeLine(billing.NewFlatFeeLineInput{
647+
Name: "Test item1",
648+
Namespace: namespace,
649+
Period: billing.Period{Start: periodStart, End: periodEnd},
653650

654-
InvoiceAt: line1IssueAt,
651+
InvoiceAt: line1IssueAt,
655652

656-
Type: billing.InvoiceLineTypeFee,
657-
ManagedBy: billing.ManuallyManagedLine,
653+
ManagedBy: billing.ManuallyManagedLine,
658654

659-
Metadata: map[string]string{
660-
"key": "value",
661-
},
662-
},
663-
FlatFee: &billing.FlatFeeLine{
664-
PerUnitAmount: alpacadecimal.NewFromFloat(100),
665-
Quantity: alpacadecimal.NewFromFloat(1),
666-
Category: billing.FlatFeeCategoryRegular,
667-
PaymentTerm: productcatalog.InAdvancePaymentTerm,
655+
Metadata: map[string]string{
656+
"key": "value",
668657
},
669-
},
658+
PerUnitAmount: alpacadecimal.NewFromFloat(100),
659+
PaymentTerm: productcatalog.InAdvancePaymentTerm,
660+
}),
670661
},
671662
})
672663

test/billing/suite.go

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -390,54 +390,36 @@ func (s *BaseSuite) CreateGatheringInvoice(t *testing.T, ctx context.Context, in
390390
Customer: in.Customer.GetID(),
391391
Currency: currencyx.Code(currency.USD),
392392
Lines: []*billing.Line{
393-
{
394-
LineBase: billing.LineBase{
395-
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
396-
Namespace: namespace,
397-
Name: "Test item1",
398-
}),
399-
Period: billing.Period{Start: periodStart, End: periodEnd},
400-
401-
InvoiceAt: invoiceAt,
402-
403-
Type: billing.InvoiceLineTypeFee,
404-
ManagedBy: billing.ManuallyManagedLine,
405-
406-
Currency: currencyx.Code(currency.USD),
407-
393+
billing.NewFlatFeeLine(
394+
billing.NewFlatFeeLineInput{
395+
Namespace: namespace,
396+
Period: billing.Period{Start: periodStart, End: periodEnd},
397+
InvoiceAt: invoiceAt,
398+
ManagedBy: billing.ManuallyManagedLine,
399+
Name: "Test item1",
400+
PerUnitAmount: alpacadecimal.NewFromFloat(100),
401+
Currency: currencyx.Code(currency.USD),
408402
Metadata: map[string]string{
409403
"key": "value",
410404
},
405+
PaymentTerm: productcatalog.InArrearsPaymentTerm,
411406
},
412-
FlatFee: &billing.FlatFeeLine{
413-
PerUnitAmount: alpacadecimal.NewFromFloat(100),
414-
Quantity: alpacadecimal.NewFromFloat(1),
415-
Category: billing.FlatFeeCategoryRegular,
416-
PaymentTerm: productcatalog.InAdvancePaymentTerm,
417-
},
418-
},
419-
{
420-
LineBase: billing.LineBase{
421-
ManagedResource: models.NewManagedResource(models.ManagedResourceInput{
422-
Namespace: namespace,
423-
Name: "Test item2",
424-
}),
425-
Period: billing.Period{Start: periodStart, End: periodEnd},
426-
427-
InvoiceAt: invoiceAt,
428-
429-
Type: billing.InvoiceLineTypeFee,
430-
ManagedBy: billing.ManuallyManagedLine,
431-
432-
Currency: currencyx.Code(currency.USD),
433-
},
434-
FlatFee: &billing.FlatFeeLine{
407+
),
408+
billing.NewFlatFeeLine(
409+
billing.NewFlatFeeLineInput{
410+
Namespace: namespace,
411+
Period: billing.Period{Start: periodStart, End: periodEnd},
412+
InvoiceAt: invoiceAt,
413+
ManagedBy: billing.ManuallyManagedLine,
414+
Name: "Test item2",
435415
PerUnitAmount: alpacadecimal.NewFromFloat(200),
436-
Quantity: alpacadecimal.NewFromFloat(1),
437-
Category: billing.FlatFeeCategoryRegular,
438-
PaymentTerm: productcatalog.InAdvancePaymentTerm,
416+
Currency: currencyx.Code(currency.USD),
417+
Metadata: map[string]string{
418+
"key": "value",
419+
},
420+
PaymentTerm: productcatalog.InArrearsPaymentTerm,
439421
},
440-
},
422+
),
441423
},
442424
})
443425

0 commit comments

Comments
 (0)