Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
[#1687](https://github.com/nextcloud/cookbook/pull/1687) @christianlupus
- Prevent popup from falsely showing during loading of the app
[#1764](https://github.com/nextcloud/cookbook/pull/1764) @christianlupus
- Fix unclear error message if recipe is already existing
[#1770](https://github.com/nextcloud/cookbook/pull/1770) @SethFalco

### Maintenance
- Fix URL of Transifex after upstream subdomain change
Expand Down
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