Skip to content

test(notifications): add unit tests for dmNotifications task - #74

Merged
dylanjeffers merged 1 commit into
mainfrom
test/dm-notifications-tests
Jul 16, 2026
Merged

test(notifications): add unit tests for dmNotifications task#74
dylanjeffers merged 1 commit into
mainfrom
test/dm-notifications-tests

Conversation

@dylanjeffers

Copy link
Copy Markdown
Contributor

Summary

Adds the first test coverage for apps/notifications/src/tasks/dmNotifications.ts (previously zero tests): 23 unit tests in src/tasks/__tests__/dmNotifications.test.ts.

Unlike the existing integration suite (which needs template Postgres DBs + Redis via audius-compose), these are pure unit tests: a small chainable Knex mock records each query's builder calls / raw SQL / bindings, and Redis is an in-memory map. They run standalone with npx jest src/tasks/__tests__/dmNotifications.test.ts and also under the normal npm test in CI.

Coverage

getUnreadMessages / getUnreadReactions

  • returns the unread rows; empty results
  • query shape: excludes blasts (blast_id null), aliases created_at/updated_at as timestamp, min/max cursor bounds, last_active_at guard, excludes own messages/reactions

getNewBlasts

sendDMNotifications

  • pushes sent for messages, reactions, and blasts; all Redis cursors advanced
  • notifications processed in ascending timestamp order
  • age guard (dmNotificationMaxAgeMs): too-old messages/reactions skipped while cursors still advance; fresh ones in the same run still sent; 0 disables the guard
  • blast exemption from the age guard (blastSet): a blast older than the cutoff still reaches its whole audience while an equally old DM is skipped
  • empty run initializes cursors; cached Redis timestamps become the query min-bounds; a processNotification failure is logged without advancing cursors (retried next tick)

Also exports getUnreadMessages, getUnreadReactions, getNewBlasts from dmNotifications.ts so they can be tested directly (no behavior change).

Note: written with jest, not vitest — this app's suite runs on jest (npm test), and adding a second runner would leave these tests out of CI.

Test plan

  • cd apps/notifications && npx jest src/tasks/__tests__/dmNotifications.test.ts — 23/23 pass
  • npm run typecheck — clean
  • npx eslint on both changed files — no errors

🤖 Generated with Claude Code

Covers getUnreadMessages, getUnreadReactions, getNewBlasts, and
sendDMNotifications with a mocked Knex query recorder and in-memory
Redis, including regressions from #73 (blast created_at AS timestamp
alias, parenthesized chat_allowed guard) and the blast exemption from
the DM max-age cutoff. Exports the three query helpers for direct
testing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dylanjeffers
dylanjeffers merged commit 7c1ee0b into main Jul 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant