Skip to content

Commit

Permalink
test: test that attachments are handled correctly when concurrent rev…
Browse files Browse the repository at this point in the history
…isions are committed
  • Loading branch information
mikevespi committed Nov 28, 2023
1 parent 1644562 commit 85e1f39
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions schema/test/unit/mutations/commit_form_change_internal_test.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
begin;

select plan(13);
select plan(15);

/** SETUP **/
truncate cif.form_change restart identity;
Expand Down Expand Up @@ -80,9 +80,11 @@ select is(

-- Test the concurrent revision functinality

truncate table cif.project, cif.operator, cif.contact restart identity cascade;
truncate table cif.project, cif.operator, cif.contact, cif.attachment 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');
insert into cif.attachment (description, file_name, file_type, file_size)
values ('description1', 'file_name1', 'file_type1', 100);

select cif.create_project(1); -- id = 1
update cif.form_change set new_form_data='{
Expand Down Expand Up @@ -123,6 +125,7 @@ update cif.form_change set new_form_data='{
and form_data_table_name='project';

select cif.add_contact_to_revision(3, 1, 1);
select cif.add_project_attachment_to_revision(3,1);

select cif.commit_project_revision(3);

Expand All @@ -148,7 +151,13 @@ select is (
select is (
(select new_form_data from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project_contact'),
'{"contactId": 1, "projectId": 1, "contactIndex": 1}'::jsonb,
'When the committing form change has an operation create, the resource also gets created in the pending revision'
'When the committing form change is creating a project contact, the contact also gets created in the pending revision'
);

select is (
(select count(*) from cif.form_change where project_revision_id = 2 and form_data_table_name = 'project_attachment'),
1::bigint,
'When the committing form change is creating a project attachment, the attachment also gets created in the pending revision'
);

-- Commit the ammednment
Expand Down Expand Up @@ -178,14 +187,22 @@ update cif.form_change set new_form_data='{
where project_revision_id=5
and form_data_table_name='project';

select cif.discard_project_attachment_form_change((select id from cif.form_change where project_revision_id = 5 and form_data_table_name = 'project_attachment'));

select cif.commit_project_revision(5);

select is (
(select new_form_data->>'projectName' from cif.form_change where id = 6),
(select new_form_data->>'projectName' from cif.form_change where id = 8),
'Correct only newer',
'The pending form change should have the value from the committing form change'
);

select is (
(select count(*) from cif.form_change where project_revision_id = 4 and form_data_table_name = 'project_attachment'),
0::bigint,
'When the committing form change is discarding a project attachment, the pending fc is deleted.'
);

select cif.commit_project_revision(4);
select is (
(select project_name from cif.project where id = 1),
Expand Down

0 comments on commit 85e1f39

Please sign in to comment.