-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: conditional verification routing
chore: prettier chore: update vitest chore: prettier chore: prettier chore: prettier chore: prettier
- Loading branch information
1 parent
230398d
commit 22a7c63
Showing
11 changed files
with
179 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from model_bakery import baker | ||
from unittest.mock import patch, MagicMock | ||
from registration.tests.utils.helpers import CommonTestSetup, TestUtils | ||
from registration.utils import custom_reverse_lazy | ||
|
||
|
||
class TestComplianceDataApi(CommonTestSetup): | ||
def setup_method(self): | ||
self.report_version = baker.make_recipe('reporting.tests.utils.report_version') | ||
self.mock_emission = 54321.1234 | ||
super().setup_method() | ||
TestUtils.authorize_current_user_as_operator_user(self, operator=self.report_version.report.operator) | ||
|
||
"""Tests for the get_attributable_emissions endpoint.""" | ||
|
||
@patch( | ||
"reporting.service.compliance_service.ComplianceService.get_emissions_attributable_for_reporting", autospec=True | ||
) | ||
def test_returns_attributable_emissions( | ||
self, | ||
mock_get_attributable_emissions: MagicMock, | ||
): | ||
# Arrange: Mock report version and report verification data | ||
mock_get_attributable_emissions.return_value = self.mock_emission | ||
|
||
# Act: Authorize user and perform GET request | ||
response = TestUtils.mock_get_with_auth_role( | ||
self, | ||
"industry_user", | ||
custom_reverse_lazy( | ||
"get_attributable_emissions", | ||
kwargs={"report_version_id": self.report_version.id}, | ||
), | ||
) | ||
|
||
# Assert: Verify the response status | ||
assert response.status_code == 200 | ||
|
||
# Assert: Verify the service was called with the correct version ID | ||
mock_get_attributable_emissions.assert_called_once_with(self.report_version.id) | ||
|
||
# Assert: Validate the response data | ||
response_json = response.json() | ||
|
||
assert float(response_json) == self.mock_emission |
16 changes: 3 additions & 13 deletions
16
...ting/src/app/bceidbusiness/industry_user/reports/[version_id]/compliance-summary/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
import { Suspense } from "react"; | ||
import ComplianceSummaryData from "@reporting/src/app/components/complianceSummary/ComplianceSummaryData"; | ||
import defaultPageFactory from "@bciers/components/nextPageFactory/defaultPageFactory"; | ||
import ComplianceSummaryPage from "@reporting/src/app/components/complianceSummary/ComplianceSummaryPage"; | ||
|
||
export default async function Page(router: any) { | ||
return ( | ||
<> | ||
<Suspense fallback="Loading Schema"> | ||
<ComplianceSummaryData | ||
versionId={parseInt(router.params?.version_id)} | ||
/> | ||
</Suspense> | ||
</> | ||
); | ||
} | ||
export default defaultPageFactory(ComplianceSummaryPage); |
16 changes: 3 additions & 13 deletions
16
...rc/app/bceidbusiness/industry_user_admin/reports/[version_id]/compliance-summary/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
import { Suspense } from "react"; | ||
import ComplianceSummaryData from "@reporting/src/app/components/complianceSummary/ComplianceSummaryData"; | ||
import defaultPageFactory from "@bciers/components/nextPageFactory/defaultPageFactory"; | ||
import ComplianceSummaryPage from "@reporting/src/app/components/complianceSummary/ComplianceSummaryPage"; | ||
|
||
export default async function Page(router: any) { | ||
return ( | ||
<> | ||
<Suspense fallback="Loading Schema"> | ||
<ComplianceSummaryData | ||
versionId={parseInt(router.params?.version_id)} | ||
/> | ||
</Suspense> | ||
</> | ||
); | ||
} | ||
export default defaultPageFactory(ComplianceSummaryPage); |
30 changes: 0 additions & 30 deletions
30
bciers/apps/reporting/src/app/components/complianceSummary/ComplianceSummaryData.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
bciers/apps/reporting/src/app/components/complianceSummary/ComplianceSummaryPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react"; | ||
import { actionHandler } from "@bciers/actions"; | ||
import ComplianceSummaryForm from "./ComplianceSummaryForm"; | ||
import { tasklistData } from "./TaskListElements"; | ||
import { HasReportVersion } from "@reporting/src/app/utils/defaultPageFactoryTypes"; | ||
import { getRegistrationPurpose } from "@reporting/src/app/utils/getRegistrationPurpose"; | ||
import { getAttributableEmissions } from "@reporting/src/app/utils/getAttributableEmissions"; | ||
import { | ||
RegistrationPurposes, | ||
regulatedOperationPurposes, | ||
} from "@/registration/app/components/operations/registration/enums"; | ||
|
||
const getComplianceData = async (versionId: number) => { | ||
return actionHandler( | ||
`reporting/report-version/${versionId}/compliance-data`, | ||
"GET", | ||
`reporting/report-version/${versionId}/compliance-data`, | ||
); | ||
}; | ||
export default async function ComplianceSummaryPage({ | ||
version_id, | ||
}: HasReportVersion) { | ||
const complianceData = await getComplianceData(version_id); | ||
//🔍 Check if reports need verification step... | ||
let needsVerification = false; | ||
//🔍 Check if registration purpose is OBPS Regulated Operation, Opt-in or New Entrants | ||
const registrationPurpose = (await getRegistrationPurpose(version_id)) | ||
?.registration_purpose; | ||
needsVerification = regulatedOperationPurposes.includes( | ||
registrationPurpose as RegistrationPurposes, | ||
); | ||
if ( | ||
needsVerification === false && | ||
registrationPurpose === RegistrationPurposes.REPORTING_OPERATION | ||
) { | ||
//🔍 Check if the registration purpose is Reporting Operation AND their total emissions attributable for reporting threshold is = or > than 25,000 TCo2 | ||
const attributableEmissionThreshold = 25000000; | ||
const attributableEmissions = await getAttributableEmissions(version_id); | ||
needsVerification = attributableEmissions >= attributableEmissionThreshold; | ||
} | ||
return ( | ||
<ComplianceSummaryForm | ||
versionId={version_id} | ||
needsVerification={needsVerification} | ||
summaryFormData={complianceData} | ||
taskListElements={tasklistData} | ||
/> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
bciers/apps/reporting/src/app/utils/getAttributableEmissions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { actionHandler } from "@bciers/actions"; | ||
|
||
export async function getAttributableEmissions(versionId: number) { | ||
const response = await actionHandler( | ||
`reporting/report-version/${versionId}/attributable-emissions`, | ||
"GET", | ||
"", | ||
); | ||
if (response.error) { | ||
throw new Error( | ||
"We couldn't find the attributable emissions for this report.", | ||
); | ||
} | ||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters