File size: 1,540 Bytes
83a59ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package entities

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestUser_GetBillingAnchorDay_FreeUser(t *testing.T) {
	user := User{
		SubscriptionName: SubscriptionNameFree,
		CreatedAt:        time.Date(2026, 3, 20, 10, 0, 0, 0, time.UTC),
	}
	assert.Equal(t, 20, user.GetBillingAnchorDay())
}

func TestUser_GetBillingAnchorDay_EmptySubscription(t *testing.T) {
	user := User{
		SubscriptionName: "",
		CreatedAt:        time.Date(2026, 1, 5, 10, 0, 0, 0, time.UTC),
	}
	assert.Equal(t, 5, user.GetBillingAnchorDay())
}

func TestUser_GetBillingAnchorDay_PaidUser(t *testing.T) {
	renewsAt := time.Date(2026, 6, 15, 0, 0, 0, 0, time.UTC)
	user := User{
		SubscriptionName:     SubscriptionNameProMonthly,
		SubscriptionRenewsAt: &renewsAt,
		CreatedAt:            time.Date(2026, 1, 5, 10, 0, 0, 0, time.UTC),
	}
	assert.Equal(t, 15, user.GetBillingAnchorDay())
}

func TestUser_GetBillingAnchorDay_PaidUserNilRenewsAt(t *testing.T) {
	user := User{
		SubscriptionName:     SubscriptionNameProMonthly,
		SubscriptionRenewsAt: nil,
		CreatedAt:            time.Date(2026, 4, 28, 10, 0, 0, 0, time.UTC),
	}
	assert.Equal(t, 28, user.GetBillingAnchorDay())
}

func TestUser_GetBillingAnchorDay_PaidUserDay31(t *testing.T) {
	renewsAt := time.Date(2026, 1, 31, 0, 0, 0, 0, time.UTC)
	user := User{
		SubscriptionName:     SubscriptionNameUltraMonthly,
		SubscriptionRenewsAt: &renewsAt,
		CreatedAt:            time.Date(2025, 12, 1, 10, 0, 0, 0, time.UTC),
	}
	assert.Equal(t, 31, user.GetBillingAnchorDay())
}