2020-12-07 23:50:22 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
// Disable console log
|
|
|
|
console.log = jest.fn()
|
|
|
|
|
2021-08-02 17:46:00 +02:00
|
|
|
import {Block} from './blocks/block'
|
|
|
|
import {createBoard} from './blocks/board'
|
2020-12-07 23:50:22 +01:00
|
|
|
import octoClient from './octoClient'
|
|
|
|
import 'isomorphic-fetch'
|
2020-12-08 00:40:32 +01:00
|
|
|
import {FetchMock} from './test/fetchMock'
|
2020-12-07 23:50:22 +01:00
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
global.fetch = FetchMock.fn
|
2020-12-07 23:50:22 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReset()
|
2020-12-07 23:50:22 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
test('OctoClient: get blocks', async () => {
|
|
|
|
const blocks = createBoards()
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
|
2020-12-07 23:50:22 +01:00
|
|
|
let boards = await octoClient.getBlocksWithType('board')
|
|
|
|
expect(boards.length).toBe(blocks.length)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
|
2020-12-07 23:50:22 +01:00
|
|
|
boards = await octoClient.getSubtree()
|
|
|
|
expect(boards.length).toBe(blocks.length)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
|
2021-05-13 23:04:49 +02:00
|
|
|
boards = await octoClient.exportArchive()
|
2020-12-07 23:50:22 +01:00
|
|
|
expect(boards.length).toBe(blocks.length)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
|
2020-12-07 23:50:22 +01:00
|
|
|
const parentId = 'id1'
|
|
|
|
boards = await octoClient.getBlocksWithParent(parentId)
|
|
|
|
expect(boards.length).toBe(blocks.length)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks)))
|
2020-12-07 23:50:22 +01:00
|
|
|
boards = await octoClient.getBlocksWithParent(parentId, 'board')
|
|
|
|
expect(boards.length).toBe(blocks.length)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('OctoClient: insert blocks', async () => {
|
|
|
|
const blocks = createBoards()
|
|
|
|
|
|
|
|
await octoClient.insertBlocks(blocks)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
expect(FetchMock.fn).toBeCalledTimes(1)
|
|
|
|
expect(FetchMock.fn).toHaveBeenCalledWith(
|
2020-12-07 23:50:22 +01:00
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(blocks),
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('OctoClient: importFullArchive', async () => {
|
|
|
|
const blocks = createBoards()
|
|
|
|
|
|
|
|
await octoClient.importFullArchive(blocks)
|
|
|
|
|
2020-12-08 00:40:32 +01:00
|
|
|
expect(FetchMock.fn).toBeCalledTimes(1)
|
|
|
|
expect(FetchMock.fn).toHaveBeenCalledWith(
|
2020-12-07 23:50:22 +01:00
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(blocks),
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2021-08-02 17:46:00 +02:00
|
|
|
function createBoards(): Block[] {
|
2020-12-07 23:50:22 +01:00
|
|
|
const blocks = []
|
|
|
|
|
|
|
|
for (let i = 0; i < 5; i++) {
|
2021-08-02 17:46:00 +02:00
|
|
|
const board = createBoard()
|
2020-12-07 23:50:22 +01:00
|
|
|
board.id = `board${i + 1}`
|
|
|
|
blocks.push(board)
|
|
|
|
}
|
|
|
|
|
|
|
|
return blocks
|
|
|
|
}
|