storj/satellite/payments/coupons_test.go
Yingrong Zhao 5304f672ad satellite/payments: fix invoice generation to include the last day of
the month

The Stripe API had a bug before that it wasn't calcualting the input
timestamp based on correct timezone. We had a workaround to not include
the last day of the month in our code when submitting to Stripe.
Now, Stripe has fixed the issue. We need to remove the workaround and
include the last day of the month into our invoice generation

Change-Id: Ic6364ed071be73a19f0b0b46f274a02fb2489db5
2021-08-31 16:25:18 +00:00

45 lines
1.4 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package payments
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestCoupon_ExpirationDate(t *testing.T) {
for i, tt := range []struct {
created time.Time
duration int
expires time.Time
}{
{
created: time.Date(2020, 1, 30, 0, 0, 0, 0, time.UTC), // 2020-01-30 00:00:00 +0000 UTC
duration: 0, // sign-up month only
expires: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), // 2020-02-01 00:00:00 +0000 UTC
},
{
created: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), // 2020-02-01 00:00:00 +0000 UTC
duration: 1, // sign-up month + 1 full month
expires: time.Date(2020, 4, 1, 0, 0, 0, 0, time.UTC), // 2020-04-01 00:00:00 +0000 UTC
},
{
created: time.Date(2020, 2, 5, 8, 0, 0, 0, time.UTC), // 2020-02-05 08:00:00 +0000 UTC
duration: 2, // sign-up month + 2 full months
expires: time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), // 2020-05-01 00:00:00 +0000 UTC
},
} {
coupon := CouponOld{
Duration: &tt.duration,
Created: tt.created,
}
expirationDate := coupon.ExpirationDate()
require.NotNil(t, expirationDate)
require.Equal(t, tt.expires, *expirationDate, fmt.Sprint(i), expirationDate.String())
}
}