From 0459c782121ef643f21b9ef5bdced614f1d999cd Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Wed, 6 Dec 2023 21:43:50 -0800 Subject: [PATCH] test: cleanup assertions and add testing for creating a funding agreement --- .../commit_form_change_internal_test.sql | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 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 650c393d69..a482b8f3a4 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(19); +select plan(21); /** SETUP **/ truncate cif.form_change restart identity; @@ -126,10 +126,29 @@ update cif.form_change set new_form_data='{ select cif.add_contact_to_revision(3, 1, 1); select cif.add_project_attachment_to_revision(3,1); +select cif.create_form_change( + 'create', + 'funding_parameter_EP', + 'cif', + 'funding_parameter', + json_build_object( + 'projectId', 1, + 'provinceSharePercentage', 50, + 'holdbackPercentage', 10, + 'maxFundingAmount', 1, + 'anticipatedFundingAmount', 1, + 'proponentCost',777, + 'contractStartDate', '2022-03-01 16:21:42.693489-07', + 'projectAssetsLifeEndDate', '2022-03-01 16:21:42.693489-07' + )::jsonb, + null, + 3 + ); select cif.commit_project_revision(3); --- Both committing and pending project revisions have made changes to the project form. +-- Test when both committing and pending project revisions have made changes to the project form, +-- and creates of new records in committing that do not exist in pending yet. select is ( (select new_form_data->>'projectName' from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project'), 'Correct', @@ -169,13 +188,13 @@ select is ( select is ( (select form_data_record_id from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project_attachment'), - 1::int, + (select form_data_record_id from cif.form_change where project_revision_id = 3 and form_data_table_name = 'project_attachment'), 'When committing has an operation of create, the form_data_record_id propogates to the pending form change for attachments' ); select is ( (select form_data_record_id from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project_contact'), - 1::int, + (select form_data_record_id from cif.form_change where project_revision_id = 3 and form_data_table_name = 'project_contact'), 'When committing has an operation of create, the form_data_record_id propogates to the pending form change for contacts' ); @@ -185,6 +204,18 @@ select is ( 'When the committing form change is creating a project attachment, the attachment also gets created in the pending revision' ); +select is ( + (select form_data_record_id from cif.form_change where project_revision_id = 2 and form_data_table_name = 'funding_parameter_EP'), + (select form_data_record_id from cif.form_change where project_revision_id = 3 and form_data_table_name = 'funding_parameter_EP'), + 'When committing has an operation of create, the form_data_record_id propogates to the pending form change for funding parameter form' +); + +select is ( + (select new_form_data from cif.form_change where project_revision_id = 2 and form_data_table_name = 'funding_parameter_EP'), + (select new_form_data from cif.form_change where project_revision_id = 3 and form_data_table_name = 'funding_parameter_EP'), + 'When committing has an operation of create, the form_data_record_id propogates to the pending form change for funding parameter form' +); + -- Commit the ammednment select cif.commit_project_revision(2); @@ -198,7 +229,8 @@ select results_eq ( 'After committing the pending form change, the project table has all of the correct values' ); --- Test when committing has made changes to the form but the pending has not +-- Test when committing has made changes to the form but the pending has not, +-- and deleting a project attachment in the committing form change select cif.create_project_revision(1, 'Amendment'); -- id = 4 select cif.create_project_revision(1, 'General Revision'); -- id = 5 update cif.form_change set new_form_data='{ @@ -217,7 +249,7 @@ select cif.discard_project_attachment_form_change((select id from cif.form_chang select cif.commit_project_revision(5); select is ( - (select new_form_data->>'projectName' from cif.form_change where id = 8), + (select new_form_data->>'projectName' from cif.form_change where project_revision_id = 4 and form_data_table_name = 'project'), 'Correct only newer', 'The pending form change should have the value from the committing form change' );