Skip to content

Commit

Permalink
test: add pgTap tests for new energy product validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 5, 2020
1 parent 0081256 commit c8b6db1
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
product_data ggircs_portal.product;
product_return ggircs_portal.ciip_incentive_by_product;
non_energy_product_count integer;
has_products boolean;

begin

Expand All @@ -51,8 +52,12 @@ returns setof ggircs_portal.ciip_incentive_by_product as $function$
and application_id = application_revision.application_id
);

has_products := (select product_id from ggircs_portal.ciip_production where
version_number = application_revision.version_number
and application_id = application_revision.application_id limit 1) is not null;

-- Validate that application is not missing any required energy products
if (select array_length(reported_products, 1)) > 0 and (select reported_products[0].product_id) is not null then
if has_products=true then
perform ggircs_portal_private.validate_energy_products(reported_products);
end if;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ create or replace function ggircs_portal_private.validate_energy_products(
when (product_data.add_emissions_from_eios and (select not 7 = any (product_ids))) then
raise exception 'Reported product requires emissions_from_eios to be reported, but emissions_from_eios is missing';
else
select true;
return;
end case;

end loop;
return;
end;

$function$ language 'plpgsql' stable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ insert into ggircs_portal.product (
)
overriding system value
values
(1, 'Purchased electricity', 'published',
true, false, true, false, false, false, false, false, false, false, true),
(2, 'Exported electricity', 'published',
(1, 'Exported electricity', 'published',
true, true, true, false, false, false, false, false, false, false, true),
(3, 'Purchased heat', 'published',
(3, 'Purchased electricity', 'published',
true, false, true, false, false, false, false, false, false, false, true),
(4, 'Exported heat', 'published',
(2, 'Exported heat', 'published',
true, true, true, false, false, false, false, false, false, false, true),
(4, 'Purchased heat', 'published',
true, false, true, false, false, false, false, false, false, false, true),
(5, 'Electricity generated on site', 'published',
true, false, true, false, false, false, false, false, false, false, true),
(6, 'Heat generated on site', 'published',
Expand Down Expand Up @@ -236,7 +236,7 @@ set form_result = '[
"productAmount": 100
},
{
"productRowId": 1,
"productRowId": 3,
"productAmount": 42,
"productEmissions": 11
}
Expand All @@ -258,15 +258,39 @@ select is(
'purchased electricity emissions are added to the facility emissions for products that require it'
);

-- Report a product with no allocation of emissions which requires "Purchased Heat" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 12,
"productAmount": 100
}
]'
where application_id = 1 and version_number = 1 and form_id = 4;

select throws_like(
$$

with record as (
select row(application_revision.*)::ggircs_portal.application_revision
from ggircs_portal.application_revision where application_id = 1 and version_number = 1
)
select * from ggircs_portal.application_revision_ciip_incentive(
(select * from record)
)
$$,
'%Reported product requires purchased_electricity%',
'throws an exception if a product requires purchased electricity and it is not present'
);

-- Report a product with no allocation of emissions which requires "Exported Electricity" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 13,
"productAmount": 100
},
{
"productRowId": 2,
"productRowId": 1,
"productAmount": 42,
"productEmissions": 12
}
Expand All @@ -288,15 +312,39 @@ select is(
'exported electricity emissions are added to the facility emissions for products that require it'
);

-- Report a product with no allocation of emissions which requires "Exported Electricity" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 13,
"productAmount": 100
}
]'
where application_id = 1 and version_number = 1 and form_id = 4;

select throws_like(
$$

with record as (
select row(application_revision.*)::ggircs_portal.application_revision
from ggircs_portal.application_revision where application_id = 1 and version_number = 1
)
select * from ggircs_portal.application_revision_ciip_incentive(
(select * from record)
)
$$,
'%Reported product requires exported_electricity%',
'throws an exception if a product requires exported electricity and it is not present'
);

-- Report a product with no allocation of emissions which requires "Purchased Heat" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 14,
"productAmount": 100
},
{
"productRowId": 3,
"productRowId": 4,
"productAmount": 42,
"productEmissions": 13
}
Expand All @@ -318,15 +366,39 @@ select is(
'purchased heat emissions are removed from the facility emissions for products that require it'
);

-- Report a product with no allocation of emissions which requires "Expported Heat" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 14,
"productAmount": 100
}
]'
where application_id = 1 and version_number = 1 and form_id = 4;

select throws_like(
$$

with record as (
select row(application_revision.*)::ggircs_portal.application_revision
from ggircs_portal.application_revision where application_id = 1 and version_number = 1
)
select * from ggircs_portal.application_revision_ciip_incentive(
(select * from record)
)
$$,
'%Reported product requires purchased_heat%',
'throws an exception if a product requires purchased heat and it is not present'
);

-- Report a product with no allocation of emissions which requires "Exported Heat" to be reported
update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 15,
"productAmount": 100
},
{
"productRowId": 4,
"productRowId": 2,
"productAmount": 42,
"productEmissions": 14
}
Expand All @@ -348,6 +420,30 @@ select is(
'exported heat emissions are removed from the facility emissions for products that require it'
);

update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 15,
"productAmount": 100
}
]'
where application_id = 1 and version_number = 1 and form_id = 4;

select throws_like(
$$

with record as (
select row(application_revision.*)::ggircs_portal.application_revision
from ggircs_portal.application_revision where application_id = 1 and version_number = 1
)
select * from ggircs_portal.application_revision_ciip_incentive(
(select * from record)
)
$$,
'%Reported product requires exported_heat%',
'throws an exception if a product requires exported heat and it is not present'
);

-- Report a product with no allocation of emissions which requires "EIO Emissions" to be reported
update ggircs_portal.form_result
set form_result = '[
Expand Down Expand Up @@ -378,6 +474,30 @@ select is(
'EIO Emissions are added to the facility emissions for products that require it'
);

update ggircs_portal.form_result
set form_result = '[
{
"productRowId": 18,
"productAmount": 100
}
]'
where application_id = 1 and version_number = 1 and form_id = 4;

select throws_like(
$$

with record as (
select row(application_revision.*)::ggircs_portal.application_revision
from ggircs_portal.application_revision where application_id = 1 and version_number = 1
)
select * from ggircs_portal.application_revision_ciip_incentive(
(select * from record)
)
$$,
'%Reported product requires emissions_from_eios%',
'throws an exception if a product requires emissions from eios and it is not present'
);

-- Report 2 non-energy products with requires_emission_allocation = false
update ggircs_portal.form_result
set form_result = '[
Expand Down

0 comments on commit c8b6db1

Please sign in to comment.