Skip to content

Conversation

oguzkocer
Copy link
Contributor

@oguzkocer oguzkocer commented Jun 26, 2025

Why

The current Subscriber type is missing several fields that are returned by the WordPress.com API, causing incomplete data representation and potential parsing failures. This PR ensures we can properly handle all subscriber data fields.

What Changed

New Fields Added to Subscriber

  • subscription_id - Unique identifier for the subscription
  • is_email_subscriber - Boolean flag for email-only subscribers
  • url - Subscriber's website URL
  • country - Subscriber's country information
  • plans - List of subscription plans

New Types

  • SubscriberCountry - Represents country data with code and name
  • SubscriptionPlan - Contains plan details including ID and name

Bug Fixes

  • Fixed serialization values for EmailAddress & DisplayName in ListSubscribersSortField
  • Updated /sites/<wp_com_site_id>/subscribers/individual endpoint to properly return Subscriber type

Type Safety Improvements

  • Made appropriate Subscriber fields optional to match API responses
  • Updated GetSubscriberQuery to use strongly-typed UserId & SubscriptionId

Testing

We don't have an infrastructure to run integration tests for WordPress.com endpoints. This makes it very difficult to ensure that the implementation is correct and introduces a lot of manual testing overhead during development. To improve this situation, this PR introduces a basic setup that allows a developer to copy the wp_com_test_credentials.json-example as wp_com_test_credentials.json to run relevant tests.

The PR introduces a few tests for subscribers endpoint, however they all have the #[ignore] flag and won't be run by default. If a developer has the correct credentials & ids in wp_com_test_credentials.json, they can run the tests with:

cargo test -p wp_api_integration_tests --test 'test_wp_com_subscribers_immut' -- --ignored

I have considered adding instructions for this in the README, but I'd like this to be a temporary solution and I have some concerns about having WordPress.com specific instructions, so at least for this PR, I decided to skip this step.

Additional Test Changes

  • Added unit tests for parsing subscribers with plans

Breaking Changes

  • Some Subscriber fields are now Option<T> - existing code may need updates
  • GetSubscriberQuery now uses typed IDs instead of raw strings

@oguzkocer oguzkocer added this to the 0.2 milestone Jun 26, 2025
@oguzkocer oguzkocer marked this pull request as ready for review June 26, 2025 05:37
@oguzkocer oguzkocer enabled auto-merge (squash) June 26, 2025 05:37
@oguzkocer oguzkocer disabled auto-merge June 26, 2025 05:37
@oguzkocer oguzkocer marked this pull request as draft June 26, 2025 05:37
@oguzkocer oguzkocer marked this pull request as ready for review June 26, 2025 20:46
@oguzkocer oguzkocer enabled auto-merge (squash) June 26, 2025 20:46
@oguzkocer oguzkocer requested a review from crazytonyli June 26, 2025 20:47
@oguzkocer oguzkocer merged commit 4d24008 into trunk Jun 26, 2025
20 checks passed
@oguzkocer oguzkocer deleted the add-missing-fields-to-subscribers branch June 26, 2025 20:55
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