From c2b173f65343e9a57a0d52d74f3ff84d9c8b912a Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Fri, 17 Nov 2023 17:44:46 -0800 Subject: [PATCH] test: test the updates of the simple forms in commit_form_change_internal --- .../commit_form_change_internal_test.sql | 81 ++++++++++++++++++- .../commit_project_revision_test.sql | 1 - 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/schema/test/unit/mutations/commit_form_change_internal_test.sql b/schema/test/unit/mutations/commit_form_change_internal_test.sql index 3fa3a42583..aaad949fc2 100644 --- a/schema/test/unit/mutations/commit_form_change_internal_test.sql +++ b/schema/test/unit/mutations/commit_form_change_internal_test.sql @@ -1,6 +1,6 @@ begin; -select plan(6); +select plan(10); /** SETUP **/ truncate cif.form_change restart identity; @@ -77,7 +77,84 @@ select is( 'The form_change status should be committed' ); --- Calls the proper function set in the form table + +-- Test the concurrent revision functinality + +truncate table cif.project, cif.operator restart identity cascade; +insert into cif.operator(legal_name) values ('test operator'); +insert into cif.contact(given_name, family_name, email) values ('John', 'Test', 'foo@abc.com'); + +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'; + +select cif.commit_project_revision(3); + +select is ( + (select new_form_data->>'projectName' from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project'), + 'Correct', + 'When both the committing and pending form changes have changed the same field, the value from the pending should persist' +); + +select is ( + (select project_name from cif.project where id = 1), + 'Incorrect', + 'The project receives the value from the committing form change' +); + +select is ( + (select new_form_data->>'summary' from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project'), + 'Correct', + 'When the commiting form change has updated a field that the pending has not, it updates the pending form change' +); + +-- Commit the ammednment +select cif.commit_project_revision(2); + +select results_eq ( + $$ + (select project_name, summary, funding_stream_rfp_id, project_status_id, proposal_reference, operator_id from cif.project where id = 1) + $$, + $$ + values('Correct'::varchar, 'Correct'::varchar, 1::int, 1::int, '1235'::varchar, 1::int) + $$, + 'After committing the pending form change, the project table has all of the correct values' +); + select finish(); diff --git a/schema/test/unit/mutations/commit_project_revision_test.sql b/schema/test/unit/mutations/commit_project_revision_test.sql index 4fe817e1e7..3021fd3939 100644 --- a/schema/test/unit/mutations/commit_project_revision_test.sql +++ b/schema/test/unit/mutations/commit_project_revision_test.sql @@ -24,7 +24,6 @@ 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);