From 49c685e288d5e554ac49afe17075a85bd2b94398 Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 08:35:23 +0100 Subject: [PATCH 1/8] setting default --- src/API/Site/Controllers/MerchantCenter/SettingsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/API/Site/Controllers/MerchantCenter/SettingsController.php b/src/API/Site/Controllers/MerchantCenter/SettingsController.php index e9ffac77e4..64dcad9d0d 100644 --- a/src/API/Site/Controllers/MerchantCenter/SettingsController.php +++ b/src/API/Site/Controllers/MerchantCenter/SettingsController.php @@ -130,6 +130,7 @@ protected function get_schema_properties(): array { 'destination', 'manual', ], + 'default' => 'destination', ], 'website_live' => [ 'type' => 'boolean', From bc232cbef9336831da127c7899fff3f4dc921ef1 Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 12:18:08 +0100 Subject: [PATCH 2/8] unit test for tax_rate --- .../MerchantCenter/SettingsControllerTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php new file mode 100644 index 0000000000..5c27e3fff5 --- /dev/null +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -0,0 +1,36 @@ +controller = new SettingsController( $this->server ); + $this->controller->register(); + } + + public function test_default_settings() { + $response = $this->do_request( self::ROUTE, 'GET' ); + + $this->assertEquals( 'destination', $response->get_data()['tax_rate'] ); + $this->assertEquals( 200, $response->get_status() ); + } +} From aa88b50a46a56812901cd4153a2933131ef81e42 Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 12:27:50 +0100 Subject: [PATCH 3/8] fix function name --- .../Site/Controllers/MerchantCenter/SettingsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index 5c27e3fff5..bf59f3d662 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -27,7 +27,7 @@ public function setUp(): void { $this->controller->register(); } - public function test_default_settings() { + public function test_default_tax_rate_settings() { $response = $this->do_request( self::ROUTE, 'GET' ); $this->assertEquals( 'destination', $response->get_data()['tax_rate'] ); From 3e72d8e68e5ae804e508baacf6b744ed0f532c9a Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 13:18:21 +0100 Subject: [PATCH 4/8] Fix unit test --- .../MerchantCenter/SettingsControllerTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index bf59f3d662..60735c99c3 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -1,10 +1,10 @@ controller = new SettingsController( $this->server ); + + $this->options = $this->createMock( OptionsInterface::class ); + $this->controller->set_options_object( $this->options ); $this->controller->register(); } public function test_default_tax_rate_settings() { - $response = $this->do_request( self::ROUTE, 'GET' ); + $response = $this->do_request( self::ROUTE ); $this->assertEquals( 'destination', $response->get_data()['tax_rate'] ); $this->assertEquals( 200, $response->get_status() ); From 4a3d08eb228354fb2579b65d7eb5002ebfc1636f Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 14:02:57 +0100 Subject: [PATCH 5/8] define options variable --- .../Site/Controllers/MerchantCenter/SettingsControllerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index 60735c99c3..84386e9314 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -18,6 +18,9 @@ class SettingsControllerTest extends RESTControllerUnitTest { /** @var SettingsController $controller */ protected $controller; + /** @var MockObject|OptionsInterface $options */ + protected $options; + protected const ROUTE = '/wc/gla/mc/settings'; public function setUp(): void { From e0cc337ca7e7ab9aa93c21f25a69a23eb907cc0b Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 14:53:28 +0100 Subject: [PATCH 6/8] add unit test for post method --- .../Controllers/MerchantCenter/SettingsControllerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index 84386e9314..8f290a58b7 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -39,4 +39,11 @@ public function test_default_tax_rate_settings() { $this->assertEquals( 'destination', $response->get_data()['tax_rate'] ); $this->assertEquals( 200, $response->get_status() ); } + + public function test_default_tax_rate_settings_post() { + $response = $this->do_request( self::ROUTE, 'POST', [] ); + + $this->assertEquals( 'destination', $response->get_data()['data']['tax_rate'] ); + $this->assertEquals( 200, $response->get_status() ); + } } From 06201219218b0763fc4947da897a20f90512f5fc Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 18:51:10 +0100 Subject: [PATCH 7/8] remove unwanted imports --- .../Site/Controllers/MerchantCenter/SettingsControllerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index 8f290a58b7..1c71649528 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -5,8 +5,6 @@ use Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\MerchantCenter\SettingsController; use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\RESTControllerUnitTest; -use Exception; -use PHPUnit\Framework\MockObject\MockObject; /** * Class SettingsControllerTest From d6f565866ac0886418f5d4d17097bc51c8fe5c83 Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Mon, 19 Aug 2024 19:02:18 +0100 Subject: [PATCH 8/8] update package name --- .../Site/Controllers/MerchantCenter/SettingsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php index 1c71649528..f0bc4bcbf0 100644 --- a/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php +++ b/tests/Unit/API/Site/Controllers/MerchantCenter/SettingsControllerTest.php @@ -9,7 +9,7 @@ /** * Class SettingsControllerTest * - * @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\API\Site\Controllers\Ads + * @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\API\Site\Controllers\MerchantCenter */ class SettingsControllerTest extends RESTControllerUnitTest {