Skip to content

Commit

Permalink
test: initial tests for concurrent revisions merging
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevespi committed Nov 17, 2023
1 parent 1d9e70e commit 4e9e252
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion schema/deploy/mutations/commit_form_change_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ begin
new_form_data => fc.new_form_data
);
elsif fc.operation = 'update' then
-- store the other pending project revisions corresponding form_change, and its parent
-- store the pending project revisions corresponding form_change, and its parent
select * into pending_form_change from cif.form_change
where project_revision_id = pending_project_revision_id
and form_data_table_name = fc.form_data_table_name
Expand Down
99 changes: 98 additions & 1 deletion schema/test/unit/mutations/commit_project_revision_test.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
begin;

select plan(9);
select plan(13);

/** BEGIN SETUP **/
truncate table
Expand All @@ -24,6 +24,7 @@ restart identity;

insert into cif.operator(legal_name) values ('test operator');
insert into cif.contact(given_name, family_name, email) values ('John', 'Test', 'foo@abc.com');
insert into cif.contact(given_name, family_name, email) values ('Mira', 'Test', 'bar@abc.com');

select cif.create_project(1);

Expand Down Expand Up @@ -210,6 +211,102 @@ select results_eq(
'commit_project_revision sets revision_status to Applied when revision_type is General Revision'
);

-- Test the concurrent revision functinality

truncate cif.project restart identity cascade;

select cif.create_project(1); -- id = 1
update cif.form_change set new_form_data='{
"projectName": "name",
"summary": "original (incorrect at point of test)",
"fundingStreamRfpId": 1,
"projectStatusId": 1,
"proposalReference": "1235",
"operatorId": 1
}'::jsonb
where project_revision_id=1
and form_data_table_name='project';
select cif.commit_project_revision(1);


select cif.create_project_revision(1, 'Amendment'); -- id = 2
update cif.form_change set new_form_data='{
"projectName": "Correct",
"summary": "original (incorrect at point of test)",
"fundingStreamRfpId": 1,
"projectStatusId": 1,
"proposalReference": "1235",
"operatorId": 1
}'::jsonb
where project_revision_id=2
and form_data_table_name='project';

select cif.create_project_revision(1, 'General Revision'); -- id = 3
update cif.form_change set new_form_data='{
"projectName": "Incorrect",
"summary": "Correct",
"fundingStreamRfpId": 1,
"projectStatusId": 1,
"proposalReference": "1235",
"operatorId": 1
}'::jsonb
where project_revision_id=3
and form_data_table_name='project';

insert into cif.form_change(
new_form_data,
operation,
form_data_schema_name,
form_data_table_name,
json_schema_name,
project_revision_id
)
values
(
json_build_object(
'projectId', 1,
'contactId', 1,
'contactIndex', 1
),
'create', 'cif', 'project_contact', 'project_contact', 3
);

select lives_ok (
$$
select cif.commit_project_revision(3)
$$,
'The General Revision successfully commits while there is a pending Amendment on the project'
);

select lives_ok (
$$
select cif.commit_project_revision(2)
$$,
'The Amendment successfully commits after a General Revision being committed while the Amendment was pending'
);

select is (
(select new_form_data from cif.form_change where
project_revision_id=2
and form_data_table_name='project'),
'{
"projectName": "Correct",
"summary": "Correct",
"fundingStreamRfpId": 1,
"projectStatusId": 1,
"proposalReference": "1235",
"operatorId": 1
}'::jsonb,
'The project form_change has the correct data after the Amendment is committed'
);

select isnt_empty (
$$
select id from cif.project_contact where project_id=1;
$$,
'The project_contact added in the General Revision was succesfully added after the Amendment was committed'
);

select finish();

rollback;

0 comments on commit 4e9e252

Please sign in to comment.