From 2c969feb6144dc7048157cb2337ce42fc1180975 Mon Sep 17 00:00:00 2001 From: Kumar Saurabh Date: Thu, 10 Sep 2026 05:40:30 +0530 Subject: [PATCH] fix: propagate board clone failures Signed-off-by: Kumar Saurabh --- src/services/BoardApi.js | 22 +++++++++------------- src/services/BoardApi.spec.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 src/services/BoardApi.spec.js diff --git a/src/services/BoardApi.js b/src/services/BoardApi.js index a6551b56d8..f9a7627764 100644 --- a/src/services/BoardApi.js +++ b/src/services/BoardApi.js @@ -144,19 +144,15 @@ export class BoardApi { } async cloneBoard(board, withCards = false, withAssignments = false, withLabels = false, withDueDate = false, moveCardsToLeftStack = false, restoreArchivedCards = false) { - try { - const response = await axios.post(this.url(`/boards/${board.id}/clone`), { - withCards, - withAssignments, - withLabels, - withDueDate, - moveCardsToLeftStack, - restoreArchivedCards, - }) - return response.data - } catch (err) { - return err - } + const response = await axios.post(this.url(`/boards/${board.id}/clone`), { + withCards, + withAssignments, + withLabels, + withDueDate, + moveCardsToLeftStack, + restoreArchivedCards, + }) + return response.data } exportBoard(board, format) { diff --git a/src/services/BoardApi.spec.js b/src/services/BoardApi.spec.js new file mode 100644 index 0000000000..62c49760c7 --- /dev/null +++ b/src/services/BoardApi.spec.js @@ -0,0 +1,35 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import axios from '@nextcloud/axios' +import { BoardApi } from './BoardApi.js' + +jest.mock('@nextcloud/axios', () => ({ + post: jest.fn(), +})) + +jest.mock('@nextcloud/router', () => ({ + generateOcsUrl: jest.fn(url => url), + generateUrl: jest.fn(url => url), +})) + +describe('BoardApi', () => { + describe('cloneBoard', () => { + it('returns the cloned board on success', async () => { + const board = { id: 42 } + const clonedBoard = { id: 84, title: 'Cloned board' } + axios.post.mockResolvedValue({ data: clonedBoard }) + + await expect(new BoardApi().cloneBoard(board)).resolves.toEqual(clonedBoard) + }) + + it('rejects when the request fails', async () => { + const error = new Error('Clone failed') + axios.post.mockRejectedValue(error) + + await expect(new BoardApi().cloneBoard({ id: 42 })).rejects.toBe(error) + }) + }) +})