Skip to content
Open
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
22 changes: 9 additions & 13 deletions src/services/BoardApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 35 additions & 0 deletions src/services/BoardApi.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})