Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions lib/Controller/Implementation/RecipeImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public function update($id) {
$recipeData = $this->restParser->getParameters();
try {
$file = $this->service->addRecipe($recipeData);
} catch (RecipeExistsException $ex) {
$json = [
'msg' => $ex->getMessage(),
'file' => $ex->getFile(),
'line' => $ex->getLine(),
];
return new JSONResponse($json, Http::STATUS_CONFLICT);
} catch (NoRecipeNameGivenException $ex) {
$json = [
'msg' => $ex->getMessage(),
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Controller/Implementation/RecipeImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ public function testUpdateNoName(): void {
$this->assertEquals($errorMsg, $ret->getData()['msg']);
}

public function testUpdateConflictingName(): void {
$this->ensureCacheCheckTriggered();

$recipe = ['a', 'recipe', 'as', 'array'];

$errorMsg = "Another recipe with that name already exists";
$ex = new RecipeExistsException($errorMsg);

$this->restParser->method('getParameters')->willReturn($recipe);
$this->recipeService->expects($this->once())->method('addRecipe')->with($recipe)->willThrowException($ex);
$this->dbCacheService->expects($this->never())->method('addRecipe');

$ret = $this->sut->update(1);

$this->assertEquals(409, $ret->getStatus());
$this->assertEquals($errorMsg, $ret->getData()['msg']);
}

public function testCreate(): void {
$this->ensureCacheCheckTriggered();

Expand Down