Skip to content

Commit

Permalink
chore: refactor compliance summary needs verification
Browse files Browse the repository at this point in the history
  • Loading branch information
shon-button committed Dec 19, 2024
1 parent fe24b9b commit 44c10ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ 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";
import { getReportNeedsVerification } from "@reporting/src/app/utils/getReportNeedsVerification";

const getComplianceData = async (versionId: number) => {
return actionHandler(
Expand All @@ -21,23 +16,8 @@ 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;
}
//🔍 Check if reports need verification
const needsVerification = await getReportNeedsVerification(version_id);
return (
<ComplianceSummaryForm
versionId={version_id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { actionHandler } from "@bciers/actions";

export async function getAttributableEmissions(versionId: number) {
export async function getReportNeedsVerification(versionId: number) {
const response = await actionHandler(
`reporting/report-version/${versionId}/attributable-emissions`,
"GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { render } from "@testing-library/react";
import ComplianceSummaryForm from "@reporting/src/app/components/complianceSummary/ComplianceSummaryForm";
import ComplianceSummaryPage from "@reporting/src/app/components/complianceSummary/ComplianceSummaryPage";
import { actionHandler } from "@bciers/actions";
import { getRegistrationPurpose } from "@reporting/src/app/utils/getRegistrationPurpose";
import { getAttributableEmissions } from "@reporting/src/app/utils/getAttributableEmissions";
import { getReportNeedsVerification } from "@reporting/src/app/utils/getReportNeedsVerification";
import { tasklistData } from "@reporting/src/app/components/complianceSummary/TaskListElements";
import { RegistrationPurposes } from "@/registration/app/components/operations/registration/enums";

import { vi } from "vitest";

Expand All @@ -21,22 +19,16 @@ vi.mock("@bciers/actions", () => ({
actionHandler: vi.fn(),
}));

vi.mock("@reporting/src/app/utils/getRegistrationPurpose", () => ({
getRegistrationPurpose: vi.fn(),
}));

vi.mock("@reporting/src/app/utils/getAttributableEmissions", () => ({
getAttributableEmissions: vi.fn(),
vi.mock("@reporting/src/app/utils/getReportNeedsVerification", () => ({
getReportNeedsVerification: vi.fn(),
}));

const mockComplianceSummaryForm = ComplianceSummaryForm as ReturnType<
typeof vi.fn
>;
const mockActionHandler = actionHandler as ReturnType<typeof vi.fn>;
const mockGetRegistrationPurpose = getRegistrationPurpose as ReturnType<
typeof vi.fn
>;
const mockGetAttributableEmissions = getAttributableEmissions as ReturnType<

const mockGetReportNeedsVerification = getReportNeedsVerification as ReturnType<
typeof vi.fn
>;

Expand All @@ -46,14 +38,8 @@ describe("ComplianceSummaryPage", () => {

// Mock the data for the test
const complianceData = { some: "data" };
const registrationPurpose = RegistrationPurposes.REPORTING_OPERATION;
const attributableEmissions = 10000000; // Below the threshold

mockActionHandler.mockResolvedValue(complianceData);
mockGetRegistrationPurpose.mockResolvedValue({
registration_purpose: registrationPurpose,
});
mockGetAttributableEmissions.mockResolvedValue(attributableEmissions);
mockGetReportNeedsVerification.mockResolvedValue(false);

// Render the page
render(await ComplianceSummaryPage({ version_id: versionId }));
Expand All @@ -75,12 +61,8 @@ describe("ComplianceSummaryPage", () => {

// Mock the data for the test
const complianceData = { some: "data" };
const registrationPurpose = RegistrationPurposes.OBPS_REGULATED_OPERATION;

mockActionHandler.mockResolvedValue(complianceData);
mockGetRegistrationPurpose.mockResolvedValue({
registration_purpose: registrationPurpose,
});
mockGetReportNeedsVerification.mockResolvedValue(true);

// Render the page
render(await ComplianceSummaryPage({ version_id: versionId }));
Expand All @@ -102,15 +84,8 @@ describe("ComplianceSummaryPage", () => {

// Mock the data for the test
const complianceData = { some: "data" };
const registrationPurpose =
RegistrationPurposes.ELECTRICITY_IMPORT_OPERATION;
const attributableEmissions = 30000000; // Above the threshold

mockActionHandler.mockResolvedValue(complianceData);
mockGetRegistrationPurpose.mockResolvedValue({
registration_purpose: registrationPurpose,
});
mockGetAttributableEmissions.mockResolvedValue(attributableEmissions);
mockGetReportNeedsVerification.mockResolvedValue(true);

// Render the page
render(await ComplianceSummaryPage({ version_id: versionId }));
Expand Down

0 comments on commit 44c10ca

Please sign in to comment.