test: add unit tests for domain and business logic #4
Reference in New Issue
Block a user
No description provided.
Delete Branch "add-unit-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds focused unit tests covering domain types and business logic (14 tests, 3 files).
Coverage:
inMemoryMapper:CollectCounts,GetCounts(5 table cases),GetStats(internal map vs deep copy)listCourseHandler: pagination loop (drain-full multi-batch + limited single call) + name resolutionlistCoursesStatsHandler: by-org aggregation via repo + mapper delegation branchgetCourseHandler: name resolution + error wrappingcreateCourseHandler/createCoursesHandler: param mapping + error wrappingAll tests pass with
go test ./internal/kurious/...under Go 1.26.go vetclean.Note: the generated
mocks.CourseRepositoryis stale (missingListStatistics). Tests work around this with a local wrapper; regenerating mocks would be a follow-up.📋 PR #4 — Triage Review
Files: 3 new test files, 411 lines, 14 tests
✅ What's good
ErrorIs+Containsfor error wrapping verificationstubMapperinquery_test.gois a proper test double implementing the fullCourseMapperinterfaceGetStatsdeep-copy test is thoughtful — verifies mutation isolation for bothcopyMap: trueandfalseDrainFull) exercises the real drain loop (2400 items / 3 pages)⚠️ Issues to flag
fullRepowrapper duplicated 3× — identical boilerplate inadapters/,command/,query/tests. Will be eliminated when mocks are regenerated.OrganizaitonID(missing 'n') andCourseThematicsID(extra 's') in domain types. Pre-existing, but tests now lock it in. Worth a separate cleanup issue.memory_mapper_test.go— setsm.stats,m.courseThematicByLearningType,m.totalCountdirectly. Couples tests to internal struct layout.Limit: 1001inCollectCounts— looks like a potential off-by-one. Test documents existing behavior correctly, but worth investigating.🔍 Missing coverage (non-blocking)
inMemoryMapper(plain maps, no mutex)CreateBatchpartial failure test💬 Review focus
fullRepoworkaroundOrganizaitonIDtypo renameLimit: 1001— intentional or bug?Verdict: ✅ Approve — solid test coverage, correct patterns, no bugs introduced. All issues are pre-existing or follow-up items.