Skip to content

Add subscriptions integration tests (4603) #3425

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

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

mmaymo
Copy link
Collaborator

@mmaymo mmaymo commented May 28, 2025

This PR introduces a new IntegrationMockedTestCase class for testing and enhances the existing PayPalSubscriptionsRenewalTest class with more test coverage.
The new class provides reusable testing infrastructure including methods for creating mock orders, subscriptions, payment tokens, and simulating PayPal API responses. The PR expands the subscription renewal tests with detailed assertions for various scenarios including transaction ID handling, payment method consistency, subscription status changes, and parent order updates. Tests now follow a more structured Given-When-Then format with documentation of test intentions and expected behaviours.

Captura de pantalla 2025-05-28 a las 9 22 38 Captura de pantalla 2025-05-28 a las 9 21 13

mmaymo added 4 commits May 12, 2025 19:01
scenarios:
- Preventing duplicate renewals for recent subscriptions
- Creating renewal orders for subscriptions older than 8 hours
- Handling subscriptions with explicit renewal meta
- Ensuring payment methods are correctly transferred to renewal orders
- Verifying transaction IDs are properly set on orders
- Managing subscription status transitions during renewal
- Handling edge cases like missing parent orders and empty subscription arrays
Copy link
Collaborator

@Dinamiko Dinamiko left a comment

Choose a reason for hiding this comment

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

Overall looks great, just a couple of small notes:

  1. CI is failing, maybe we can skip those failing tests on CI for now.
  2. There is no cleanup for created database records (orders, subscriptions...), we can skip this for this PR as probably there are also other existing tests that does no clean the database, so I suggest to create a separated PR for ensuring db records are cleared after each test.

public function createCustomerIfNotExists(int $customer_id= 1): int
{
$customer = new \WC_Customer($customer_id);
if (! empty($customer->get_email() )) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this condition correct? or should be inverted?

$mockOrderEndpoint = $this->mockOrderEndpoint('CAPTURE', true);
$c = $this->setupTestContainer($mockOrderEndpoint);

$paymentToken = $this->setupPaymentToken($this->customer_id, $gateway_id);
Copy link
Collaborator

@Dinamiko Dinamiko May 28, 2025

Choose a reason for hiding this comment

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

$paymentToken seems not used in this test.

$mockOrderEndpoint = $this->mockOrderEndpoint('CAPTURE', false);
$c = $this->setupTestContainer($mockOrderEndpoint);

$paymentToken = $this->setupPaymentToken($this->customer_id, PayPalGateway::ID);
Copy link
Collaborator

@Dinamiko Dinamiko May 28, 2025

Choose a reason for hiding this comment

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

$paymentToken seems not used in this test.

$c = $this->setupTestContainer($mockOrderEndpoint);

// Setup payment token and subscription
$paymentToken = $this->setupPaymentToken($this->customer_id, PayPalGateway::ID);
Copy link
Collaborator

@Dinamiko Dinamiko May 28, 2025

Choose a reason for hiding this comment

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

$paymentToken seems not used in this test.

public function test_process_empty_subscriptions_array()
{
$c = $this->getContainer();
$logger = $c->get('woocommerce.logger.woocommerce');
Copy link
Collaborator

Choose a reason for hiding this comment

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

$logger seems not used in this test.

@mmaymo
Copy link
Collaborator Author

mmaymo commented Jun 2, 2025

Yeah I will create myself an issue to handle preconditions and teardown of all the tests

@mmaymo mmaymo requested a review from Dinamiko June 2, 2025 12:51
*/
public function mockOrderEndpoint(string $intent = 'CAPTURE', bool $success = true): object
{
$order_endpoint = $this->getMockBuilder(OrderEndpoint::class)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we were using Mockery in most of the tests in this project. Should we maybe continue that for consistency, or should we switch to PHPUnit mocks? I am not sure if they have any significant difference.

*/
public function test_vaulting_is_enabled_when_subscription_mode_is_vaulting_api()
{
add_filter('user_has_cap', function ($allcaps, $caps, $args) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This filter is not being removed, might cause test pollution

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.

4 participants