Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ protected function get_items_for_batch( int $batch_number, array $args ): array
$offset = ( $batch_number - 1 ) * $batch_size;

$query_args = array(
'number' => $batch_size,
'offset' => $offset,
'status' => 'approve',
'number' => $batch_size,
'offset' => $offset,
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

return FeedUploadUtils::get_ratings_and_reviews_data( $query_args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function __construct( AbstractFeedFileWriter $feed_writer ) {
*/
public function get_feed_data(): array {
$query_args = array(
'status' => 'approve',
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

return FeedUploadUtils::get_ratings_and_reviews_data( $query_args );
Expand Down
57 changes: 44 additions & 13 deletions tests/Unit/Feed/FeedUploadUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ public function test_get_ratings_and_reviews_data_valid_review() {
// Create a review comment.
$comment_id = self::factory()->comment->create( [
'comment_post_ID' => $product_id,
'comment_type' => 'review',
'comment_date' => '2023-10-01 10:00:00',
'comment_content' => 'Awesome product!',
'comment_author' => 'John Doe',
'user_id' => 0,
] );
update_comment_meta( $comment_id, 'rating', 5 );

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] );
//Query arguments to fetch R&R data
$query_args = array(
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args );

$expected_review = [
'aggregator' => 'woocommerce',
Expand Down Expand Up @@ -83,7 +91,14 @@ public function test_get_ratings_and_reviews_data_non_product_review() {
] );
update_comment_meta( $comment_id, 'rating', 4 );

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] );
//Query arguments to fetch R&R data
$query_args = array(
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args );
$this->assertEmpty( $result, 'Expected no review for a non-product comment.' );
}

Expand All @@ -100,13 +115,21 @@ public function test_get_ratings_and_reviews_data_no_rating_review() {
// Create a comment without a valid rating.
$comment_id = self::factory()->comment->create( [
'comment_post_ID' => $product_id,
'comment_type' => 'review',
'comment_date' => '2023-10-01 10:00:00',
'comment_content' => 'I did not rate this product.',
'comment_author' => 'Alice',
'user_id' => 3,
] );

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] );
//Query arguments to fetch R&R data
$query_args = array(
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args );
$this->assertEmpty( $result, 'Expected no review when rating is missing.' );
}

Expand All @@ -115,14 +138,22 @@ public function test_get_ratings_and_reviews_data_invalid_product() {
$invalid_product_id = 999999;
$comment_id = self::factory()->comment->create( [
'comment_post_ID' => $invalid_product_id,
'comment_type' => 'review',
'comment_date' => '2023-10-01 12:00:00',
'comment_content' => 'Product does not exist.',
'comment_author' => 'Bob',
'user_id' => 4,
] );
update_comment_meta( $comment_id, 'rating', 3 );

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] );
//Query arguments to fetch R&R data
$query_args = array(
'status' => 'approve',
'post_type' => 'product',
'comment_type' => 'review',
);

$result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args );
$this->assertEmpty( $result, 'Expected no review for comment with invalid product.' );
}

Expand Down Expand Up @@ -168,7 +199,7 @@ public function test_get_coupons_data_valid_coupon_with_target_product() {
// Build the expected coupon shape according to how FeedUploadUtils outputs the data.
$expected_coupon = [
'offer_id' => $coupon_id, // coupon ID as an integer
'title' => 'coupon-code-1', // lowercased coupon post title
'title' => 'COUPON-CODE-1', // uppercase coupon post title
'value_type' => 'PERCENTAGE',
'percent_off' => '15', // as a string
'fixed_amount_off' => '', // empty string output
Expand All @@ -178,7 +209,7 @@ public function test_get_coupons_data_valid_coupon_with_target_product() {
'target_selection' => 'SPECIFIC_PRODUCTS',
'start_date_time' => $coupon_data['start_date_time'], // use the output from the coupon post date/time
'end_date_time' => '',
'coupon_codes' => ['coupon-code-1'],
'coupon_codes' => ['COUPON-CODE-1'],
'public_coupon_code' => '',
'target_filter' => '{"or":[{"retailer_id":{"eq":"product-sku-1_'.$product1->get_id().'"}}]}',
'target_product_retailer_ids' => '',
Expand Down Expand Up @@ -234,7 +265,7 @@ public function test_get_coupons_data_valid_shipping_coupon() {
// Build the expected coupon shape according to how FeedUploadUtils outputs the data.
$expected_coupon = [
'offer_id' => $coupon_id, // coupon ID as an integer
'title' => 'coupon-code-1', // lowercased coupon post title
'title' => 'COUPON-CODE-1', // uppercase coupon post title
'value_type' => 'PERCENTAGE',
'fixed_amount_off' => '0', // empty string output
'percent_off' => '100', // as a string
Expand All @@ -244,7 +275,7 @@ public function test_get_coupons_data_valid_shipping_coupon() {
'target_selection' => 'ALL_CATALOG_PRODUCTS',
'start_date_time' => $coupon_data['start_date_time'], // use the output from the coupon post date/time
'end_date_time' => '',
'coupon_codes' => ['coupon-code-1'],
'coupon_codes' => ['COUPON-CODE-1'],
'public_coupon_code' => '',
'target_filter' => '',
'target_product_retailer_ids' => '',
Expand Down Expand Up @@ -326,7 +357,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_products() {
// Build the expected coupon shape.
$expected_coupon = [
'offer_id' => $coupon_id, // coupon ID as an integer
'title' => 'coupon-incl-excl', // lowercased coupon post title
'title' => 'COUPON-INCL-EXCL', // uppercase coupon post title
'value_type' => 'PERCENTAGE',
'percent_off' => '20', // as a string
'fixed_amount_off' => '', // empty string output
Expand All @@ -336,7 +367,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_products() {
'target_selection' => 'SPECIFIC_PRODUCTS',
'start_date_time' => $coupon_data['start_date_time'], // use the generated start date/time
'end_date_time' => '',
'coupon_codes' => ['coupon-incl-excl'], // coupon_codes as an array containing the title
'coupon_codes' => ['COUPON-INCL-EXCL'], // coupon_codes as an array containing the title
'public_coupon_code' => '',
'target_filter' => '{"and":[{"or":[{"retailer_id":{"eq":"product-sku-1_'.$product1->get_id().'"}},{"retailer_id":{"eq":"product-sku-2_'.$product2->get_id().'"}}]},{"and":[{"retailer_id":{"neq":"product-sku-3_'.$product3->get_id().'"}}]}]}',
'target_product_retailer_ids' => '',
Expand Down Expand Up @@ -435,8 +466,8 @@ public function test_get_coupons_data_coupon_with_included_excluded_categories()

// Build the expected coupon shape.
$expected_coupon = [
'offer_id' => $coupon_id, // coupon ID as an integer
'title' => 'coupon-cat-only', // lowercased coupon post title
'offer_id' => $coupon_id, // coupon ID as an integer
'title' => 'COUPON-CAT-ONLY', // uppercase coupon post title
'value_type' => 'PERCENTAGE',
'percent_off' => '15', // as a string
'fixed_amount_off' => '', // empty string output
Expand All @@ -446,7 +477,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_categories()
'target_selection' => 'SPECIFIC_PRODUCTS',
'start_date_time' => $coupon_data['start_date_time'], // generated start date/time
'end_date_time' => '',
'coupon_codes' => ['coupon-cat-only'], // coupon_codes as an array containing the code
'coupon_codes' => ['COUPON-CAT-ONLY'], // coupon_codes as an array containing the code
'public_coupon_code' => '',
'target_filter' => $expected_target_filter,
'target_product_retailer_ids' => '',
Expand Down