stripecoinpayments: use fixed date for test

the test as written fails if it's the last day of the month because
the two tallies that are added span two different periods.

Change-Id: I294397278508035ce640500fc3b1b0ffd82b9b71
This commit is contained in:
Jeff Wendling 2020-05-30 11:38:15 -06:00 committed by Michal Niewrzal
parent f6452e9c09
commit 839a6f15d1

View File

@ -36,6 +36,10 @@ func TestService_InvoiceElementsProcessing(t *testing.T) {
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0] satellite := planet.Satellites[0]
// pick a specific date so that it doesn't fail if it's the last day of the month
// keep month + 1 because user needs to be created before calculation
period := time.Date(2020, time.Now().Month()+1, 20, 0, 0, 0, 0, time.UTC)
numberOfProjects := 19 numberOfProjects := 19
// generate test data, each user has one project, one coupon and some credits // generate test data, each user has one project, one coupon and some credits
for i := 0; i < numberOfProjects; i++ { for i := 0; i < numberOfProjects; i++ {
@ -54,11 +58,10 @@ func TestService_InvoiceElementsProcessing(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
err = satellite.DB.Orders().UpdateBucketBandwidthSettle(ctx, project.ID, []byte("testbucket"), err = satellite.DB.Orders().UpdateBucketBandwidthSettle(ctx, project.ID, []byte("testbucket"),
pb.PieceAction_GET, int64(i+10)*memory.GiB.Int64(), time.Now()) pb.PieceAction_GET, int64(i+10)*memory.GiB.Int64(), period)
require.NoError(t, err) require.NoError(t, err)
} }
period := time.Now()
satellite.API.Payments.Service.SetNow(func() time.Time { satellite.API.Payments.Service.SetNow(func() time.Time {
return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC) return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC)
}) })
@ -121,7 +124,10 @@ func TestService_InvoiceUserWithManyProjects(t *testing.T) {
satellite := planet.Satellites[0] satellite := planet.Satellites[0]
payments := satellite.API.Payments payments := satellite.API.Payments
period := time.Now() // pick a specific date so that it doesn't fail if it's the last day of the month
// keep month + 1 because user needs to be created before calculation
period := time.Date(2020, time.Now().Month()+1, 20, 0, 0, 0, 0, time.UTC)
payments.Service.SetNow(func() time.Time { payments.Service.SetNow(func() time.Time {
return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC) return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC)
}) })
@ -219,7 +225,10 @@ func TestService_InvoiceUserWithManyCoupons(t *testing.T) {
satellite := planet.Satellites[0] satellite := planet.Satellites[0]
paymentsAPI := satellite.API.Payments paymentsAPI := satellite.API.Payments
period := time.Now() // pick a specific date so that it doesn't fail if it's the last day of the month
// keep month + 1 because user needs to be created before calculation
period := time.Date(2020, time.Now().Month()+1, 20, 0, 0, 0, 0, time.UTC)
paymentsAPI.Service.SetNow(func() time.Time { paymentsAPI.Service.SetNow(func() time.Time {
return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC) return time.Date(period.Year(), period.Month()+1, 1, 0, 0, 0, 0, time.UTC)
}) })