-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
schema/test/unit/trigger_functions/protect_date_overlap_test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |