Skip to content

Add blog_id to all notification messages (INTEGRA-49) #2989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

budzanowski
Copy link
Collaborator

Summary

Implements INTEGRA-49 by adding blog_id to all notification messages sent to WPCOM endpoints. This enables the WPCOM notification proxy to properly work with the new client credentials authentication flow.

Problem

The current notification system sends messages to WPCOM without including the blog_id in the message body. While the blog_id is embedded in the URL endpoint, the WPCOM proxy system requires it in the message payload to properly route notifications in the client credentials authentication model.

Solution

  1. Added blog_id property to NotificationsService class
  2. Modified constructor to store the blog_id from Jetpack_Options::get_option('id')
  3. Updated notify() method to include blog_id in all notification message bodies
  4. Updated tests to expect blog_id in request verification

Changes Made

NotificationsService.php

  • Added private $blog_id property to store WordPress.com blog ID
  • Modified constructor to store blog_id instead of just using it in URL
  • Updated notify() method to include blog_id in message body alongside item_id

NotificationsServiceTest.php

  • Updated test expectation to include blog_id in request body verification
  • Uses existing DUMMY_BLOG_ID constant for test consistency

Message Format Changes

Before:

'body' => array_merge($data, ['item_id' => $item_id])

After:

'body' => array_merge($data, [
    'item_id' => $item_id,
    'blog_id' => $this->blog_id,
])

Affected Notification Types

This change affects all notification types automatically:

  • Product notifications (create/update/delete)
  • Coupon notifications (create/update/delete)
  • Shipping notifications (update)
  • Settings notifications (update)

WPCOM Compatibility

The WPCOM counterpart already handles additional data in the request body:

private function get_data() {
    $body = json_decode($this->request->get_body() ?? '', true);
    $id   = $body['item_id'];
    unset($body['item_id']);
    return array_merge($body, ['id' => $id]);
}

This means the blog_id will be preserved and passed through to the notification processing logic.

Test Plan

  • ✅ PHP coding standards pass
  • ✅ Updated test expects blog_id in notification body
  • ✅ All notification types automatically include blog_id
  • Verify WPCOM proxy properly receives and processes blog_id
  • Test notification flow with client credentials authentication

Impact

  • Zero breaking changes - purely additive enhancement
  • Backward compatible - WPCOM endpoints handle additional data gracefully
  • Automatic coverage - all existing notification flows get blog_id inclusion
  • Enables client credentials - satisfies WPCOM proxy requirements

Related Issues

  • INTEGRA-49: Add blog_id to notification messages
  • INTEGRA-30: Overall client credentials migration project
  • Supports the broader effort to migrate from OAuth to client credentials authentication

🤖 Generated with Claude Code

- Add blog_id property to NotificationsService class
- Include blog_id in all notification message bodies sent to WPCOM
- Update NotificationsServiceTest to expect blog_id in request body
- Enables WPCOM notification proxy to work with client credentials flow

This change ensures all notification messages include the WordPress.com
blog_id in their payload, which is required for the WPCOM proxy system
to properly route notifications in the new client credentials
authentication flow.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.2%. Comparing base (e5982a4) to head (2062bc5).
Report is 2 commits behind head on test/combined-branches.

Additional details and impacted files

Impacted file tree graph

@@                   Coverage Diff                    @@
##             test/combined-branches   #2989   +/-   ##
========================================================
  Coverage                      66.2%   66.2%           
  Complexity                     4837    4837           
========================================================
  Files                           826     826           
  Lines                         25808   25814    +6     
  Branches                       1269    1269           
========================================================
+ Hits                          17074   17080    +6     
  Misses                         8581    8581           
  Partials                        153     153           
Flag Coverage Δ
js-unit-tests 66.4% <ø> (ø)
php-unit-tests 66.1% <100.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/API/WP/NotificationsService.php 97.9% <100.0%> (+0.1%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@budzanowski budzanowski changed the base branch from develop to test/combined-branches June 27, 2025 03:47
@budzanowski budzanowski merged commit 1608578 into test/combined-branches Jun 27, 2025
16 checks passed
@budzanowski budzanowski deleted the feature/integra-49-add-blog-id-to-notifications branch June 27, 2025 03:49
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