Skip to content

Conversation

@ChmaraX
Copy link
Contributor

@ChmaraX ChmaraX commented Jan 20, 2026

What changed? Why was the change needed?

This pull request primarily adds new end-to-end tests for context-aware subscriber scheduling in the event trigger flow, and refactors test setup code for improved readability and maintainability. The most significant changes are grouped below:

New context-aware schedule tests for event triggers:

  • Added tests to verify that triggering events with a specific context respects the subscriber's context-specific schedule, including scenarios where schedules differ between contexts and where the default (no context) schedule is used. These tests ensure correct job cancellation and message creation based on context and schedule.
  • Updated test setup and teardown to enable and restore both IS_SUBSCRIBERS_SCHEDULE_ENABLED and the new IS_CONTEXT_PREFERENCES_ENABLED feature flags for the schedule logic tests.

@linear
Copy link

linear bot commented Jan 20, 2026

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for dashboard-v2-novu-staging canceled.

Name Link
🔨 Latest commit fc6947a
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/696f715a75cdd0000821be5c

@github-actions github-actions bot changed the title feat(api-service,worker): context aware schedule feat(api-service,worker): context aware schedule fixes NV-7064 Jan 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Walkthrough

This pull request implements context-aware scheduling for subscribers throughout the system. Changes include adding a new contextKeys optional property to GetSubscriberScheduleCommand with validation decorators, propagating contextKeys through the subscriber creation and job execution flows, and introducing context-based filtering logic in the subscriber schedule lookup using a feature flag. Environment configuration is updated to enable the IS_CONTEXT_PREFERENCES_ENABLED flag. Tests are expanded to validate context-specific scheduling behavior, including scenarios where workflows trigger with and without context, and verify that appropriate schedules are selected based on context matching.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is a template with empty sections and no concrete details about what changed or why, providing no meaningful information about the changeset. Fill in the PR description template with details about what changed, why it was needed, and any relevant context or considerations for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'feat(api-service,worker): context aware schedule' clearly describes the main change—implementing context-aware scheduling across api-service and worker components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@apps/api/src/app/events/e2e/trigger-event.e2e.ts`:
- Around line 3795-3808: The afterEach restores feature flags by assigning
stored values back to process.env which will set the literal string "undefined"
if the original was undefined; instead, check the saved variables
isSubscribersScheduleEnabled and isContextPreferencesEnabled and if a saved
value is undefined use delete (remove the env key) rather than assigning the
string, otherwise restore the saved string value to process.env—apply this logic
to the restoration lines that reference IS_SUBSCRIBERS_SCHEDULE_ENABLED and
IS_CONTEXT_PREFERENCES_ENABLED.
- Around line 4512-4710: The test fails due to invalid 12‑hour time strings
produced by createScheduleIncludingCurrentTime (e.g., "13:00 PM" or "00:00 AM");
update createScheduleIncludingCurrentTime to always output properly normalized
12‑hour times ("hh:mm AM/PM") by converting a 24h hour to (hour % 12 === 0 ? 12
: hour % 12), zero‑padding minutes, and selecting AM/PM based on the original
hour (hour < 12 -> AM else PM); ensure any place building weeklySchedule entries
uses this formatter so tests no longer produce invalid times and remain stable.

In `@apps/api/src/app/inbox/e2e/session.e2e.ts`:
- Around line 1172-1245: The test "should return context-specific schedule when
multiple contexts exist" mutates process.env.IS_CONTEXT_PREFERENCES_ENABLED
without guaranteeing cleanup; capture the original value before setting it, wrap
the test body that sets (process.env as any).IS_CONTEXT_PREFERENCES_ENABLED =
'true' and subsequent assertions in a try/finally, and in finally restore
process.env.IS_CONTEXT_PREFERENCES_ENABLED back to the original value (or delete
it if it was undefined) so the flag cannot leak to other tests; update the test
function surrounding the setup/teardown to use this pattern.

In `@apps/worker/src/.env.test`:
- Around line 98-100: Reorder the three environment keys so they follow
alphabetical order required by dotenv-linter: move
IS_CONTEXT_PREFERENCES_ENABLED to appear before IS_PUSH_UNREAD_COUNT_ENABLED,
keeping IS_SUBSCRIBERS_SCHEDULE_ENABLED as the first line; update the block
containing IS_SUBSCRIBERS_SCHEDULE_ENABLED, IS_CONTEXT_PREFERENCES_ENABLED, and
IS_PUSH_UNREAD_COUNT_ENABLED accordingly to eliminate the UnorderedKey warning.

@ChmaraX ChmaraX merged commit 67a8443 into next Jan 20, 2026
36 checks passed
@ChmaraX ChmaraX deleted the nv-7064-context-aware-schedule branch January 20, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants