Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDS-5995] - create mine report definitions #3413

Merged
merged 9 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE mine_report_definition
ADD CONSTRAINT uq_report_name UNIQUE (report_name);
16 changes: 8 additions & 8 deletions services/common/src/components/reports/ReportDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ interface ReportDetailsFormProps {
}

const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
isEditMode = true,
initialValues,
mineGuid,
formButtons,
handleSubmit,
}) => {
isEditMode = true,
initialValues,
mineGuid,
formButtons,
handleSubmit,
}) => {
const { reportGuid } = useParams<{ reportGuid?: string }>();

const coreEditReportPermission = USER_ROLES.role_edit_reports;
Expand Down Expand Up @@ -250,7 +250,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({

useEffect(() => {
// update compliance article options when "Report Name" changes
if (mine_report_definition_guid) {
if (mine_report_definition_guid && mineReportDefinitionOptions.length) {
const newReportComplianceArticle = mineReportDefinitionOptions.find((opt) => {
return opt.mine_report_definition_guid === mine_report_definition_guid;
});
Expand All @@ -260,7 +260,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
} else {
setSelectedReportCode("");
}
}, [mine_report_definition_guid]);
}, [mine_report_definition_guid, mineReportDefinitionOptions]);

useEffect(() => {
if (system === SystemFlagEnum.core) {
Expand Down
8 changes: 6 additions & 2 deletions services/common/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export const STANDARD_PERMIT_CONDITIONS = (noticeOfWorkType) =>
export const STANDARD_PERMIT_CONDITION = (permitConditionGuid) =>
`/mines/permits/standard-conditions/${permitConditionGuid}`;

export const PERMIT_AMENDMENT_CONDITION_ASSIGN_REVIEWER = "mines/permits/condition-category/assign-review-user";
export const PERMIT_AMENDMENT_CONDITION_ASSIGN_REVIEWER =
"mines/permits/condition-category/assign-review-user";

export const PERMIT_SERVICE_EXTRACTION = `/mines/permits/condition-extraction`;
export const POLL_PERMIT_SERVICE_EXTRACTION = (taskId: string) =>
Expand Down Expand Up @@ -259,7 +260,10 @@ export const MINE_WORK_INFORMATION = (mineGuid, mineWorkInformationGuid) =>
export const REPORTS = (params = {}) => `/mines/reports?${queryString.stringify(params)}`;
export const REPORT_SUBMISSIONS = (params?) =>
`/mines/reports/submissions?${queryString.stringify(params)}`;
export const MINE_REPORT_DEFINITIONS = (params = {}) => `/mines/reports/definitions?${queryString.stringify(params)}`;
export const MINE_REPORT_DEFINITIONS = (params = {}) =>
`/mines/reports/definitions?${queryString.stringify(params)}`;
export const MINE_REPORT_DEFINITION = "/mines/reports/definitions";
export const MINE_REPORT_DUE_DATE_TYPES = "/mines/reports/due-date-types";
export const MINE_REPORTS = (mineGuid, params?) =>
`/mines/${mineGuid}/reports?${queryString.stringify(params)}`;
export const MINE_REPORT = (mineGuid, mineReportGuid) =>
Expand Down
1 change: 1 addition & 0 deletions services/common/src/interfaces/reports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./mineReportContact.interface";
export * from "./mineReport.interface";
export * from "./mineReportDefinition.interface";
export * from "./mineReportParams.interface";
export * from "./mineReportDueDateType.interface";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IMineReportDueDateType {
mine_report_due_date_type: string;
description: string;
}
155 changes: 155 additions & 0 deletions services/common/src/redux/slices/complianceReportsSlice.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { configureStore } from "@reduxjs/toolkit";
import CustomAxios from "@mds/common/redux/customAxios";
import complianceReportReducer, {
createMineReportDefinition,
fetchComplianceReports,
fetchMineReportDueDateTypes,
ReportDefinitionSubmission,
} from "./complianceReportsSlice";
import {
hideLoadingMock,
showLoadingMock,
} from "@mds/common/redux/slices/mineReportPermitRequirementSlice.spec";

// Mocks
jest.mock("@mds/common/redux/customAxios");
jest.mock("react-redux-loading-bar", () => ({
showLoading: () => showLoadingMock,
hideLoading: () => hideLoadingMock,
}));
jest.mock("@mds/common/redux/customAxios");

jest.mock("react-redux-loading-bar", () => ({
showLoading: () => showLoadingMock,
hideLoading: () => hideLoadingMock,
}));
jest.mock("antd", () => ({
notification: {
success: jest.fn(),
},
}));

describe("complianceReportsSlice", () => {
let store;

// Mock responses
const mockComplianceReports = {
data: {
records: [
{
mine_report_definition_guid: "guid1",
report_name: "Report 1",
description: "Description for Report 1",
mine_report_due_date_type: "Type1",
is_common: false,
is_prr_only: true,
active_ind: true,
default_due_date: "2024-12-31",
},
{
mine_report_definition_guid: "guid2",
report_name: "Report 2",
description: "Description for Report 2",
mine_report_due_date_type: "Type2",
is_common: true,
is_prr_only: false,
active_ind: false,
default_due_date: "2025-01-01",
},
],
current_page: 1,
items_per_page: 10,
total: 2,
total_pages: 1,
},
};

const mockDueDateTypes = {
data: [
{ mine_report_due_date_type: "TypeA", description: "Type A Description" },
{ mine_report_due_date_type: "TypeB", description: "Type B Description" },
],
};

beforeEach(() => {
store = configureStore({
reducer: {
complianceCodes: complianceReportReducer,
},
});
});

afterEach(() => {
jest.clearAllMocks();
});

describe("fetchComplianceReports", () => {
it("should fetch compliance reports successfully", async () => {
// Mock implementation for the API call
(CustomAxios as jest.Mock).mockImplementation(() => ({
get: jest.fn().mockResolvedValue(mockComplianceReports),
}));

const searchParams = { per_page: 10 };
await store.dispatch(fetchComplianceReports(searchParams));

const state = store.getState().complianceCodes;

expect(state.reportPageData.records.length).toBe(2);
expect(state.reportPageData).toEqual({
...mockComplianceReports.data,
});
expect(state.params).toEqual(searchParams);
});
});

describe("createMineReportDefinition", () => {
const mockReportDefinition = {
data: {
mine_report_definition_guid: "new_guid",
report_name: "New Report",
description: "New Report Description",
mine_report_due_date_type: "ANV",
default_due_date: "2026-01-01",
is_common: true,
is_prr_only: false,
active_ind: true,
},
};

it("should successfully create a compliance report definition", async () => {
// (CustomAxios as jest.Mock).mockResolvedValue({ data: mockReportDefinition });
(CustomAxios as jest.Mock).mockImplementation(() => ({
post: jest.fn().mockResolvedValue(mockReportDefinition),
}));

const payload: ReportDefinitionSubmission = {
report_name: "New Report",
description: "New Report Description",
mine_report_due_date_type_code: "ANV",
is_common: true,
is_prr_only: false,
};

await store.dispatch(createMineReportDefinition(payload));

const state = store.getState().complianceCodes;
expect(state.reportPageData.records[0]).toMatchObject(mockReportDefinition.data);
});
});

describe("fetchMineReportDueDateTypes", () => {
it("should fetch mine report due date types successfully", async () => {
// Mock implementation for `get`
(CustomAxios as jest.Mock).mockImplementation(() => ({
get: jest.fn().mockResolvedValue(mockDueDateTypes),
}));

await store.dispatch(fetchMineReportDueDateTypes({}));

const state = store.getState().complianceCodes;

expect(state.dueDateTypes).toEqual(mockDueDateTypes.data);
});
});
});
Loading
Loading