2020-01-29 21:39:37 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package payments
|
|
|
|
|
|
|
|
import (
|
2021-08-25 20:35:57 +01:00
|
|
|
"fmt"
|
2020-01-29 21:39:37 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-05-13 18:02:51 +01:00
|
|
|
func TestCoupon_ExpirationDate(t *testing.T) {
|
2021-08-25 20:35:57 +01:00
|
|
|
for i, tt := range []struct {
|
2020-01-29 21:39:37 +00:00
|
|
|
created time.Time
|
2020-05-13 18:02:51 +01:00
|
|
|
duration int
|
|
|
|
expires time.Time
|
2020-01-29 21:39:37 +00:00
|
|
|
}{
|
2020-05-13 18:02:51 +01:00
|
|
|
{
|
|
|
|
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
|
2021-08-25 20:35:57 +01:00
|
|
|
expires: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), // 2020-02-01 00:00:00 +0000 UTC
|
2020-05-13 18:02:51 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
2021-08-25 20:35:57 +01:00
|
|
|
expires: time.Date(2020, 4, 1, 0, 0, 0, 0, time.UTC), // 2020-04-01 00:00:00 +0000 UTC
|
2020-05-13 18:02:51 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
2021-08-25 20:35:57 +01:00
|
|
|
expires: time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), // 2020-05-01 00:00:00 +0000 UTC
|
2020-05-13 18:02:51 +01:00
|
|
|
},
|
|
|
|
} {
|
2021-08-06 21:14:33 +01:00
|
|
|
coupon := CouponOld{
|
2021-03-30 00:37:46 +01:00
|
|
|
Duration: &tt.duration,
|
2020-05-13 18:02:51 +01:00
|
|
|
Created: tt.created,
|
2020-01-29 21:39:37 +00:00
|
|
|
}
|
2021-03-30 00:37:46 +01:00
|
|
|
expirationDate := coupon.ExpirationDate()
|
|
|
|
require.NotNil(t, expirationDate)
|
2021-08-25 20:35:57 +01:00
|
|
|
require.Equal(t, tt.expires, *expirationDate, fmt.Sprint(i), expirationDate.String())
|
2020-01-29 21:39:37 +00:00
|
|
|
}
|
|
|
|
}
|