Skip to content

Commit

Permalink
Fix KW dup (#93)
Browse files Browse the repository at this point in the history
* Fix KW dup
* Tests fix
  • Loading branch information
TomasHermanek authored Nov 19, 2024
1 parent 6dccfd6 commit 29f8446
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/Domain/Keyword/KeywordFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ public function __construct(
*/
public function create(Keyword $keyword): Keyword
{
$this->validator->validate($keyword);

$existingKeyword = $this->keywordRepository->findOneByNameAndExtSystem($keyword->getName(), $keyword->getExtSystem());
if ($existingKeyword) {
throw new KeywordExistsException($existingKeyword);
}
$this->validator->validate($keyword);

try {
$this->keywordManager->beginTransaction();
Expand Down
34 changes: 23 additions & 11 deletions tests/Controller/Api/Adm/V1/KeywordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public function testCreateFailure(array $requestJson, array $validationErrors):

public function createFailureDataProvider(): array
{
$existingKeyword = self::getContainer()
->get(KeywordRepository::class)
->find(KeywordFixtures::KEYWORD_1);

return [
[
'requestJson' => [
Expand All @@ -134,17 +130,33 @@ public function createFailureDataProvider(): array
ValidationException::ERROR_FIELD_EMPTY,
],
],
],
]
];
}

/**
* @dataProvider keywordExistsDataProvider
*/
public function testKeywordExists(array $requestJson): void
{
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(KeywordUrl::createPath(), $requestJson);
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
}

public function keywordExistsDataProvider(): array
{
$existingKeyword = self::getContainer()
->get(KeywordRepository::class)
->find(KeywordFixtures::KEYWORD_1);

return [
[
'requestJson' => [
'name' => $existingKeyword->getName(),
'extSystem' => ExtSystemFixtures::ID_CMS,
],
'validationErrors' => [
'name' => [
ValidationException::ERROR_FIELD_UNIQUE,
]
],
]
],
];
}
Expand Down

0 comments on commit 29f8446

Please sign in to comment.