Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserSubscriptionDaysRemainingAt(t *testing.T) {
|
||||
now := time.Date(2026, time.July, 19, 12, 0, 0, 0, time.UTC)
|
||||
tests := []struct {
|
||||
name string
|
||||
expiresAt time.Time
|
||||
want int
|
||||
}{
|
||||
{name: "expired", expiresAt: now.Add(-time.Nanosecond), want: 0},
|
||||
{name: "expires now", expiresAt: now, want: 0},
|
||||
{name: "less than one day", expiresAt: now.Add(subscriptionDayDuration - time.Nanosecond), want: 1},
|
||||
{name: "exactly one day", expiresAt: now.Add(subscriptionDayDuration), want: 1},
|
||||
{name: "over one day", expiresAt: now.Add(subscriptionDayDuration + time.Nanosecond), want: 2},
|
||||
{name: "less than two days", expiresAt: now.Add(2*subscriptionDayDuration - time.Nanosecond), want: 2},
|
||||
{name: "exactly two days", expiresAt: now.Add(2 * subscriptionDayDuration), want: 2},
|
||||
{name: "over two days", expiresAt: now.Add(2*subscriptionDayDuration + time.Nanosecond), want: 3},
|
||||
{name: "exactly seven days", expiresAt: now.Add(7 * subscriptionDayDuration), want: 7},
|
||||
{name: "over seven days", expiresAt: now.Add(7*subscriptionDayDuration + time.Nanosecond), want: 8},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
sub := &UserSubscription{ExpiresAt: tt.expiresAt}
|
||||
require.Equal(t, tt.want, sub.daysRemainingAt(now))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user