refactor(utils): one PgTextString for the four pgtype.Text unwrappers

handlers textToString, router textToString, router getText, and utils
normText were four copies of the same NULL-to-empty unwrap (99 call
sites). One exported utils.PgTextString replaces them all; the private
normText (comparison normalizer) stays but is now the odd one out.

Harness fix found on the way: setupTestServer built a full wiring
literal for route registration and then RETURNED a second, sparser
literal that never copied AnnotationService — setup.AnnotationService
was always nil on the struct every test receives. Nobody noticed until
cross_library_move_test became the first caller (it previously used
the now-retired plain CreateMediaHighlight query); it now exercises
the real SaveHighlight path through the wired service.
This commit is contained in:
John O'Keefe committed 2026-10-17 16:36:58 -04:00
1 parent 00305ffc7b
commit 188ae076ab
15 files changed
+140 -139

No files matched your search

+9 -4
View File
@@ -12,6 +12,7 @@ import (
"bookhoard/internal/database"
"bookhoard/internal/services"
wsync "bookhoard/internal/sync"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
@@ -160,11 +161,13 @@ func TestCrossLibraryMovePreservesHistory(t *testing.T) {
TotalPages: pgtype.Int4{Int32: 300, Valid: true},
})
require.NoError(t, err)
_, err = setup.DB.CreateMediaHighlight(ctx, database.CreateMediaHighlightParams{
_, err = setup.AnnotationService.SaveHighlight(ctx, wsync.SaveHighlightRequest{
MediaItemID: original.ID,
UserID: adminPgID,
SelectionText: "a line worth keeping",
Color: pgtype.Text{String: "#ffff00", Valid: true},
Color: "#ffff00",
Source: "web",
ModifiedAt: time.Now(),
})
require.NoError(t, err)
@@ -419,11 +422,13 @@ func archiveAndIsolate(t *testing.T, setup *TestServerSetup, adminID, adminPgID
TotalPages: pgtype.Int4{Int32: 200, Valid: true},
})
require.NoError(t, err)
_, err = setup.DB.CreateMediaHighlight(ctx, database.CreateMediaHighlightParams{
_, err = setup.AnnotationService.SaveHighlight(ctx, wsync.SaveHighlightRequest{
MediaItemID: item.ID,
UserID: adminPgID,
SelectionText: "annotation on the old copy",
Color: pgtype.Text{String: "#00ff00", Valid: true},
Color: "#00ff00",
Source: "web",
ModifiedAt: time.Now(),
})
require.NoError(t, err)
+13 -12
View File
@@ -710,18 +710,19 @@ func setupTestServer(t *testing.T) *TestServerSetup {
// Create TestServerSetup struct with all resources
setup := &TestServerSetup{
Server: ts,
DB: queries,
DBPool: dbPool,
Config: cfg,
ConnManager: connManager,
QueueProcessor: queueProcessor,
ProgressService: progressService,
CleanupCancel: cleanupCancel,
QueueCtx: queueCtx,
QueueCancel: queueCancel,
Token: adminToken,
RegularToken: regularToken,
Server: ts,
DB: queries,
DBPool: dbPool,
Config: cfg,
ConnManager: connManager,
QueueProcessor: queueProcessor,
ProgressService: progressService,
AnnotationService: annotationService,
CleanupCancel: cleanupCancel,
QueueCtx: queueCtx,
QueueCancel: queueCancel,
Token: adminToken,
RegularToken: regularToken,
}
// Register cleanup function to run automatically when test completes