Skip to content

Commit

Permalink
Add WPCOM tests for product attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemd24 committed Apr 11, 2024
1 parent 76298ec commit d2d8b32
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Unit/Integration/WPCOMProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function test_get_products() {

$this->assertEquals( $product_1->get_id(), $response->get_data()[0]['id'] );
$this->assertEquals( $expected_metadata, $this->format_metadata( $response->get_data()[0]['meta_data'] ) );
$this->assertArrayHasKey( 'gla_attributes', $response->get_data()[0] );
}

public function test_get_products_with_gla_syncable_false() {
Expand All @@ -143,6 +144,7 @@ public function test_get_products_with_gla_syncable_false() {

$this->assertEquals( $this->get_test_metadata(), $this->format_metadata( $response_mapped[ $product_1->get_id() ]['meta_data'] ) );
$this->assertEquals( $this->get_test_metadata( ChannelVisibility::DONT_SYNC_AND_SHOW ), $this->format_metadata( $response_mapped[ $product_2->get_id() ]['meta_data'] ) );
$this->assertArrayNotHasKey( 'gla_attributes', $response->get_data()[0] );
}

public function test_get_products_without_gla_visibility_metadata() {
Expand All @@ -164,6 +166,7 @@ public function test_get_products_without_gla_visibility_metadata() {

$this->assertEquals( $product_2->get_id(), $response->get_data()[0]['id'] );
$this->assertEquals( $expected_metadata, $this->format_metadata( $response->get_data()[0]['meta_data'] ) );
$this->assertArrayHasKey( 'gla_attributes', $response->get_data()[0] );
}

public function test_get_product_without_gla_visibility_metadata() {
Expand Down Expand Up @@ -244,6 +247,7 @@ public function test_get_variations() {
foreach ( $variations as $variation ) {
$this->assertArrayHasKey( $variation['variation_id'], $response_mapped );
$this->assertEquals( $expected_metadata, $this->format_metadata( $response_mapped[ $variation['variation_id'] ]['meta_data'] ) );
$this->assertArrayHasKey( 'gla_attributes', $response->get_data()[0] );
}
}

Expand Down Expand Up @@ -271,9 +275,47 @@ public function test_get_variations_without_gla_syncable_param() {
foreach ( $variations as $variation ) {
$this->assertArrayHasKey( $variation['variation_id'], $response_mapped );
$this->assertEquals( $expected_metadata, $this->format_metadata( $response_mapped[ $variation['variation_id'] ]['meta_data'] ) );
$this->assertArrayNotHasKey( 'gla_attributes', $response->get_data()[0] );
}
}

public function test_get_specific_variation_with_gla_syncable() {
$product = ProductHelper::create_variation_product();
$variation = $product->get_available_variations()[0];

$this->add_metadata( $variation['variation_id'], $this->get_test_metadata( null ) );

$response = $this->do_request( '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation['variation_id'], 'GET', [ 'gla_syncable' => '1' ] );

$this->assertEquals( 200, $response->get_status() );

$expected_metadata = [
'public_meta' => 'public',
];

$this->assertEquals( $expected_metadata, $this->format_metadata( $response->get_data()['meta_data'] ) );
$this->assertArrayHasKey( 'gla_attributes', $response->get_data() );
}

public function test_get_specific_variation_without_gla_syncable() {
$product = ProductHelper::create_variation_product();
$variation = $product->get_available_variations()[0];

$this->add_metadata( $variation['variation_id'], $this->get_test_metadata( null ) );

$response = $this->do_request( '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation['variation_id'], 'GET', [ 'gla_syncable' => '0' ] );

$this->assertEquals( 200, $response->get_status() );

$expected_metadata = [
'public_meta' => 'public',
'_private_meta' => 'private',
];

$this->assertEquals( $expected_metadata, $this->format_metadata( $response->get_data()['meta_data'] ) );
$this->assertArrayNotHasKey( 'gla_attributes', $response->get_data() );
}

public function test_get_coupons() {
$coupon_1 = CouponHelper::create_coupon( 'dummycoupon-1', 'publish', $this->get_test_metadata() );
$coupon_2 = CouponHelper::create_coupon( 'dummycoupon-2', 'publish', $this->get_test_metadata( ChannelVisibility::DONT_SYNC_AND_SHOW ) );
Expand Down

0 comments on commit d2d8b32

Please sign in to comment.