test(notifications): add unit tests for dmNotifications task - #74
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the first test coverage for
apps/notifications/src/tasks/dmNotifications.ts(previously zero tests): 23 unit tests insrc/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.tsand also under the normalnpm testin CI.Coverage
getUnreadMessages/getUnreadReactionsblast_idnull), aliasescreated_at/updated_atastimestamp, min/max cursor bounds,last_active_atguard, excludes own messages/reactionsgetNewBlaststimestamp(regression:created_at AS timestampalias from fix(notifications): send blast push notifications again #73) and a computedchat_idchat_allowedapplies to every batch — asserts the parenthesizedAND (?::INTEGER IS NULL OR to_user_id > ?)guard from fix(notifications): send blast push notifications again #73sendDMNotificationsdmNotificationMaxAgeMs): too-old messages/reactions skipped while cursors still advance; fresh ones in the same run still sent;0disables the guardblastSet): a blast older than the cutoff still reaches its whole audience while an equally old DM is skippedprocessNotificationfailure is logged without advancing cursors (retried next tick)Also exports
getUnreadMessages,getUnreadReactions,getNewBlastsfromdmNotifications.tsso 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 passnpm run typecheck— cleannpx eslinton both changed files — no errors🤖 Generated with Claude Code