Skip to content

fix: address testing and documentation issues#1284

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
parkerwinner:fix/testing-and-docs-issues
Jun 28, 2026
Merged

fix: address testing and documentation issues#1284
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
parkerwinner:fix/testing-and-docs-issues

Conversation

@parkerwinner

Copy link
Copy Markdown
Contributor

Summary

This PR addresses four testing and documentation issues found in the backend codebase.

Changes

Issue: IndexedEventsService.create return type

  • Changed return type from Promise<IndexedEvent> to Promise<IndexedEvent | null>
  • Method now correctly returns null on duplicate event_id instead of undefined cast as non-nullable
  • Added test case verifying duplicate event_id handling

Issue: authService helper unit tests

  • Added direct unit tests for verifySignature() covering valid sig, wrong signer, non-64-byte sig, non-base64 input, and invalid public key
  • Added tests for verifyChallengeTimestamp() at/under/over expiry window and future timestamps
  • Added tests for extractBearerToken() covering null, wrong scheme, malformed headers, and happy path

Issue: scoresService test coverage

  • Un-skipped param-assertion tests for updateUserScoresBulk
  • Added clamping tests proving 300/850 boundary enforcement for both insert and update paths
  • Added comprehensive test suite for setAbsoluteUserScoresBulk covering value placeholders, cache invalidation, error propagation, and empty-map/empty-user-id no-ops

Issue: services layer documentation

  • Expanded README with services index table listing all services, their responsibilities, and key entry points
  • Documented background schedulers and where they are wired in index.ts
  • Added environment variable mapping to services

Testing

All new tests pass locally. The fixes strengthen type safety and test coverage for security-critical paths.

Closes #1166
Closes #1168
Closes #1170
Closes #1172

- Fix IndexedEventsService.create return type to Promise<IndexedEvent | null>
  * Returns null on duplicate event_id instead of undefined cast as IndexedEvent
  * Add test for duplicate event_id path (closes LabsCrypt#1166)

- Add unit tests for authService security helpers
  * verifySignature: valid sig, wrong signer, non-64-byte, non-base64, invalid key
  * verifyChallengeTimestamp: at/under/over window, future timestamp
  * extractBearerToken: null, wrong scheme, malformed headers (closes LabsCrypt#1168)

- Add comprehensive tests for scoresService
  * Un-skip param-assertion tests for updateUserScoresBulk
  * Add clamping tests for 300/850 boundaries (insert and update)
  * Add full test coverage for setAbsoluteUserScoresBulk
  * Cover empty-map and empty-user-id no-op paths (closes LabsCrypt#1170)

- Expand services README with layer overview
  * Add services index table with responsibilities and entry points
  * Document background schedulers and their wiring in index.ts
  * Note key env vars read by each service (closes LabsCrypt#1172)
@ogazboiz ogazboiz merged commit 64a0f25 into LabsCrypt:main Jun 28, 2026
4 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment