Fix sql tests failing on the first of the month (#3042)

* initial commit
This commit is contained in:
Irena Rindos authored and GitHub committed 2023-03-01 19:14:57 -05:00
1 parent 236d7ca872
commit 860af44556
1 file changed
+23 -3
@@ -107,6 +107,16 @@ begin;
end;
$$ language plpgsql;
create function test_is_not_same_month(start_time timestamptz, end_time timestamptz) returns boolean
as $$
begin
if date_trunc('month', start_time) != date_trunc('month', end_time) then
return TRUE;
end if;
return FALSE;
end;
$$ language plpgsql;
prepare select_hcp_billing_monthly_sessions_all as
select *
from hcp_billing_monthly_sessions_all;
@@ -153,10 +163,20 @@ begin;
'hcp billing: test_setup_data: should be 48 sessions for yesterday');
select is(count(*), 1::bigint,
'hcp_billing_monthly_sessions_all should return 1 row when there are only sessions in this month') from hcp_billing_monthly_sessions_all;
select row_eq('select_hcp_billing_monthly_sessions_all', row(date_trunc('month', now()), date_trunc('hour', now()), 48::bigint),
select row_eq('select_hcp_billing_monthly_sessions_all', row(date_trunc('month', 'yesterday'::timestamptz), date_trunc('day', now()), 48::bigint),
'hcp_billing_monthly_sessions_all should have 1 row with 48 sessions_pending_count when there are only sessions for yesterday');
select results_eq('select_hcp_billing_monthly_sessions_current_month', 'select_hcp_billing_monthly_sessions_all',
'hcp_billing_monthly_sessions_current_month and hcp_billing_monthly_sessions_all should be equal');
-- On the first day of the month, the data will exist in the prior month, in which case we want to test for an inequality
-- between the current month and all months
select case when test_is_not_same_month('yesterday'::timestamptz, now())
then collect_tap(
results_ne('select_hcp_billing_monthly_sessions_current_month', 'select_hcp_billing_monthly_sessions_all',
'hcp_billing_monthly_sessions_current_month and hcp_billing_monthly_sessions_all should NOT be equal')
)
else collect_tap(
results_eq('select_hcp_billing_monthly_sessions_current_month', 'select_hcp_billing_monthly_sessions_all',
'hcp_billing_monthly_sessions_current_month and hcp_billing_monthly_sessions_all should be equal')
)
end;
select results_eq('select_hcp_billing_monthly_sessions_current_month', 'select_hcp_billing_monthly_sessions_last_2_months_1_row',
'hcp_billing_monthly_sessions_current_month and the first row of hcp_billing_monthly_sessions_last_2_months should be equal');