Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"@hmcts-cft/simple-router": "workspace:*",
"@hmcts/admin-pages": "workspace:*",
"@hmcts/administrative-court-daily-cause-list": "workspace:*",
"@hmcts/ast-daily-hearing-list": "workspace:*",
"@hmcts/auth": "workspace:*",
"@hmcts/care-standards-tribunal-weekly-hearing-list": "workspace:*",
"@hmcts/cic-weekly-hearing-list": "workspace:*",
"@hmcts/civil-and-family-daily-cause-list": "workspace:*",
"@hmcts/civil-daily-cause-list": "workspace:*",
"@hmcts/cookie-manager": "1.1.0",
Expand All @@ -36,6 +38,7 @@
"@hmcts/london-administrative-court-daily-cause-list": "workspace:*",
"@hmcts/public-pages": "workspace:*",
"@hmcts/rcj-standard-daily-cause-list": "workspace:*",
"@hmcts/send-daily-hearing-list": "workspace:*",
"@hmcts/sjp-press-list": "workspace:*",
"@hmcts/sjp-public-list": "workspace:*",
"@hmcts/subscriptions": "workspace:*",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/pages/(admin)/manual-upload-summary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

const listTypeId = uploadData.listType ? Number.parseInt(uploadData.listType, 10) : null;
const listType = listTypeId ? await findListTypeById(listTypeId) : null;
const listTypeName = listType ? (locale === "cy" ? listType.welshFriendlyName : listType.friendlyName) || uploadData.listType : uploadData.listType;
const listTypeName = listType
? (locale === "cy" ? listType.welshFriendlyName : listType.shortenedFriendlyName || listType.friendlyName) || listType.name || uploadData.listType

Check warning on line 19 in apps/web/src/pages/(admin)/manual-upload-summary/index.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=hmcts.cath&issues=AZ7_fmI0M5jVkSooRB7Z&open=AZ7_fmI0M5jVkSooRB7Z&pullRequest=772
: uploadData.listType;

return { courtName, listTypeName };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

const listTypeId = uploadData.listType ? Number.parseInt(uploadData.listType, 10) : null;
const listType = listTypeId ? await findListTypeById(listTypeId) : null;
const listTypeName = listType ? (locale === "cy" ? listType.welshFriendlyName : listType.friendlyName) || uploadData.listType : uploadData.listType;
const listTypeName = listType
? (locale === "cy" ? listType.welshFriendlyName : listType.shortenedFriendlyName || listType.friendlyName) || listType.name || uploadData.listType

Check warning on line 24 in apps/web/src/pages/(admin)/non-strategic-upload-summary/index.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=hmcts.cath&issues=AZ7_fmFDM5jVkSooRB7Y&open=AZ7_fmFDM5jVkSooRB7Y&pullRequest=772
: uploadData.listType;

return { courtName, listTypeName };
}
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/pages/(admin)/non-strategic-upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "@hmcts/ast-daily-hearing-list"; // Register AST converter
import "@hmcts/care-standards-tribunal-weekly-hearing-list"; // Register CST converter
import "@hmcts/cic-weekly-hearing-list"; // Register CIC converter
import "@hmcts/send-daily-hearing-list"; // Register SEND converter
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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{% extends "layouts/base-template.njk" %}
{% from "govuk/components/table/macro.njk" import govukTable %}

{% block head %}
{{ super() }}
<style>
.back-to-top {
margin-top: 40px;
}
</style>
{% endblock %}

{% block page_content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

<h1 class="govuk-heading-l" id="top">{{ header.listTitle }}</h1>

<p class="govuk-body">
<a href="{{ t.factLinkUrl }}" class="govuk-link">{{ t.factLinkText }}</a> {{ t.factAdditionalText }}
</p>

<p class="govuk-body">
{% for line in t.venueAddressLines %}{{ line }}{% if not loop.last %}<br>{% endif %}{% endfor %}
</p>

<p class="govuk-body govuk-!-margin-bottom-1"><strong>{{ t.listForDate }} {{ header.listForDate }}</strong></p>

<p class="govuk-body">{{ t.lastUpdated }} {{ header.lastUpdatedDate }} {{ t.at }} {{ header.lastUpdatedTime }}</p>

<details class="govuk-details govuk-!-margin-top-6" data-module="govuk-details" open>
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
{{ t.importantInformationTitle }}
</span>
</summary>
<div class="govuk-details__text">
{% for paragraph in t.importantInformationParagraphs %}
<p class="govuk-body">{{ paragraph }}</p>
{% endfor %}
<p class="govuk-body">
{{ t.importantInformationLinkPrefix }}
<a href="{{ t.importantInformationLinkUrl }}" class="govuk-link">{{ t.importantInformationLinkText }}</a>.
</p>
</div>
</details>

<div class="govuk-form-group govuk-!-margin-top-6">
<h2 class="govuk-heading-s">{{ t.searchCasesTitle }}</h2>
<label class="govuk-label govuk-visually-hidden" for="case-search-input">
{{ t.searchCasesLabel }}
</label>
<input class="govuk-input govuk-!-width-one-half" id="case-search-input" name="search" type="text" aria-label="{{ t.searchCasesLabel }}">
</div>

<div id="hearings-table-container">
<table class="govuk-table" id="hearings-table" role="table" aria-label="{{ t.pageTitle }}">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.appellant }}</th>
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.appealReferenceNumber }}</th>
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.caseType }}</th>
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.hearingType }}</th>
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.hearingTime }}</th>
<th scope="col" class="govuk-table__header">{{ t.tableHeaders.additionalInformation }}</th>
</tr>
</thead>
<tbody class="govuk-table__body">
{% for hearing in hearings %}
<tr class="govuk-table__row">
<td class="govuk-table__cell">{{ hearing.appellant }}</td>
<td class="govuk-table__cell">{{ hearing.appealReferenceNumber }}</td>
<td class="govuk-table__cell">{{ hearing.caseType }}</td>
<td class="govuk-table__cell">{{ hearing.hearingType }}</td>
<td class="govuk-table__cell">{{ hearing.hearingTime }}</td>
<td class="govuk-table__cell">{{ hearing.additionalInformation }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

<p class="govuk-body-s govuk-!-margin-top-6">{{ t.dataSource }}: {{ dataSource }}</p>

<div class="back-to-top">
<a href="#top" class="govuk-link">{{ t.backToTop }}</a>
</div>

</div>
</div>
{% endblock %}
232 changes: 232 additions & 0 deletions apps/web/src/pages/(list-types)/ast-daily-hearing-list/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import type { Request, Response } from "express";
import { beforeEach, describe, expect, it, vi } from "vitest";

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

vi.mock("@hmcts/list-types-common", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hmcts/list-types-common")>();
return {
...actual,
createJsonValidator: () => mockValidate
};
});

vi.mock("@hmcts/publication", () => ({
getArtefactById: vi.fn(),
getPublicationJson: vi.fn(),
PROVENANCE_LABELS: {
MANUAL_UPLOAD: "Manual Upload",
LIST_ASSIST: "List Assist"
}
}));

vi.mock("@hmcts/ast-daily-hearing-list", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hmcts/ast-daily-hearing-list")>();
return {
...actual,
renderAstDailyHearingListData: vi.fn()
};
});

import { renderAstDailyHearingListData } from "@hmcts/ast-daily-hearing-list";
import { getArtefactById, getPublicationJson } from "@hmcts/publication";
import { GET } from "./index.js";

describe("AST Daily 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: "15",
listTypeId: 30,
contentDate: new Date("2026-01-01"),
displayFrom: new Date("2026-01-01"),
displayTo: new Date("2026-01-01"),
lastReceivedDate: new Date("2026-01-01T12:00:00Z"),
provenance: "MANUAL_UPLOAD"
};

const mockJsonData = [
{
appellant: "A Smith",
appealReferenceNumber: "AST/2026/001",
caseType: "Section 4",
hearingType: "Substantive",
hearingTime: "10am",
additionalInformation: "Remote hearing"
}
];

const mockRenderedData = {
header: {
listTitle: "Asylum Support Tribunal Daily Hearing List",
listForDate: "1 January 2026",
lastUpdatedDate: "1 January 2026",
lastUpdatedTime: "12pm"
},
hearings: [
{
appellant: "A Smith",
appealReferenceNumber: "AST/2026/001",
caseType: "Section 4",
hearingType: "Substantive",
hearingTime: "10am",
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(renderAstDailyHearingListData).mockReturnValue(mockRenderedData);

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

expect(getArtefactById).toHaveBeenCalledWith("test-artefact-123");
expect(getPublicationJson).toHaveBeenCalledWith("test-artefact-123");
expect(mockValidate).toHaveBeenCalledWith(mockJsonData);
expect(renderAstDailyHearingListData).toHaveBeenCalledWith(mockJsonData, {
locale: "en",
contentDate: mockArtefact.contentDate,
lastReceivedDate: mockArtefact.lastReceivedDate.toISOString(),
listTitle: "Asylum Support Tribunal Daily Hearing List"
});
const renderCall = vi.mocked(res.render!).mock.calls[0]!;
expect(renderCall[0]).toBe("ast-daily-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 404 when JSON blob is not found", async () => {
const mockArtefact = {
artefactId: "test-artefact-123",
locationId: "15",
listTypeId: 30,
contentDate: new Date("2026-01-01"),
lastReceivedDate: new Date("2026-01-01T12:00:00Z"),
provenance: "MANUAL_UPLOAD"
};

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

vi.mocked(getArtefactById).mockResolvedValue(mockArtefact as any);
vi.mocked(getPublicationJson).mockResolvedValue(null);

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

expect(res.status).toHaveBeenCalledWith(404);
});

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

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

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

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

expect(res.status).toHaveBeenCalledWith(400);
});

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);
});

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

const mockRenderedData = {
header: { listTitle: "Welsh title", listForDate: "1 Ionawr 2026", lastUpdatedDate: "1 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([]);
mockValidate.mockReturnValue({ isValid: true, errors: [] });
vi.mocked(renderAstDailyHearingListData).mockReturnValue(mockRenderedData);

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

expect(renderAstDailyHearingListData).toHaveBeenCalledWith([], expect.objectContaining({ locale: "cy" }));
});
});
});
Loading
Loading