Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@hmcts/magistrates-public-adult-court-list": "workspace:*",
"@hmcts/magistrates-public-list": "workspace:*",
"@hmcts/magistrates-standard-list": "workspace:*",
"@hmcts/pht-weekly-hearing-list": "workspace:*",
"@hmcts/public-pages": "workspace:*",
"@hmcts/rcj-standard-daily-cause-list": "workspace:*",
"@hmcts/send-daily-hearing-list": "workspace:*",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { moduleRoot as magistratesAdultCourtListModuleRoot } from "@hmcts/magist
import { moduleRoot as magistratesPublicAdultCourtListModuleRoot } from "@hmcts/magistrates-public-adult-court-list/config";
import { moduleRoot as magistratesPublicListModuleRoot } from "@hmcts/magistrates-public-list/config";
import { moduleRoot as magistratesStandardListModuleRoot } from "@hmcts/magistrates-standard-list/config";
import { moduleRoot as phtWeeklyHearingListModuleRoot } from "@hmcts/pht-weekly-hearing-list/config";
import {
apiRoutes as publicPagesApiRoutes,
fileUploadRoutes as publicPagesFileUploadRoutes,
Expand Down Expand Up @@ -144,7 +145,8 @@ export async function createApp(): Promise<Express> {
grcWeeklyHearingListModuleRoot,
wpafccWeeklyHearingListModuleRoot,
utiacStatutoryAppealModuleRoot,
utiacJrModuleRoot
utiacJrModuleRoot,
phtWeeklyHearingListModuleRoot
];

await configureGovuk(app, modulePaths, {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/pages/(admin)/non-strategic-upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "@hmcts/upper-tribunal-administrative-appeals-chamber-daily-hearing-list"
import { LANGUAGE_LABELS, SENSITIVITY_LABELS, storeNonStrategicUpload, type UploadFormData, validateNonStrategicUploadForm } from "@hmcts/admin-pages";
import { requireRole, USER_ROLES } from "@hmcts/auth";
import { getAllLocations, getLocationById } from "@hmcts/location";
import { Language, Sensitivity } from "@hmcts/publication";
import { Language } from "@hmcts/publication";
import { findListTypeById, findNonStrategicListTypes } from "@hmcts/system-admin-pages";
import { saveSession } from "@hmcts/web-core";
import type { Request, RequestHandler, Response } from "express";
Expand All @@ -25,7 +25,9 @@ async function getListTypesData() {
text: listType.shortenedFriendlyName || listType.friendlyName || listType.name
}))
];
const sensitivityMap = Object.fromEntries(nonStrategicListTypes.map((listType) => [listType.id.toString(), Sensitivity.PUBLIC]));
const sensitivityMap = Object.fromEntries(
nonStrategicListTypes.map((listType) => [listType.id.toString(), listType.defaultSensitivity?.toUpperCase() ?? ""])
);
return { options, sensitivityMap };
}

Expand Down
255 changes: 255 additions & 0 deletions apps/web/src/pages/(list-types)/pht-weekly-hearing-list/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
import type { Request, Response } from "express";
import { beforeEach, describe, expect, it, vi } from "vitest";

const mockValidate = vi.hoisted(() => vi.fn());

vi.mock("@hmcts/publication", () => ({
getArtefactById: vi.fn(),
getPublicationJson: vi.fn(),
canAccessPublicationData: vi.fn().mockReturnValue(true),
resolveListType: vi.fn().mockResolvedValue({}),
validateJson: vi.fn().mockReturnValue({ isValid: true, errors: [] }),
PROVENANCE_LABELS: {
MANUAL_UPLOAD: "Manual Upload",
LIST_ASSIST: "List Assist"
}
}));

vi.mock("@hmcts/pht-weekly-hearing-list", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hmcts/pht-weekly-hearing-list")>();
return {
...actual,
renderPhtData: vi.fn(),
validatePhtWeeklyHearingList: mockValidate
};
});

import { renderPhtData } from "@hmcts/pht-weekly-hearing-list";
import { getArtefactById, getPublicationJson } from "@hmcts/publication";
import { GET } from "./index.js";

describe("PHT Weekly Hearing List page controller", () => {
let req: Partial<Request>;
let res: Partial<Response>;

beforeEach(() => {
vi.clearAllMocks();

req = {
query: {}
};

res = {
status: vi.fn().mockReturnThis(),
render: vi.fn(),
locals: { locale: "en" }
};
});

describe("GET handler", () => {
it("should render the list successfully with valid data", async () => {
const mockArtefact = {
artefactId: "test-artefact-123",
locationId: "9001",
listTypeId: 999,
contentDate: new Date("2026-01-01"),
displayFrom: new Date("2026-01-01"),
displayTo: new Date("2026-01-07"),
lastReceivedDate: new Date("2026-01-01T12:00:00Z"),
provenance: "MANUAL_UPLOAD"
};

const mockJsonData = [
{
date: "01/01/2026",
caseName: "Test Case A vs B",
hearingLength: "1 hour",
hearingType: "Substantive hearing",
venue: "Primary Health Tribunal",
additionalInformation: "Remote hearing"
}
];

const mockRenderedData = {
header: {
listTitle: "Primary Health Tribunal Weekly Hearing List",
weekCommencingDate: "01 January 2026",
lastUpdatedDate: "01 January 2026",
lastUpdatedTime: "12pm"
},
hearings: [
{
date: "01 January 2026",
caseName: "Test Case A vs B",
hearingLength: "1 hour",
hearingType: "Substantive hearing",
venue: "Primary Health Tribunal",
additionalInformation: "Remote hearing"
}
]
};

req.query = { artefactId: "test-artefact-123" };

vi.mocked(getArtefactById).mockResolvedValue(mockArtefact as any);
vi.mocked(getPublicationJson).mockResolvedValue(mockJsonData);
mockValidate.mockReturnValue({ isValid: true, errors: [] });
vi.mocked(renderPhtData).mockReturnValue(mockRenderedData as any);

await GET(req as Request, res as Response);

expect(getArtefactById).toHaveBeenCalledWith("test-artefact-123");
expect(getPublicationJson).toHaveBeenCalled();
expect(mockValidate).toHaveBeenCalledWith(mockJsonData);
expect(renderPhtData).toHaveBeenCalledWith(mockJsonData, {
locale: "en",
courtName: "Primary Health Tribunal",
contentDate: mockArtefact.contentDate,
lastReceivedDate: mockArtefact.lastReceivedDate.toISOString(),
listTitle: "Primary Health Tribunal Weekly Hearing List"
});
const renderCall = vi.mocked(res.render!).mock.calls[0]!;
expect(renderCall[0]).toBe("pht-weekly-hearing-list");
expect(renderCall[1]).toMatchObject({
header: mockRenderedData.header,
hearings: mockRenderedData.hearings,
dataSource: "Manual Upload"
});
});

it("should return 400 when artefactId is missing", async () => {
req.query = {};

await GET(req as Request, res as Response);

expect(res.status).toHaveBeenCalledWith(400);
expect(res.render).toHaveBeenCalledWith(
"errors/common",
expect.objectContaining({
errorTitle: "Bad Request",
errorMessage: "Missing artefactId parameter"
})
);
});

it("should return 404 when artefact is not found", async () => {
req.query = { artefactId: "non-existent-artefact" };

vi.mocked(getArtefactById).mockResolvedValue(null);

await GET(req as Request, res as Response);

expect(res.status).toHaveBeenCalledWith(404);
expect(res.render).toHaveBeenCalledWith(
"errors/common",
expect.objectContaining({
errorTitle: "Not Found",
errorMessage: "The requested list could not be found"
})
);
});

it("should return 400 when JSON validation fails", async () => {
const mockArtefact = {
artefactId: "test-artefact-123",
listTypeId: 999,
contentDate: new Date("2026-01-01"),
lastReceivedDate: new Date("2026-01-01T12:00:00Z"),
provenance: "MANUAL_UPLOAD"
};

const mockJsonData = [
{
date: "invalid-date",
caseName: "Test Case",
hearingLength: "1 hour",
hearingType: "Substantive hearing",
venue: "Primary Health Tribunal",
additionalInformation: "Remote hearing"
}
];

req.query = { artefactId: "test-artefact-123" };

vi.mocked(getArtefactById).mockResolvedValue(mockArtefact as any);
vi.mocked(getPublicationJson).mockResolvedValue(mockJsonData);
mockValidate.mockReturnValue({ isValid: false, errors: ["Invalid date format"] });

await GET(req as Request, res as Response);

expect(res.status).toHaveBeenCalledWith(400);
expect(res.render).toHaveBeenCalledWith(
"errors/common",
expect.objectContaining({
errorTitle: "Invalid Data",
errorMessage: "The list data is invalid"
})
);
});

it("should return 500 on server error", async () => {
req.query = { artefactId: "test-artefact-123" };

vi.mocked(getArtefactById).mockRejectedValue(new Error("Database connection failed"));

await GET(req as Request, res as Response);

expect(res.status).toHaveBeenCalledWith(500);
expect(res.render).toHaveBeenCalledWith(
"errors/common",
expect.objectContaining({
errorTitle: "Server Error",
errorMessage: "An error occurred while loading the list"
})
);
});

it("should use Welsh locale when specified", async () => {
const mockArtefact = {
artefactId: "test-artefact-123",
listTypeId: 999,
contentDate: new Date("2026-01-01"),
lastReceivedDate: new Date("2026-01-01T12:00:00Z"),
provenance: "MANUAL_UPLOAD"
};

const mockJsonData = [
{
date: "01/01/2026",
caseName: "Test Case",
hearingLength: "1 hour",
hearingType: "Substantive hearing",
venue: "Primary Health Tribunal",
additionalInformation: "Remote hearing"
}
];

const mockRenderedData = {
header: {
listTitle: "Rhestr Gwrandawiadau Wythnosol y Tribiwnlys Iechyd Sylfaenol",
weekCommencingDate: "01 Ionawr 2026",
lastUpdatedDate: "01 Ionawr 2026",
lastUpdatedTime: "12pm"
},
hearings: []
};

req.query = { artefactId: "test-artefact-123" };
res.locals = { locale: "cy" };

vi.mocked(getArtefactById).mockResolvedValue(mockArtefact as any);
vi.mocked(getPublicationJson).mockResolvedValue(mockJsonData);
mockValidate.mockReturnValue({ isValid: true, errors: [] });
vi.mocked(renderPhtData).mockReturnValue(mockRenderedData as any);

await GET(req as Request, res as Response);

expect(renderPhtData).toHaveBeenCalledWith(
mockJsonData,
expect.objectContaining({
locale: "cy"
})
);
});
});
});
28 changes: 28 additions & 0 deletions apps/web/src/pages/(list-types)/pht-weekly-hearing-list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
phtWeeklyHearingListCy as cy,
phtWeeklyHearingListEn as en,
type PhtHearingList,
renderPhtData,
validatePhtWeeklyHearingList
} from "@hmcts/pht-weekly-hearing-list";
import { createSimpleListTypeHandler, resolveDataSource } from "../list-type-handler.js";

export const GET = createSimpleListTypeHandler<PhtHearingList>({
en,
cy,
validate: validatePhtWeeklyHearingList,
logPrefix: "pht-weekly-hearing-list",
serverError: { errorTitle: "Server Error", errorMessage: "An error occurred while loading the list" },
render: ({ artefact, jsonData, locale, res }) => {
const t = locale === "cy" ? cy : en;
const { header, hearings } = renderPhtData(jsonData, {
locale,
courtName: "Primary Health Tribunal",
contentDate: artefact.contentDate,
lastReceivedDate: artefact.lastReceivedDate.toISOString(),
listTitle: t.pageTitle
});
const dataSource = resolveDataSource(artefact.provenance, t as { provenanceLabels?: Record<string, string> });
res.render("pht-weekly-hearing-list", { en, cy, t, title: header.listTitle, header, hearings, dataSource });
}
});
Loading
Loading