Skip to content

Commit

Permalink
test: add/fix pgTap database tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Nov 25, 2020
1 parent 28544c6 commit e87541b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/test/unit/tables/reporting_year_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ select results_eq(
select lives_ok(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3000, now(), now(), now(), now(), now());
values (3000, now() + interval '20 years', now() + interval '21 years', now() + interval '20 years', now() + interval '20 years', now() + interval '21 years');
$$,
'ciip_administrator can insert data in reporting_year table'
);
Expand Down
71 changes: 71 additions & 0 deletions schema/test/unit/trigger_functions/protect_date_overlap_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(7);

select has_function(
'ggircs_portal_private', 'protect_date_overlap',
'Function protect_date_overlap should exist'
);

select lives_ok(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3000, '3000-01-01 00:00:00-08', '3000-12-31 23:59:59-08', '3001-06-01 00:00:00-07', '3001-04-01 14:49:54.191757-07', '3001-12-31 14:49:54.191757-08')
$$,
'trigger does not throw when no dates overlap with existing rows'
);

select throws_like(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3001, '3000-12-30 00:00:00-08', '3001-12-31 23:59:59-08', '3002-06-01 00:00:00-07', '3002-04-01 14:49:54.191757-07', '3002-12-30 14:49:54.191757-08')
$$,
'New date range entry overlaps%',
'Throws when application_start_date falls within another range'
);

select throws_like(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3001, '3001-01-01 00:00:00-08', '3000-12-30 23:59:59-08', '3002-06-01 00:00:00-07', '3002-04-01 14:49:54.191757-07', '3002-12-30 14:49:54.191757-08')
$$,
'New date range entry overlaps%',
'Throws when application_end_date falls within another range'
);

select throws_like(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3001, '3001-01-01 00:00:00-08', '3001-12-30 23:59:59-08', '3002-06-01 00:00:00-07', '3001-04-02 14:49:54.191757-07', '3002-12-30 14:49:54.191757-08')
$$,
'New date range entry overlaps%',
'Throws when application_open_time falls within another range'
);

select throws_like(
$$
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3001, '3001-01-01 00:00:00-08', '3001-12-30 23:59:59-08', '3002-06-01 00:00:00-07', '3002-04-01 14:49:54.191757-07', '3001-12-29 14:49:54.191757-08')
$$,
'New date range entry overlaps%',
'Throws when application_close_time falls within another range'
);

-- Create new valid entry
insert into ggircs_portal.reporting_year (reporting_year, reporting_period_start, reporting_period_end, swrs_deadline, application_open_time, application_close_time) overriding system value
values (3001, '3001-01-01 00:00:00-08', '3001-12-30 23:59:59-08', '3002-06-01 00:00:00-07', '3002-04-01 14:49:54.191757-07', '3002-12-31 14:49:54.191757-08');

select throws_like(
$$
update ggircs_portal.reporting_year set reporting_period_start='3000-01-02 00:00:00-08' where reporting_year=3001;
$$,
'New date range entry overlaps%',
'Trigger throws on update operation'
);

select finish();

rollback;

0 comments on commit e87541b

Please sign in to comment.