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
[RFC][WIP] Expose product option information in API #7547
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ Sylius\Component\Product\Model\ProductOptionValue: | |
code: | ||
expose: true | ||
type: string | ||
value: | ||
expose: true | ||
type: string | ||
virtual_properties: | ||
getName: | ||
serialized_name: name | ||
getValue: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Both virtual properties should be removed and we should expose all translations |
||
serialized_name: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Tests\Controller; | ||
|
||
use Lakion\ApiTestCase\JsonApiTestCase; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author alcaeus <alcaeus@alcaeus.org> | ||
*/ | ||
final class ProductOptionTest extends JsonApiTestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private static $authorizedHeaderWithContentType = [ | ||
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', | ||
'CONTENT_TYPE' => 'application/json', | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $authorizedHeaderWithAccept = [ | ||
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', | ||
'ACCEPT' => 'application/json', | ||
]; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_show_product_options_list_when_access_is_denied() | ||
{ | ||
$this->client->request('GET', '/api/v1/product-options/'); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_allows_listing_product_options() | ||
{ | ||
$this->loadFixturesFromFile('authentication/api_administrator.yml'); | ||
$this->loadFixturesFromFile('resources/product_options.yml'); | ||
|
||
$this->client->request('GET', '/api/v1/product-options/', [], [], static::$authorizedHeaderWithAccept); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'product_option/index_response', Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_delete_product_option_if_it_does_not_exist() | ||
{ | ||
$this->loadFixturesFromFile('authentication/api_administrator.yml'); | ||
|
||
$this->client->request('DELETE', '/api/v1/product-options/-1', [], [], static::$authorizedHeaderWithAccept); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_allows_delete_product_option() | ||
{ | ||
$this->loadFixturesFromFile('authentication/api_administrator.yml'); | ||
$productOptions = $this->loadFixturesFromFile('resources/product_options.yml'); | ||
|
||
$this->client->request('DELETE', '/api/v1/product-options/'.$productOptions['productOption1']->getId(), [], [], static::$authorizedHeaderWithContentType, []); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); | ||
|
||
$this->client->request('GET', '/api/v1/product-options/', [], [], static::$authorizedHeaderWithAccept); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'product_option/index_response_after_delete', Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_allows_create_product_option_with_multiple_translations() | ||
{ | ||
$this->loadFixturesFromFile('authentication/api_administrator.yml'); | ||
$this->loadFixturesFromFile('resources/locales.yml'); | ||
|
||
$data = | ||
<<<EOT | ||
{ | ||
"code": "MUG_SIZE", | ||
"translations": { | ||
"de_CH": { | ||
"name": "Bechergröße" | ||
}, | ||
"en_US": { | ||
"name": "Mug size" | ||
} | ||
}, | ||
"values": [ | ||
{ | ||
"code": "MUG_SIZE_SMALL", | ||
"translations": { | ||
"de_CH": { | ||
"value": "Klein" | ||
}, | ||
"en_US": { | ||
"value": "Small" | ||
} | ||
} | ||
}, | ||
{ | ||
"code": "MUG_SIZE_LARGE", | ||
"translations": { | ||
"de_CH": { | ||
"value": "Groß" | ||
}, | ||
"en_US": { | ||
"value": "Large" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
EOT; | ||
|
||
$this->client->request('POST', '/api/v1/product-options/', [], [], static::$authorizedHeaderWithContentType, $data); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'product_option/create_response', Response::HTTP_CREATED); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_create_product_option_without_required_fields() | ||
{ | ||
$this->loadFixturesFromFile('authentication/api_administrator.yml'); | ||
|
||
$this->client->request('POST', '/api/v1/product-options/', [], [], static::$authorizedHeaderWithContentType, []); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'product_option/create_validation_fail_response', Response::HTTP_BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/Responses/Expected/product_option/create_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Mug size", | ||
"code": "MUG_SIZE", | ||
"values": [ | ||
{ | ||
"name": "Mug size", | ||
"value": "Small", | ||
"code": "MUG_SIZE_SMALL" | ||
}, | ||
{ | ||
"name": "Mug size", | ||
"value": "Large", | ||
"code": "MUG_SIZE_LARGE" | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/Responses/Expected/product_option/create_validation_fail_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"code": 400, | ||
"message": "Validation Failed", | ||
"errors": { | ||
"errors": [ | ||
"Please add at least 2 option values." | ||
], | ||
"children": { | ||
"position": {}, | ||
"translations": {}, | ||
"values": {}, | ||
"code": { | ||
"errors": [ | ||
"Please enter option code." | ||
] | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Responses/Expected/product_option/index_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"page": 1, | ||
"limit": 10, | ||
"pages": 1, | ||
"total": 2, | ||
"_links": { | ||
"self": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
}, | ||
"first": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
}, | ||
"last": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
} | ||
}, | ||
"_embedded": { | ||
"items": [ | ||
{ | ||
"code": "MUG_SIZE", | ||
"values": [] | ||
}, | ||
{ | ||
"code": "MUG_COLOR", | ||
"values": [] | ||
} | ||
] | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Responses/Expected/product_option/index_response_after_delete.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"page": 1, | ||
"limit": 10, | ||
"pages": 1, | ||
"total": 1, | ||
"_links": { | ||
"self": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
}, | ||
"first": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
}, | ||
"last": { | ||
"href": "\/api\/v1\/product-options\/?page=1&limit=10" | ||
} | ||
}, | ||
"_embedded": { | ||
"items": [ | ||
{ | ||
"code": "MUG_COLOR", | ||
"values": [] | ||
} | ||
] | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of fetching the name with virtual property, we should expose all product option translations