Skip to content

Commit

Permalink
fix cat api test
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Nov 28, 2023
1 parent 8df42ef commit ff6cf12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 12 additions & 11 deletions tests/includes/API/Test_Product_Categories_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function tearDown(): void {
}

public function test_namespace_property(): void {
$namespace = $this->get_reflected_property_value('namespace');
$namespace = $this->get_reflected_property_value( 'namespace' );

$this->assertEquals('wcpos/v1', $namespace );
$this->assertEquals( 'wcpos/v1', $namespace );
}

public function test_rest_base(): void {
$rest_base = $this->get_reflected_property_value('rest_base');
$rest_base = $this->get_reflected_property_value( 'rest_base' );

$this->assertEquals('products/categories', $rest_base);
$this->assertEquals( 'products/categories', $rest_base );
}

/**
Expand Down Expand Up @@ -83,16 +83,17 @@ public function test_product_category_api_get_all_ids(): void {
$cat2 = ProductHelper::create_product_category( 'Clothes' );
$request = $this->wp_rest_get_request( '/wcpos/v1/products/categories' );
$request->set_param( 'posts_per_page', -1 );
$request->set_param( 'fields', array('id') );
$request->set_param( 'fields', array( 'id' ) );

$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );

$data = $response->get_data();
$this->assertEquals( 3, \count( $data ) ); // there is one cat id = 15 by default
$this->assertEquals( 3, \count( $data ) ); // there is one cat id install in test setup
$ids = wp_list_pluck( $data, 'id' );

$this->assertEqualsCanonicalizing( array( 15, $cat1['term_id'], $cat2['term_id'] ), $ids );
$this->assertContains( $cat1['term_id'], $ids );
$this->assertContains( $cat2['term_id'], $ids );
}

/**
Expand All @@ -101,10 +102,10 @@ public function test_product_category_api_get_all_ids(): void {
public function test_product_category_response_contains_uuid_meta_data(): void {
$category = ProductHelper::create_product_category( 'Music' );
$request = $this->wp_rest_get_request( '/wcpos/v1/products/categories/' . $category['term_id'] );
$response = $this->server->dispatch($request);
$response = $this->server->dispatch( $request );

$data = $response->get_data();
$this->assertEquals(200, $response->get_status());
$this->assertTrue(Uuid::isValid($data['uuid']), 'The UUID value is not valid.');
$this->assertEquals( 200, $response->get_status() );
$this->assertTrue( Uuid::isValid( $data['uuid'] ), 'The UUID value is not valid.' );
}
}
3 changes: 2 additions & 1 deletion tests/includes/API/Test_Stores_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ public function get_expected_response_fields() {
'price_display_suffix',
'tax_total_display',
'meta_data',
'_links',
);
}

public function test_product_api_get_all_fields(): void {
public function test_stores_api_get_all_fields(): void {
$expected_response_fields = $this->get_expected_response_fields();

$request = $this->wp_rest_get_request( '/wcpos/v1/stores' );
Expand Down

0 comments on commit ff6cf12

Please sign in to comment.