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

Validate missing fields in Store API #45840

Merged
merged 5 commits into from Mar 27, 2024
Merged

Conversation

senadir
Copy link
Member

@senadir senadir commented Mar 22, 2024

Changes proposed in this Pull Request:

In additional fields, we would only validate passed fields, this means required missing fields would not get validated, this fixes it and enable the test for it.

Closes #45496

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Tests should pass.
  2. Add the following snippet to your store
add_action(
	'woocommerce_loaded',
	function () {
		__experimental_woocommerce_blocks_register_checkout_field(
			array(
				'id'       => 'plugin-namespace/job-function',
				'label'    => 'What is your main role at your company?',
				'location' => 'additional',
				'required' => true,
				'type'     => 'text',
			)
		);
	}
);
  1. Send this request to Store API after adding to cart:
{
	"billing_address": {
		"first_name": "test",
		"last_name": "test",
		"company": "",
		"address_1": "test",
		"address_2": "",
		"city": "test",
		"state": "",
		"postcode": "cb241ab",
		"country": "GB",
		"phone": "",
		"email": "testaccount@test.com"
	},
	"shipping_address": {
		"first_name": "test",
		"last_name": "test",
		"company": "",
		"address_1": "test",
		"address_2": "",
		"city": "test",
		"state": "",
		"postcode": "cb241ab",
		"country": "GB",
		"phone": ""
	},
	"payment_method": "bacs",
	"additional_fields": {}
}
  1. You should get an error saying the field is missing or not the correct type.

@senadir senadir self-assigned this Mar 22, 2024
@senadir senadir added type: bug The issue is a confirmed bug. focus: checkout Issues related to checkout page. team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues labels Mar 22, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 22, 2024
Copy link
Contributor

github-actions bot commented Mar 22, 2024

Test Results Summary

Commit SHA: 1fd8e60

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests344003703819m 7s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@senadir senadir force-pushed the fix/additional-fields-validation branch from c6ae01f to 608c999 Compare March 26, 2024 13:26
@senadir senadir marked this pull request as ready for review March 26, 2024 14:35
@woocommercebot woocommercebot requested review from a team and wavvves and removed request for a team March 26, 2024 14:35
Copy link
Contributor

Hi @wavvves,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@@ -38,7 +38,7 @@ class CheckoutFields {
*
Copy link
Member Author

Choose a reason for hiding this comment

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

This file has no changes.

@@ -383,12 +383,14 @@ public function validate_additional_fields( $fields, $request ) {
$fields = $this->sanitize_additional_fields( $fields );
$additional_field_schema = $this->get_additional_fields_schema();

Copy link
Member Author

Choose a reason for hiding this comment

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

Changes are starting from here.

Copy link
Contributor

@wavvves wavvves left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

@senadir senadir merged commit 3513af5 into trunk Mar 27, 2024
51 checks passed
@senadir senadir deleted the fix/additional-fields-validation branch March 27, 2024 15:50
@github-actions github-actions bot added this to the 8.9.0 milestone Mar 27, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Mar 27, 2024
@alopezari alopezari added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris contains: rest api change Indicates if the PR contains a REST API change. and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contains: rest api change Indicates if the PR contains a REST API change. focus: checkout Issues related to checkout page. needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkout Additional fields not validated if required in Store API
3 participants