Skip to content

Commit

Permalink
fix(SILVA-515): added new fields and test update
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Dec 6, 2024
1 parent 32269ad commit bccae3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions frontend/src/__test__/services/OpeningService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ describe('OpeningService', () => {
describe('fetchOpeningsPerYear', () => {
it('should fetch openings per year successfully', async () => {
const mockData = [
{ monthName: 'January', amount: 10 },
{ monthName: 'February', amount: 20 }
{ monthName: 'Jan', amount: 10, statusCounts: { APP: 5, FG: 2 } },
{ monthName: 'Feb', amount: 20, statusCounts: { APP: 5, FG: 2 } }
];
(axios.get as vi.Mock).mockResolvedValue({ data: mockData });

const props = { orgUnitCode: '001', statusCode: 'APP', entryDateStart: '2023-01-01', entryDateEnd: '2023-12-31' };
const props = { orgUnitCode: ['001'], statusCode: ['APP'], entryDateStart: '2023-01-01', entryDateEnd: '2023-12-31' };
const result = await fetchOpeningsPerYear(props);

expect(axios.get).toHaveBeenCalledWith(`${backendUrl}/api/dashboard-metrics/submission-trends?orgUnitCode=001&statusCode=APP&entryDateStart=2023-01-01&entryDateEnd=2023-12-31`, {
expect(axios.get).toHaveBeenCalledWith(`${backendUrl}/api/users/submission-trends?orgUnitCode=001&statusCode=APP&entryDateStart=2023-01-01&entryDateEnd=2023-12-31`, {
headers: { Authorization: `Bearer ${authToken}`,
"Access-Control-Allow-Origin": "http://localhost:3000",
"Content-Type": "application/json" }
});
expect(result).toEqual([
{ group: 'Openings', key: 'January', value: 10 },
{ group: 'Openings', key: 'February', value: 20 }
{ group: 'Openings', key: 'Jan', value: 10, statusCount: { APP: 5, FG: 2 } },
{ group: 'Openings', key: 'Feb', value: 20, statusCount: { APP: 5, FG: 2 } }
]);
});

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/services/OpeningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export async function fetchOpeningsPerYear(props: IOpeningPerYear): Promise<Open
const formattedData: OpeningPerYearChart[] = data.map(item => ({
group: "Openings",
key: item.monthName,
value: item.amount
value: item.amount,
statusCount: item.statusCounts
}));

return formattedData;
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/services/search/openings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAuthIdToken } from "../AuthService";
import { dateTypes, blockStatuses } from "../../mock-data/openingSearchFilters";
import { createDateParams } from "../../utils/searchUtils";
import { API_ENDPOINTS, defaultHeaders } from "../apiConfig";
import { TextValueData } from "../../utils/multiSelectSortUtils";

export interface OpeningFilters {
searchInput?: string;
Expand Down Expand Up @@ -66,6 +67,16 @@ export interface CodeDescription {
description: string;
}

export const status: TextValueData[] = [
{value:'AMG', text: 'Amalgamate'},
{value:'AMD', text: 'Amended'},
{value:'APP', text: 'Approved'},
{value:'DFT', text: 'Draft'},
{value:'FG', text: 'Free Growing'},
{value:'RMD', text: 'Removed'},
{value:'RET', text: 'Retired'},
{value:'SUB', text: 'Submitted'}
];

export const fetchOpenings = async (filters: OpeningFilters): Promise<any> => {
// Get the date params based on dateType
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/OpeningPerYearChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface OpeningPerYearChart {
group: string;
key: string;
value: string;
statusCount: Record<string, number>;
}

0 comments on commit bccae3b

Please sign in to comment.