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

Add Validation on Customer Gender #617

Merged
merged 3 commits into from
Jan 1, 2020
Merged
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
10 changes: 10 additions & 0 deletions src/Resources/config/validation/customer/UpdateCustomerRequest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
<option name="groups">sylius</option>
<option name="groups">sylius_customer_profile_update</option>
</constraint>
<constraint name="Choice">
<option name="choices">
<value>u</value>
<value>m</value>
<value>f</value>
</option>
<option name="message">sylius.shop_api.gender.not_valid</option>
<option name="groups">sylius</option>
<option name="groups">sylius_customer_profile_update</option>
</constraint>
</property>
</class>
</constraint-mapping>
2 changes: 2 additions & 0 deletions src/Resources/translations/validators.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ sylius:
verification_token:
not_blank: Please provide a token.
not_exists: The token does not exist.
gender:
not_valid: Please enter a valid gender
24 changes: 24 additions & 0 deletions tests/Controller/Customer/UpdateCustomerApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,28 @@ public function it_does_not_allow_to_update_customer_without_passing_required_da
$response = $this->client->getResponse();
$this->assertResponse($response, 'customer/validation_empty_data', Response::HTTP_BAD_REQUEST);
}

/**
* @test
*/
public function it_does_not_allow_to_update_customer_without_entering_valid_gender(): void
{
$this->loadFixturesFromFiles(['channel.yml', 'customer.yml']);
$this->logInUser('oliver@queen.com', '123password');

$data =
<<<JSON
{
"firstName": "New name",
"lastName": "New lastName",
"birthday": "2017-11-01",
"gender": "mmm",
"phoneNumber": "0918972132",
"subscribedToNewsletter": true
}
JSON;
$this->client->request('PUT', '/shop-api/me', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();
$this->assertResponse($response, 'customer/validation_gender_not_valid_response', Response::HTTP_BAD_REQUEST);
}
}
3 changes: 2 additions & 1 deletion tests/Responses/Expected/customer/validation_empty_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"Last name must be at least 2 characters long."
],
"gender": [
"Please choose your gender."
"Please choose your gender.",
"Please enter a valid gender"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"code": 400,
"message": "Validation failed",
"errors": {
"gender": [
"Please enter a valid gender"
]
}
}