Skip to content

Commit

Permalink
Merge pull request #1570 from bcgov/refactor/apply-default-form-resul…
Browse files Browse the repository at this point in the history
…t-column

refactor: apply default form result column
  • Loading branch information
matthieu-foucault authored Mar 31, 2021
2 parents e024786 + 2a43553 commit 3e77152
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('When reviewing a submitted application as an analyst', () => {
// Production Form
cy.visit(productionFormUrl);
cy.get('div.card-header').contains('Form input saved');
cy.contains('Add a Product').click();
cy.contains('Continue').click();
cy.get('.rbt +div .error-detail').contains('is a required property');
cy.get('#root_0_productRowId').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ begin

else
-- Populate initial version of application form results with data from swrs or empty results
if ((select fj.name from ggircs_portal.form_json as fj where temp_row.form_id = fj.id) in ('Production', 'fuel')) then
form_result='[{}]';
else
form_result = '{}';
end if;
form_result = (select default_form_result from ggircs_portal.form_json fj where temp_row.form_id = fj.id);
if (select prepopulate_from_swrs from ggircs_portal.form_json where id = temp_row.form_id) then
select form_result_init_function from ggircs_portal.form_json where id = temp_row.form_id into init_function;
if (init_function is not null) then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(3);
select plan(4);

select has_function(
'ggircs_portal', 'create_application_mutation_chain', array['integer'],
Expand All @@ -30,6 +30,12 @@ select is(
'create_application_mutation_chain copies the report_id from the facility table to the application table'
);

select is(
(select form_result from ggircs_portal.form_result where application_id=1 and version_number=1 and form_id=1),
(select default_form_result from ggircs_portal.form_json where id=1),
'The initial empty form_result is derived from the form_json.default_form_result column'
);

-- Set the timestamp to a time where the application window is closed
-- 2020 open date minus one second
select mocks.set_mocked_time_in_transaction('2021-04-01 14:49:54.191757-07'::timestamptz - interval '1 second');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ short_name,
description,
form_json,
prepopulate_from_ciip,
prepopulate_from_swrs
prepopulate_from_swrs,
default_form_result
) values
('admin', 'admin-2018', 'admin', 'admin', '{}', false, false);
('admin', 'admin-2018', 'admin', 'admin', '{}', false, false, '{}');

insert into ggircs_portal.ciip_application_wizard(form_id, form_position, is_active)
values ((select id from ggircs_portal.form_json order by id desc limit 1), 0, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ insert into ggircs_portal.form_result(application_id, version_number, form_id, f
values
(1, 0, 1, '{}'),
(1, 0, 2, '{}'),
(1, 0, 3, '[{}]'),
(1, 0, 4, '[{}]'),
(1, 0, 3, '[]'),
(1, 0, 4, '[]'),
(3, 0, 1, '{}'),
(3, 0, 2, '{}'),
(3, 0, 3, '[{}]'),
(3, 0, 4, '[{}]'),
(3, 0, 3, '[]'),
(3, 0, 4, '[]'),
(4, 0, 1, '{}'),
(4, 0, 2, '{}'),
(4, 0, 3, '[{}]'),
(4, 0, 4, '[{}]');
(4, 0, 3, '[]'),
(4, 0, 4, '[]');


-- set different updated_at values for applications 1 & 2 (should update) / 3 & 4 (shouldn't update)
Expand Down Expand Up @@ -174,7 +174,7 @@ select is(

select is(
(select form_result from ggircs_portal.form_result where application_id=1 and version_number=0 and form_id=4),
'[{}]'::jsonb,
'[]'::jsonb,
'Refresh function did nothing to the production form for application 1'
);

Expand Down

0 comments on commit 3e77152

Please sign in to comment.