Skip to content

fix(integrations.mocked): [Bug] Notification details screen shows something went wrong toast when viewing unviewed notification #778 - #860

Open
lewanp wants to merge 2 commits into
mainfrom
fix/mocked-notifications-mark-as
Open

fix(integrations.mocked): [Bug] Notification details screen shows something went wrong toast when viewing unviewed notification #778#860
lewanp wants to merge 2 commits into
mainfrom
fix/mocked-notifications-mark-as

Conversation

@lewanp

@lewanp lewanp commented Aug 10, 2026

Copy link
Copy Markdown

What does this PR do?

  • My bugfix

Related Ticket(s)

Key Changes

  • packages/integrations/mocked/src/modules/notifications/notifications.service.tsmarkAs() no longer throws NotImplementedException. It delegates to a new mapper function and returns of(undefined).pipe(responseDelay()), so the request completes with 201 instead of 501.
  • packages/integrations/mocked/src/modules/notifications/notifications.mapper.ts — new markNotificationAs() updates status and updatedAt on the in-memory mocks. It updates all three locale arrays (MOCK_NOTIFICATIONS_EN/PL/DE) because the same notification ids are shared across locales, so mutating only one would leave the mocked data inconsistent between languages.
  • Unknown notification ids are a no-op rather than an error; the mapper returns a boolean so a caller can distinguish the case if ever needed.

Side effects

  • The mocked integration is now stateful for notification status: marking a notification as viewed persists for the lifetime of the API process (reset on restart). This is intentional — the notification list and summary now reflect the change, matching how a real integration behaves.
  • No changes to the frontend. NotificationDetails.client.tsx keeps its error toast, which is still correct for genuine network failures — the bug was purely in the backend mock.
  • No public API, signature, or contract changes. @o2s/integrations.mocked is the only integration implementing Notifications.Service, so no other integration is affected.
  • Includes a patch changeset for @o2s/integrations.mocked.

How to test

No migrations or new dependencies needed.

  1. npm run dev and log in as john@example.com / user (default org: Tech Solutions Inc, cust-002, which has the notifications:mark_read permission).
  2. Open the notifications list and click any notification with the "Not viewed" status.
  3. Expected: the details screen renders with no "Something went wrong" toast. Going back to the list shows the notification as "Viewed".

Alternatively, against the API directly (AUTH_JWT_SECRET=secret from apps/api-harmonization/.env.local), with a JWT whose customer.permissions grants notifications: ['view', 'mark_read']:

# before: "UNVIEWED"
curl -s "http://localhost:3001/api/blocks/notification-details/NOT-123-456?locale=en" \
  -H "Authorization: Bearer $TOKEN" -H "x-locale: en"

# was 501 Not Implemented, now 201 with an empty body
curl -i -X POST "http://localhost:3001/api/blocks/notification-details" \
  -H "Authorization: Bearer $TOKEN" -H "x-locale: en" -H "Content-Type: application/json" \
  -d '{"id":"NOT-123-456","status":"VIEWED"}'

# after: "VIEWED" — also for ?locale=pl and ?locale=de
curl -s "http://localhost:3001/api/blocks/notification-details/NOT-123-456?locale=en" \
  -H "Authorization: Bearer $TOKEN" -H "x-locale: en"

Verified on a running api-harmonization instance: 201 on the POST, status flips to VIEWED in all three locales, and a token without mark_read (prospect on cust-003) is still rejected by the permission guard with Missing required permissions: notifications:mark_read. tsc --noEmit and eslint --max-warnings=0 are clean, and the existing @o2s/integrations.mocked test suite passes (28/28).

Media (Loom or gif)

  • N/A

Summary by CodeRabbit

  • Bug Fixes
    • Opening an unread notification now marks it as viewed successfully.
    • Removed the error toast previously shown when marking notifications as viewed.
    • Notification status and timestamp updates now work consistently across supported languages.

…rvice

Opening an unviewed notification triggers an automatic mark-as-read request from
NotificationDetails.client.tsx for users with the mark_read permission. The mocked
Notifications service threw NotImplementedException, so the request failed and the
frontend showed a "Something went wrong" toast.

markAs now updates the notification status in the in-memory mocks (across all locale
variants, since ids are shared) and completes successfully.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03ca4f59-d18b-4a02-a783-782267c0941a

📥 Commits

Reviewing files that changed from the base of the PR and between b358ce4 and 459b871.

📒 Files selected for processing (1)
  • .changeset/mocked-notifications-mark-as.md

Walkthrough

The mocked notifications integration now updates notification status and timestamps across localized collections. The service delegates requests to the mapper and returns a delayed void observable instead of throwing an exception.

Changes

Notification status marking

Layer / File(s) Summary
Localized notification update
packages/integrations/mocked/src/modules/notifications/notifications.mapper.ts
Adds markNotificationAs, which updates matching notifications in English, Polish, and German collections with the requested status and a shared current ISO timestamp.
Mark-as service integration
packages/integrations/mocked/src/modules/notifications/notifications.service.ts, .changeset/mocked-notifications-mark-as.md
The service delegates markAs to the mapper and returns a delayed undefined observable. The changeset records the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit marks notes, three locales in line,
Each gets a status and timestamp sign.
The service completes with no error toast,
While unviewed notes are no longer lost.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the mocked Notifications bug and the user-visible error when viewing an unviewed notification.
Description check ✅ Passed The description includes all template sections and provides clear implementation details, side effects, and reproducible test steps.
Linked Issues check ✅ Passed The changes implement markAs successfully, prevent the error toast, and mark notifications as viewed as required by issue #778.
Out of Scope Changes check ✅ Passed All changes support issue #778 and the stated objective, including mapper updates, service behavior, locale consistency, and the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mocked-notifications-mark-as

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.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report for packages/configs/vitest-config

Status Category Percentage Covered / Total
🔵 Lines 78.27% 1740 / 2223
🔵 Statements 77.15% 1830 / 2372
🔵 Functions 74.89% 519 / 693
🔵 Branches 65.68% 1148 / 1748
File CoverageNo changed files found.
Generated in workflow #727 for commit 459b871 by the Vitest Coverage Report Action

* so all locale variants are updated to keep the mocked data consistent.
* Returns `true` when a notification with the given id was found.
*/
export const markNotificationAs = (request: Notifications.Request.MarkNotificationAsRequest): boolean => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does this mean that once marked as viewed, it will stay that way until nestjs app restarts? i'm not sure if this is a desired behavior, as for mocked/demo purposes it should be possible to "retry" marking it as viewed from time to time without having to restart/redeploy the app; perhaps some timeout could be added that switched back to unviewed state after e.g. 5min?

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.

[Bug] Notification details screen shows something went wrong toast when viewing unviewed notification

2 participants