From 4e9e25224ffa19040bb8cbc7ec80773616779b1e Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Thu, 16 Nov 2023 16:00:49 -0800 Subject: [PATCH] test: initial tests for concurrent revisions merging --- .../mutations/commit_form_change_internal.sql | 2 +- .../commit_project_revision_test.sql | 99 ++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/schema/deploy/mutations/commit_form_change_internal.sql b/schema/deploy/mutations/commit_form_change_internal.sql index eaabad0d50..1c0d40ca91 100644 --- a/schema/deploy/mutations/commit_form_change_internal.sql +++ b/schema/deploy/mutations/commit_form_change_internal.sql @@ -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 diff --git a/schema/test/unit/mutations/commit_project_revision_test.sql b/schema/test/unit/mutations/commit_project_revision_test.sql index 6d4293f7d3..4fe817e1e7 100644 --- a/schema/test/unit/mutations/commit_project_revision_test.sql +++ b/schema/test/unit/mutations/commit_project_revision_test.sql @@ -1,6 +1,6 @@ begin; -select plan(9); +select plan(13); /** BEGIN SETUP **/ truncate table @@ -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); @@ -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;