feat: multiple improvements to library functionality (#50)
Node.js CI / CI (push) Successful in 1m18s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m17s

## Summary

This PR implements several improvements to the library application:

- Added start and finish date tracking for media items
- Added "Retired" category for abandoned media
- Implemented avatar-based user menu with dropdown navigation
- Added automatic background token refresh to prevent session expiry
- Created centralised logging system with frontend-to-API log forwarding
- Added toast notifications for error handling

## Changes

### Media Tracking (#41)
- Added `dateStarted` and `dateFinished` fields to Books, Games, Manga, Music, and Shows
- Updated TypeScript types, Prisma schema, and API services
- Added manual date input fields to frontend forms
- Properly converts HTML date strings to Date objects before API submission

### Retired Category (#43)
- Added `RETIRED` status to all media type enums
- Updated Prisma schema, frontend dropdowns, and filter buttons
- Added status label handling for retired items

### User Menu (#46)
- Replaced username text with avatar image in header
- Created dropdown menu with navigation items (Users, Audit, Suggestions)
- Added logout button to menu
- Implemented keyboard accessibility (tabindex, role, keyup handlers)

### Token Refresh (#44)
- Implemented automatic token refresh every 13 minutes in background
- Added proactive refresh to prevent token expiry during form filling
- Prevents users from losing form data due to expired sessions

### Centralised Logging (#1)
- Created `/log` endpoint on API to receive frontend logs
- Replaced API console.log calls with @nhcarrigan/logger
- Created ConsoleLoggerService to intercept all console methods on frontend
- Added global error handlers (window.error, unhandledrejection) on frontend
- Added process error handlers (uncaughtException, unhandledRejection, SIGTERM, SIGINT) on API
- All frontend console activity now forwarded to centralised logging

### Error Handling
- Created ToastService and ToastComponent for displaying errors
- Integrated with GlobalErrorHandler and HTTP interceptor
- Added accessibility features (keyboard navigation, ARIA attributes)
- Set toast opacity to 40% for optimal readability

### Testing & Build
- Fixed pre-existing test failure for GET / route (now returns version info)
- Added ESM module mocking (jsdom, marked, dompurify, @nhcarrigan/logger)
- Configured Jest with isolatedModules to handle TypeScript errors
- Excluded test-setup.ts from production build
- All tests passing (123 total)
- Build passing with no errors

## Test Plan

- [x] All tests pass (123 tests)
- [x] Build passes without errors
- [x] Lint passes (only pre-existing warnings)
- [x] Date fields work correctly on all media types
- [x] Retired status displays and filters properly
- [x] Avatar menu opens/closes correctly with keyboard and mouse
- [x] Token refresh prevents session expiry
- [x] Toast notifications appear for errors
- [x] Frontend logs forward to API successfully
- [x] Root route returns version information

Closes #41
Closes #43
Closes #44
Closes #46
Closes #1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Hikari <hikari@nhcarrigan.com>
Reviewed-on: #50
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #50.
This commit is contained in:
2026-02-19 16:52:43 -08:00
committed by Naomi Carrigan
parent 9caf74945a
commit 7579f1ec97
93 changed files with 4297 additions and 645 deletions
+195
View File
@@ -0,0 +1,195 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { CommentUser, Comment, CreateCommentDto } from "../src/lib/comment.types";
describe("comment Types", () => {
describe("commentUser interface", () => {
it("should accept valid user object with minimal fields", () => {
const user: CommentUser = {
id: "user123",
username: "testuser",
};
expect(user.avatar).toBeUndefined();
expect(user.inDiscord).toBeUndefined();
expect(user.isVip).toBeUndefined();
expect(user.isMod).toBeUndefined();
expect(user.isStaff).toBeUndefined();
});
it("should accept valid user object with all fields", () => {
const fullUser: CommentUser = {
avatar: "https://example.com/avatar.png",
id: "user456",
inDiscord: true,
isMod: true,
isStaff: false,
isVip: true,
username: "vipmoduser",
};
expect(fullUser.avatar).toBe("https://example.com/avatar.png");
expect(fullUser.inDiscord).toBeTruthy();
expect(fullUser.isVip).toBeTruthy();
expect(fullUser.isMod).toBeTruthy();
expect(fullUser.isStaff).toBeFalsy();
});
});
describe("comment interface", () => {
it("should accept valid comment object with minimal fields", () => {
const comment: Comment = {
content: "This is a great book!",
createdAt: new Date("2024-01-15"),
id: "comment123",
updatedAt: new Date("2024-01-15"),
user: {
id: "user123",
username: "bookworm",
},
userId: "user123",
};
expect(comment.rawContent).toBeUndefined();
expect(comment.gameId).toBeUndefined();
expect(comment.bookId).toBeUndefined();
expect(comment.musicId).toBeUndefined();
expect(comment.artId).toBeUndefined();
expect(comment.showId).toBeUndefined();
expect(comment.mangaId).toBeUndefined();
});
it("should accept comment for a book", () => {
const bookComment: Comment = {
bookId: "book123",
content: "<p>Amazing read!</p>",
createdAt: new Date("2024-01-20"),
id: "comment456",
rawContent: "Amazing read!",
updatedAt: new Date("2024-01-21"),
user: {
avatar: "https://example.com/reader.png",
id: "user789",
inDiscord: true,
isMod: false,
isStaff: false,
isVip: false,
username: "reader",
},
userId: "user789",
};
expect(bookComment.bookId).toBe("book123");
expect(bookComment.rawContent).toBe("Amazing read!");
expect(bookComment.gameId).toBeUndefined();
});
it("should accept comment for a game", () => {
const gameComment: Comment = {
content: "Best game ever!",
createdAt: new Date("2024-02-01"),
gameId: "game789",
id: "comment789",
updatedAt: new Date("2024-02-01"),
user: {
id: "user456",
username: "gamer",
},
userId: "user456",
};
expect(gameComment.gameId).toBe("game789");
expect(gameComment.bookId).toBeUndefined();
});
it("should accept comment for music", () => {
const musicComment: Comment = {
content: "Beautiful album",
createdAt: new Date("2024-02-10"),
id: "comment999",
musicId: "music123",
updatedAt: new Date("2024-02-10"),
user: {
id: "user111",
username: "musiclover",
},
userId: "user111",
};
expect(musicComment.musicId).toBe("music123");
});
it("should accept comment for art", () => {
const artComment: Comment = {
artId: "art456",
content: "Stunning artwork!",
createdAt: new Date("2024-02-15"),
id: "comment111",
updatedAt: new Date("2024-02-15"),
user: {
id: "user222",
username: "artcritic",
},
userId: "user222",
};
expect(artComment.artId).toBe("art456");
});
it("should accept comment for a show", () => {
const showComment: Comment = {
content: "Great series!",
createdAt: new Date("2024-02-20"),
id: "comment222",
showId: "show789",
updatedAt: new Date("2024-02-20"),
user: {
id: "user333",
username: "tvfan",
},
userId: "user333",
};
expect(showComment.showId).toBe("show789");
});
it("should accept comment for manga", () => {
const mangaComment: Comment = {
content: "Awesome manga!",
createdAt: new Date("2024-02-25"),
id: "comment333",
mangaId: "manga123",
updatedAt: new Date("2024-02-25"),
user: {
id: "user444",
username: "mangareader",
},
userId: "user444",
};
expect(mangaComment.mangaId).toBe("manga123");
});
});
describe("createCommentDto interface", () => {
it("should accept DTO with content", () => {
const createDto: CreateCommentDto = {
content: "This is my comment",
};
expect(createDto.content).toBe("This is my comment");
});
it("should accept DTO with formatted content", () => {
const createDto: CreateCommentDto = {
content: "<p>This is <strong>formatted</strong> content!</p>",
};
expect(createDto.content).toBe("<p>This is <strong>formatted</strong> content!</p>");
});
});
});