Skip to content

Commit

Permalink
[Product Reviews API] - minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstoicareea committed Oct 9, 2017
1 parent b94a5dc commit 01cca12
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ imports:
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/cart.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/payments.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product_variant.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product_review.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product_variant.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/promotion.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/shipments.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/taxon.yml" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ sylius_api_product_association_type:
sylius_api_product_option:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_option.yml"

sylius_api_product_review:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_review.yml"
prefix: /products/{productCode}

sylius_api_product_taxon_position:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_taxon_position.yml"

sylius_api_product_variant:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_variant.yml"
prefix: /products/{productCode}

sylius_api_product_review:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_review.yml"
prefix: /products/{productCode}

sylius_api_promotion:
resource: "@SyliusAdminApiBundle/Resources/config/routing/promotion.yml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function createQueryBuilderByProductCode(string $locale, string $productC
/**
* {@inheritdoc}
*/
public function findOneByIdAndProductCode(string $id, string $productCode): ?ReviewInterface {
public function findOneByIdAndProductCode($id, string $productCode): ?ReviewInterface
{
return $this->createQueryBuilder('o')
->innerJoin('o.reviewSubject', 'product')
->andWhere('product.code = :productCode')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function findAcceptedByProductSlugAndChannel(string $slug, string $locale
public function createQueryBuilderByProductCode(string $locale, string $productCode): QueryBuilder;

/**
* @param integer $id
* @param mixed $id
* @param string $productCode
*
* @return ReviewInterface|null
*/
public function findOneByIdAndProductCode(string $id, string $productCode): ?ReviewInterface;
public function findOneByIdAndProductCode($id, string $productCode): ?ReviewInterface;
}
24 changes: 12 additions & 12 deletions tests/Controller/ProductReviewApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Lakion\ApiTestCase\JsonApiTestCase;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductReview;
use Sylius\Component\Review\Model\ReviewInterface;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ public function it_allows_showing_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$this->client->request('GET', $this->getReviewUrl($product, $productReview), [], [], static::$authorizedHeaderWithAccept);
Expand Down Expand Up @@ -183,7 +183,7 @@ public function it_allows_delete_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$this->client->request('DELETE', $this->getReviewUrl($product, $productReview), [], [], static::$authorizedHeaderWithContentType, []);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function it_allows_updating_information_about_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$data =
Expand Down Expand Up @@ -240,7 +240,7 @@ public function it_allows_updating_partial_information_about_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$data =
Expand All @@ -267,7 +267,7 @@ public function it_allows_accept_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$this->client->request('PATCH', $this->getReviewUrl($product, $productReview) . '/accept', [], [], static::$authorizedHeaderWithAccept);
Expand All @@ -287,7 +287,7 @@ public function it_does_not_allows_accept_product_review_if_it_has_not_new_statu
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview2'];

$this->client->request('POST', $this->getReviewUrl($product, $productReview) . '/accept', [], [], static::$authorizedHeaderWithAccept);
Expand All @@ -307,7 +307,7 @@ public function it_allows_reject_product_review()
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview1'];

$this->client->request('PATCH', $this->getReviewUrl($product, $productReview) . '/reject', [], [], static::$authorizedHeaderWithAccept);
Expand All @@ -327,7 +327,7 @@ public function it_does_not_allows_reject_product_review_if_it_has_not_new_statu
/** @var ProductInterface $product */
$product = $productReviewsData['product1'];

/** @var ProductReview $productReview */
/** @var ReviewInterface $productReview */
$productReview = $productReviewsData['productReview3'];

$this->client->request('POST', $this->getReviewUrl($product, $productReview) . '/accept', [], [], static::$authorizedHeaderWithAccept);
Expand All @@ -341,18 +341,18 @@ public function it_does_not_allows_reject_product_review_if_it_has_not_new_statu
*
* @return string
*/
private function getReviewListUrl(ProductInterface $product)
private function getReviewListUrl(ProductInterface $product): string
{
return sprintf('/api/v1/products/%s/reviews/', $product->getCode());
}

/**
* @param ProductInterface $product
* @param ProductReview $productReview
* @param ReviewInterface $productReview
*
* @return string
*/
private function getReviewUrl(ProductInterface $product, ProductReview $productReview)
private function getReviewUrl(ProductInterface $product, ReviewInterface $productReview): string
{
return sprintf('%s%s', $this->getReviewListUrl($product), $productReview->getId());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/DataFixtures/ORM/resources/product_reviews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Sylius\Component\Core\Model\Customer:
lastName: King
email: example.king@example.com
emailCanonical: example.king@example.com

Sylius\Component\Core\Model\Product:
product1:
fallbackLocale: en_US
Expand Down Expand Up @@ -39,4 +40,4 @@ Sylius\Component\Core\Model\ProductReview:
comment: "mug_review_bad_comment"
author: "@customer_example1"
status: "accepted"
reviewSubject: "@product1"
reviewSubject: "@product1"
166 changes: 83 additions & 83 deletions tests/Responses/Expected/product_review/accept_response.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
{
"id": @integer@,
"title": "mug_review_best",
"rating": 4,
"comment": "mug_review_best_comment",
"author": {
"id": @integer@,
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"self": {
"href": @string@
}
}
},
"status": "accepted",
"reviewSubject": {
"id": @integer@,
"code": "MUG_REVIEW_BEST",
"attributes": [],
"options": [],
"associations": [],
"translations": {
"en": {
"locale": "en"
}
},
"productTaxons": [],
"channels": [],
"reviews": {
"1": {
"title": "mug_review_best",
"rating": 4,
"comment": "mug_review_best_comment",
"author": {
"id": @integer@,
"title": "mug_review_good",
"rating": 3,
"comment": "mug_review_good_comment",
"author": {
"id": @integer@,
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"self": {
"href": @string@
"href": @string@
}
}
},
"status": "rejected",
"createdAt": @string@,
"updatedAt": @string@
},
"2": {
}
},
"status": "accepted",
"reviewSubject": {
"id": @integer@,
"title": "mug_review_bad",
"rating": 1,
"comment": "mug_review_bad_comment",
"author": {
"id": @integer@,
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"self": {
"href": @string@
"code": "MUG_REVIEW_BEST",
"attributes": [],
"options": [],
"associations": [],
"translations": {
"en": {
"locale": "en"
}
}
},
"status": "accepted",
"createdAt": @string@,
"updatedAt": @string@
}
"productTaxons": [],
"channels": [],
"reviews": {
"1": {
"id": @integer@,
"title": "mug_review_good",
"rating": 3,
"comment": "mug_review_good_comment",
"author": {
"id": @integer@,
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"self": {
"href": @string@
}
}
},
"status": "rejected",
"createdAt": @string@,
"updatedAt": @string@
},
"2": {
"id": @integer@,
"title": "mug_review_bad",
"rating": 1,
"comment": "mug_review_bad_comment",
"author": {
"id": @integer@,
"email": "example.queen@example.com",
"emailCanonical": "example.queen@example.com",
"firstName": "Example",
"lastName": "Queen",
"gender": "u",
"_links": {
"self": {
"href": @string@
}
}
},
"status": "accepted",
"createdAt": @string@,
"updatedAt": @string@
}
},
"averageRating": 2.5,
"images": [],
"_links": {
"self": {
"href": "/api/v1/products/MUG_REVIEW_BEST"
},
"variants": {
"href": "/api/v1/products/MUG_REVIEW_BEST/variants/"
}
}
},
"averageRating": 2.5,
"images": [],
"_links": {
"self": {
"href": "/api/v1/products/MUG_REVIEW_BEST"
},
"variants": {
"href": "/api/v1/products/MUG_REVIEW_BEST/variants/"
}
}
},
"createdAt": @string@,
"updatedAt": @string@
}
"createdAt": @string@,
"updatedAt": @string@
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"code":400,
"message":""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
},
"createdAt": @string@,
"updatedAt": @string@
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"_embedded": {
"items": []
}
}
}
Loading

0 comments on commit 01cca12

Please sign in to comment.