From 8d6ac651605b94ce59290ed9e05ab511e780c4f8 Mon Sep 17 00:00:00 2001 From: Dmitry Ng <19asdek91@gmail.com> Date: Sun, 29 Mar 2026 16:35:39 +0300 Subject: [PATCH] fix: correct license validity and expiration logic in tests and implementation --- sdk/license.go | 2 +- sdk/license_test.go | 12 ++++++------ sdk/testdata/data.json | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/license.go b/sdk/license.go index b4c37b5..cd67e8f 100644 --- a/sdk/license.go +++ b/sdk/license.go @@ -61,7 +61,7 @@ func (l *LicenseInfo) IsValid() bool { } func (l *LicenseInfo) IsExpired() bool { - return l.Type == LicenseExpireable && l.ExpiredAt.After(alignDays(time.Now().UTC())) + return l.Type == LicenseExpireable && l.ExpiredAt.Before(alignDays(time.Now().UTC())) } type licenseData struct { diff --git a/sdk/license_test.go b/sdk/license_test.go index aed6527..571d6b0 100644 --- a/sdk/license_test.go +++ b/sdk/license_test.go @@ -391,8 +391,8 @@ func TestLicenseInfoMethods(t *testing.T) { ExpiredAt: yesterday, // past date CreatedAt: now.AddDate(0, 0, -10), }, - expectedValid: true, // not expired per client logic - expectedExpired: false, // .After(now) is false for yesterday + expectedValid: false, // expired license is not valid + expectedExpired: true, // .Before(now) is true for yesterday }, { name: "expireable_expires_tomorrow", @@ -402,8 +402,8 @@ func TestLicenseInfoMethods(t *testing.T) { ExpiredAt: tomorrow, CreatedAt: yesterday, }, - expectedValid: false, // !IsExpired() will be false since tomorrow.After(now) = true - expectedExpired: true, // tomorrow.After(now) = true + expectedValid: true, // not expired yet, still valid + expectedExpired: false, // tomorrow.Before(now) = false }, { name: "invalid_perpetual_with_expiry", @@ -425,7 +425,7 @@ func TestLicenseInfoMethods(t *testing.T) { CreatedAt: tomorrow, // future creation date }, expectedValid: false, // fails future CreatedAt check - expectedExpired: true, // future ExpiredAt.After(now) = true + expectedExpired: false, // ExpiredAt.Before(now) = false }, { name: "invalid_zero_created_at", @@ -436,7 +436,7 @@ func TestLicenseInfoMethods(t *testing.T) { CreatedAt: time.Time{}, // zero time }, expectedValid: false, // fails zero CreatedAt check - expectedExpired: true, // tomorrow.After(now) = true + expectedExpired: false, // tomorrow.Before(now) = false }, } diff --git a/sdk/testdata/data.json b/sdk/testdata/data.json index 7b8913e..4c0d160 100644 --- a/sdk/testdata/data.json +++ b/sdk/testdata/data.json @@ -61,7 +61,7 @@ ], "expired_at": "2035-01-01T00:00:00Z", "created_at": "2025-09-16T00:00:00Z", - "valid": false + "valid": true }, { "name": "invalid_expired", @@ -78,7 +78,7 @@ ], "expired_at": "2025-06-16T00:00:00Z", "created_at": "2025-06-15T00:00:00Z", - "valid": true + "valid": false }, { "name": "invalid_future_created_at",