Skip to content
Permalink
Browse files Browse the repository at this point in the history
NEXT-15681 - Improve product review validation
  • Loading branch information
shyim authored and pweyck committed Aug 2, 2021
1 parent b9f330e commit 912b96d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Expand Up @@ -185,6 +185,7 @@ private function validate(DataBag $data, Context $context): void
$definition->add('id', new EntityExists([
'entity' => 'product_review',
'context' => $context,
'criteria' => $criteria,
]));
} else {
$criteria = new Criteria();
Expand Down
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\Framework\Test\TestCaseBase\SalesChannelApiTestBehaviour;
use Shopware\Core\Framework\Test\TestDataCollection;
use Shopware\Core\Framework\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Response;

/**
* @group store-api
Expand Down Expand Up @@ -120,6 +121,39 @@ public function testValidation(): void
static::assertEquals($response['errors'][1]['source']['pointer'], '/content');
}

public function testCustomerValidation(): void
{
$this->login();

$this->assertReviewCount(0);

$id = Uuid::randomHex();

// Create review
$this->browser->request('POST', $this->getUrl(), [
'id' => $id,
'title' => 'Lorem ipsum dolor sit amet',
'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna',
]);

// Re-login as another user
$this->login();

// Try to use the id from previous review which is not attached to this customer
$this->browser->request('POST', $this->getUrl(), [
'id' => $id,
'title' => 'Lorem ipsum dolor sit amet',
'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna',
]);

$response = $this->browser->getResponse();

static::assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
$content = json_decode($response->getContent(), true);

static::assertSame('VIOLATION::ENTITY_DOES_NOT_EXISTS', $content['errors'][0]['code']);
}

private function assertReviewCount(int $expected): void
{
$count = $this->getContainer()
Expand Down

0 comments on commit 912b96d

Please sign in to comment.