Skip to content
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

Add - Product View Report Test #2261

Merged

Conversation

jorgemd24
Copy link
Contributor

@jorgemd24 jorgemd24 commented Feb 19, 2024

Changes proposed in this Pull Request:

Part of #2146 & #2250

This PR introduces:

  • Tests for the Product View Report.
  • Removed the product_view.offer_id from the MerchantQuery, as we're using the MC-ID to extract the offerID. The product_view.id is necessary in the query and cannot be removed.
  • I've updated the default placeholder for $product_view_data from next_page to next_page_token to maintain consistency with the rest of the code.

It looks like the report for free listings isn't covered by tests, so I'll create a follow-up issue to add tests for that section.

Detailed test instructions:

  1. Run the tests ./vendor/bin/phpunit

Changelog entry

@jorgemd24 jorgemd24 self-assigned this Feb 19, 2024
@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Feb 19, 2024
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7f3571f) 59.7% compared to head (6a9a0f9) 59.9%.
Report is 14 commits behind head on feature/refactor-product-stats.

Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##             feature/refactor-product-stats   #2261     +/-   ##
==================================================================
+ Coverage                              59.7%   59.9%   +0.3%     
- Complexity                             4176    4178      +2     
==================================================================
  Files                                   457     457             
  Lines                                 17701   17708      +7     
==================================================================
+ Hits                                  10559   10611     +52     
+ Misses                                 7142    7097     -45     
Flag Coverage Δ
php-unit-tests 59.9% <95.2%> (+0.3%) ⬆️

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

Files Coverage Δ
src/API/Google/MerchantReport.php 34.2% <100.0%> (+34.2%) ⬆️
...PI/Google/Query/MerchantProductViewReportQuery.php 86.7% <ø> (+86.7%) ⬆️
src/MerchantCenter/MerchantStatuses.php 50.0% <94.1%> (-1.6%) ⬇️

... and 4 files with indirect coverage changes

@jorgemd24 jorgemd24 requested a review from a team February 19, 2024 10:54
@jorgemd24 jorgemd24 marked this pull request as ready for review February 19, 2024 10:55
Copy link
Contributor

@martynmjones martynmjones left a comment

Choose a reason for hiding this comment

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

Hey @jorgemd24, thanks for your work on these tests.

I've left a few comments but nothing is blocking and all tests are passing locally so approving ✅

Comment on lines 88 to 95
$page_size = 800;

add_filter(
'woocommerce_gla_product_view_report_page_size',
function () use ( $page_size ) {
return $page_size;
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you clarify why we're using the woocommerce_gla_product_view_report_page_size filter here? From what I can tell it has no impact on the test itself so is the intention of this to give a more complete picture of the functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so is the intention of this to give a more complete picture of the functionality?

That's right, this way allows me to test that the filter is used to set the page size, and that the search is receiving the correct page size.

https://github.com/woocommerce/google-listings-and-ads/pull/2261/files#diff-91e7d57ff211a17cd8684387ddd428407e3530dfca1487dd2ccc4fa022bec0eaR146

}

public function test_get_product_view_report_with_exception() {
$this->options->method( 'get_merchant_id' )->willReturn( 432 );
Copy link
Contributor

Choose a reason for hiding this comment

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

We're also setting the return value for get_merchant_id on the options mock in test_get_product_view_report but beyond that we don't do anything with it so instead of repeating this had you considered creating a class property for it and then assigning it to the mock in setUp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, I added here: 6a9a0f9

*
* @param string $mc_id The MC center id.
* @param string $status The status of the product.
* @param DateTime|null $expiration_date The expiration date of the product.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the $expiration_date parameter? When we set up the product view's in test_get_product_view_report it's not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use the $expiration_date to create a "GoogleDate", which is then used to simulate the expiration_date here:

https://github.com/woocommerce/google-listings-and-ads/pull/2261/files#diff-91e7d57ff211a17cd8684387ddd428407e3530dfca1487dd2ccc4fa022bec0eaR160

I could set a DateTime in the expiration_date response, but I believe this way allows us to simulate a more realistic scenario.

Base automatically changed from add/replace-wp-posts-functions-with-wc-objects to feature/refactor-product-stats February 20, 2024 15:39
@jorgemd24 jorgemd24 merged commit a0aed9b into feature/refactor-product-stats Feb 20, 2024
11 checks passed
@jorgemd24 jorgemd24 deleted the add/merchant-center-report-test branch February 20, 2024 16:31
@eason9487 eason9487 mentioned this pull request Mar 26, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants