feat(billing): Fix end time comparision for all view
This commit is contained in:
4 files changed
+18
-9
No files matched your search
@@ -122,14 +122,18 @@ func TestRepository_MonthlyActiveUsers(t *testing.T) {
|
||||
repo := TestRepo(t, conn)
|
||||
activeUsers, err := repo.MonthlyActiveUsers(ctx, WithStartTime(&threeMonthsAgo), WithEndTime(&oneMonthAgo))
|
||||
assert.NoError(t, err)
|
||||
// since the end time is exclusive, we should only get one record of active users
|
||||
// for the month of three months ago
|
||||
expectedStartTime := time.Date(today.AddDate(0, -3, 0).Year(), today.AddDate(0, -3, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
expectedEndTime := time.Date(today.AddDate(0, -2, 0).Year(), today.AddDate(0, -2, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
require.Len(t, activeUsers, 1)
|
||||
require.Len(t, activeUsers, 2)
|
||||
expectedStartTime := time.Date(today.AddDate(0, -2, 0).Year(), today.AddDate(0, -2, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
expectedEndTime := time.Date(today.AddDate(0, -1, 0).Year(), today.AddDate(0, -1, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
require.Equal(t, uint64(6), activeUsers[0].ActiveUsersCount)
|
||||
assert.Equal(t, expectedStartTime, activeUsers[0].StartTime)
|
||||
assert.Equal(t, expectedEndTime, activeUsers[0].EndTime)
|
||||
|
||||
expectedStartTime = time.Date(today.AddDate(0, -3, 0).Year(), today.AddDate(0, -3, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
expectedEndTime = time.Date(today.AddDate(0, -2, 0).Year(), today.AddDate(0, -2, 0).Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
require.Equal(t, uint64(6), activeUsers[1].ActiveUsersCount)
|
||||
assert.Equal(t, expectedStartTime, activeUsers[1].StartTime)
|
||||
assert.Equal(t, expectedEndTime, activeUsers[1].EndTime)
|
||||
})
|
||||
|
||||
t.Run("invalid-end-time-without-start-time", func(t *testing.T) {
|
||||
|
||||
@@ -102,6 +102,11 @@ func Test_MonthlyActiveUsers(t *testing.T) {
|
||||
req: &pbs.MonthlyActiveUsersRequest{StartTime: threeMonthsAgo, EndTime: oneMonthAgo},
|
||||
res: &pbs.MonthlyActiveUsersResponse{
|
||||
Items: []*pb.ActiveUsers{
|
||||
{
|
||||
Count: 6,
|
||||
StartTime: timestamppb.New(time.Date(today.Year(), today.Month()-2, 1, 0, 0, 0, 0, time.UTC)),
|
||||
EndTime: timestamppb.New(time.Date(today.Year(), today.Month()-1, 1, 0, 0, 0, 0, time.UTC)),
|
||||
},
|
||||
{
|
||||
Count: 6,
|
||||
StartTime: timestamppb.New(time.Date(today.Year(), today.Month()-3, 1, 0, 0, 0, 0, time.UTC)),
|
||||
|
||||
@@ -92,7 +92,7 @@ begin;
|
||||
return query select *
|
||||
from hcp_billing_monthly_active_users_all
|
||||
where start_time >= p_start_time
|
||||
and end_time < p_end_time;
|
||||
and end_time <= p_end_time;
|
||||
when p_start_time is not null then
|
||||
return query select *
|
||||
from hcp_billing_monthly_active_users_all
|
||||
@@ -100,7 +100,7 @@ begin;
|
||||
when p_end_time is not null then
|
||||
return query select *
|
||||
from hcp_billing_monthly_active_users_all
|
||||
where end_time < p_end_time;
|
||||
where end_time <= p_end_time;
|
||||
else
|
||||
return query select *
|
||||
from hcp_billing_monthly_active_users_all;
|
||||
|
||||
@@ -144,7 +144,7 @@ begin;
|
||||
select results_eq(
|
||||
$$
|
||||
select * from hcp_billing_monthly_active_users_all(date_trunc('month', now() - interval '5 month', 'utc'),
|
||||
date_trunc('month', now() - interval '2 month', 'utc'));
|
||||
date_trunc('month', now() - interval '3 month', 'utc'));
|
||||
$$,
|
||||
$$
|
||||
values (date_trunc('month', now() - interval '4 month', 'utc'), date_trunc('month', now() - interval '3 month', 'utc'), 6::bigint),
|
||||
@@ -154,7 +154,7 @@ begin;
|
||||
select results_eq(
|
||||
$$
|
||||
select * from hcp_billing_monthly_active_users_all(null,
|
||||
date_trunc('month', now() - interval '2 month', 'utc'));
|
||||
date_trunc('month', now() - interval '3 month', 'utc'));
|
||||
$$,
|
||||
$$
|
||||
values (date_trunc('month', now() - interval '4 month', 'utc'), date_trunc('month', now() - interval '3 month', 'utc'), 6::bigint),
|
||||
|
||||
Reference in new issue
Block a user