Merged
Conversation
Implements the book detail page, allowing users to view the title, author, and synopsis of a single book. - Creates a new dynamic route `GET /books/:bookId` to handle requests for specific books. - Extends the `apiClient` with a `getBookById` function to fetch a single book from the backend API. - Adds a new Nunjucks template (`book-data.njk`) to render the book's information using GOV.UK Design System components. - Follows a TDD approach by first creating a failing integration test for the "happy path" (when a book is successfully found) and then writing the minimal code to make it pass. - The test suite is organized by feature, with the new test added to the existing `books.test.js` file.
Updates the book list page to use the HATEOAS links provided by the backend API for navigating to book detail pages. This makes the frontend more resilient to changes in the backend URL structure. - The `GET /books` test is updated to assert that relative links are rendered correctly for each book. - The route handler for `GET /books` now includes logic to transform all absolute HATEOAS URLs from the API into relative paths suitable for the view. - This transformation logic is extracted into a reusable helper function to keep the code DRY and is now used by both the list and detail page route handlers.
Implements graceful error handling for the `GET /books/:bookId` endpoint when a requested book is not found in the backend API. - Follows a TDD workflow by first adding a failing test case that mocks a 404 API response and asserts that the application returns a 404 status. - The route handler is updated with a `try...catch` block to handle exceptions from the API client. - A user-friendly, GOV.UK-styled 404 page is rendered when the API returns a 404, separating this expected "not found" case from unexpected server errors.
Adds a new test case to cover the scenario where the backend API returns a non-404 error (e.g., 500 Internal Server Error) when fetching a single book. This test acts as a regression guard, ensuring the application's `try...catch` block correctly falls through to the generic 500 error handler and renders the appropriate user-friendly error page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Book Detail Page Implementation
Overview
This PR introduces the book detail page, allowing users to view the full details of a single book. It builds upon the existing book list by providing navigation to individual book pages and includes robust error handling for various scenarios.
Features
/books/:bookIdthat fetches and displays a single book's title, author, and synopsis./bookslist page by making each book title a clickable link to its corresponding detail page.Error Handling
Refactor
Key TDD & Architectural Decisions
books.test.js) was expanded to cover: