Skip to content

Commit

Permalink
Merge pull request #1470 from undb-xyz/setRowHeight-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin authored Aug 29, 2023
2 parents ad88c3b + a95f9aa commit 0d62700
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ITableRepository, createTestTable } from '@undb/core'
import { Some } from 'oxide.ts'
import { None, Some } from 'oxide.ts'
import { mock } from 'vitest-mock-extended'
import { SetRowHeightCommandHandler } from './set-row-height.command.handler.js'
import { SetRowHeightCommand } from './set-row-height.command.js'
Expand All @@ -24,4 +24,22 @@ describe('SetRowHeightCommandHandler', () => {
expect(repo.updateOneById).toHaveBeenCalled()
expect(repo.updateOneById.mock.calls[0][0]).toBe(table.id.value)
})

test('execute failed', async () => {
const table = createTestTable()
const repo = mock<ITableRepository>()
repo.findOneById.mockResolvedValue(None)
const spy = vi.spyOn(table, 'setRowHeight')

const command = new SetRowHeightCommand({ tableId: table.id.value, rowHeight: 'short' })

const handler = new SetRowHeightCommandHandler(repo)

await expect(handler.execute(command)).rejects.toThrowErrorMatchingInlineSnapshot(
'"Failed to unwrap Option (found None)"',
)
expect(repo.findOneById).toHaveBeenCalledWith(table.id.value)
expect(spy).not.toHaveBeenCalled()
expect(repo.updateOneById).not.toHaveBeenCalled()
})
})

0 comments on commit 0d62700

Please sign in to comment.