mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* fix: keep every button action card in place after a save A retyped action can keep its id, and an action created by an earlier save still carries its client id, so the refetched list must keep the client id of every buffered action rather than only the created ones. * feat(jobs): let a job type choose its Celery queue * test: assert the job enqueue through apply_async * refactor(database): expose the button click pre-checks on the service * refactor(database): share the button click payload and outcome mapping * feat(database): run a button click with external actions as a job * fix(database): map click races on the job and assert the audit entry * feat(database): answer a click with external actions with a job The request returns 202 and the job runs the sequence, so a slow endpoint holds a Celery worker instead of a WSGI one. * fix(database): give a capped click its slots back and cover the denied job * refactor(database): raise a plain exception for a denied click job * chore: consume the button_dispatch queue on the default worker * chore: add the button_dispatch queue to the Zed worker launch config * feat(database): wait on the job of an accepted button click * fix(database): stop waiting on a button click job after a deadline * test(e2e): a slow endpoint no longer blocks the grid during a click * test(e2e): name the second-button test for what a single worker can prove * test: assert the airtable import job enqueue through apply_async * chore: changelog for the button dispatch job * fix(database): keep the clicker's IP and session on a button click job The audit log and analytics read both from the user, which the job only restores through these mixins. * fix(database): fail a button click job whose field or table was trashed * fix(database): serialize the busy check of a click with its job creation Two racing requests could both see the cell free and each start a job, so a single worker sent every request twice. Also drops the budget bookkeeping from the inline path, which no longer reaches outside Baserow. * test: assert a refused dispatch check records no audit entry * docs: say a button click job shares the default worker with realtime updates Also adds the automation_workflow and button_dispatch queues to the example supervisor config. * fix(database): check a button click job once more at the deadline The job store stops polling before the deadline, so a job that finished unseen was reported as still running. * test: cover an accepted click in the row modal and on a card * refactor(database): ask the service whether a cell has a click in flight The view queried the job table itself; the check belongs beside the other dispatch rules in the service. * fix(database): run only the action list a click was accepted with The request checks and charges one list; the job re-read the field's current one, so an action added while the job waited ran unchecked and an added external one sent without a rate-limit slot. * fix(database): keep queued button clicks sane across crashes, retypes and trash A dead worker's job no longer blocks its cell until cleanup, a retype no longer deletes a queued job, and a trashed database refuses the click. Core permission refusals use the API's wording. The cell lock is shared and the unused refund plumbing is gone. * fix(database): stop a queued button click from sending twice or unchecked A late or replica-blind click no longer repeats its requests, a retype to external is caught, and a quota refusal answers in the request. Slots come back when no job row was written, and the stored answer is safe for jsonb. * fix: keep polling a button click job after one failed poll A click waits on the job store, which stopped for good after a single failed poll. A settled click's job is dropped so the store stops polling it. * fix(database): stop a cancelled button click between actions The owner can cancel a running job, and later actions still ran. The last job check at the deadline is bounded too, so a hung request cannot keep the button spinning. * test: cover a job's answer reaching Open URL and a click edited while queued * fix(database): let a click job finish when its button is retyped mid-run The worker's save wrote the old field id back and failed. Timeouts and unmapped failures no longer name the job type, and a job that is already final leaves the store. * fix(database): run button click jobs on the export queue Review feedback: the celery queue is for fast tasks, and a new queue needs every self-hosted worker changed. Also strips lone surrogates from the stored answer, moves the enqueue rules into the service and drops the unused websocket id. * fix(database): drop a waiting button click on logout or table switch A job can end minutes after the click, when its toast or Open URL no longer belongs to the page. * chore: drop the changelog entry for #6134 The button field has not shipped yet, so there is no fix to announce. * fix(database): point a click job at the base field A retype deletes the button row, so a job pointing at it had to be nulled first, and a click landing meanwhile failed the retype. * fix(database): keep a button spinning for its job after a reload The spinner only knew about clicks made in this page, so a reload dropped it while the job ran and a second click got the 409 toast. * fix(database): ignore a late job_started for a settled button click On a single worker the broadcast reaches the clicking tab after the job ended, and its started copy spun the button again until the next poll. * docs(database): correct the dispatch signal and e2e comments The signal's first send for a job click happens before the enqueue lock.
396 lines
12 KiB
JavaScript
396 lines
12 KiB
JavaScript
import { vi } from 'vitest'
|
|
import flushPromises from 'flush-promises'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import RowEditFieldButtonField from '@baserow/modules/database/components/row/RowEditFieldButtonField'
|
|
|
|
describe('RowEditFieldButtonField', () => {
|
|
let testApp = null
|
|
let client = null
|
|
let openUrlType = null
|
|
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
client = testApp.getApp().$client
|
|
openUrlType = testApp._app.$registry.get(
|
|
'databaseWorkflowActionType',
|
|
'open_url'
|
|
)
|
|
vi.spyOn(client, 'post').mockResolvedValue({
|
|
data: { results: [], client_actions: [] },
|
|
})
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
const field = {
|
|
id: 3,
|
|
table_id: 1,
|
|
name: 'Go',
|
|
type: 'button',
|
|
label: 'Go',
|
|
has_workflow_actions: true,
|
|
}
|
|
|
|
const mountField = (props = {}, options = {}) =>
|
|
testApp.mount(RowEditFieldButtonField, {
|
|
props: {
|
|
field,
|
|
value: null,
|
|
readOnly: false,
|
|
row: { id: 11 },
|
|
allFieldsInTable: [field],
|
|
...props,
|
|
},
|
|
...options,
|
|
})
|
|
|
|
test('the dispatch button runs the actions for a created row', async () => {
|
|
const wrapper = await mountField()
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeUndefined()
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(client.post).toHaveBeenCalledWith(
|
|
'database/field/3/workflow_actions/dispatch/',
|
|
{ row_id: 11 },
|
|
{ omitWebSocketId: true }
|
|
)
|
|
})
|
|
|
|
test('the dispatch button is inert in the row create modal', async () => {
|
|
// `RowCreateModal` renders every visible field, but there is no row yet:
|
|
// dispatching would post `row_id: undefined` and get a 400 back.
|
|
const wrapper = await mountField({ row: {}, rowIsCreated: false })
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('a user who may not click gets a disabled button that says so', async () => {
|
|
const hasPermission = vi.fn().mockReturnValue(false)
|
|
const wrapper = await mountField(
|
|
{ workspaceId: 9 },
|
|
{ global: { mocks: { $hasPermission: hasPermission } } }
|
|
)
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(hasPermission).toHaveBeenCalledWith(
|
|
'database.table.field.workflow_action.dispatch',
|
|
field,
|
|
9
|
|
)
|
|
// A disabled button fires no mouse events, so the wrapper carries the
|
|
// tooltip.
|
|
expect(button.element.parentElement.tooltipOptions.value).toBe(
|
|
'buttonField.noPermission'
|
|
)
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('a field without actions renders a disabled button and no link', async () => {
|
|
const wrapper = await mountField({
|
|
field: { ...field, has_workflow_actions: false },
|
|
})
|
|
|
|
expect(wrapper.find('a').exists()).toBe(false)
|
|
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
|
|
expect(wrapper.find('button').text()).toBe('Go')
|
|
})
|
|
|
|
test('a field that needs reconfiguring renders a disabled button with a warning', async () => {
|
|
const wrapper = await mountField({
|
|
field: { ...field, requires_reconfiguration: true },
|
|
})
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(wrapper.find('.iconoir-warning-triangle').exists()).toBe(true)
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('runs the returned client actions after the response', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
client.post.mockResolvedValue({
|
|
data: { results: [], client_actions: [action] },
|
|
})
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(execute).toHaveBeenCalledWith({
|
|
workflowAction: action,
|
|
applicationContext: {
|
|
row: { id: 11 },
|
|
fields: [field],
|
|
previousActionResults: {},
|
|
newTab: null,
|
|
},
|
|
})
|
|
})
|
|
|
|
test('a client action is given what the server actions returned', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 2,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
client.post.mockResolvedValue({
|
|
data: {
|
|
results: [
|
|
{
|
|
workflow_action_id: 1,
|
|
status: 'completed',
|
|
data: { id: 99, Name: 'Ada' },
|
|
field_names: { field_10: 'Name' },
|
|
},
|
|
],
|
|
client_actions: [action],
|
|
},
|
|
})
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
// Keyed as a string, the way a formula path carries the id.
|
|
expect(
|
|
execute.mock.calls[0][0].applicationContext.previousActionResults
|
|
).toEqual({
|
|
1: { data: { id: 99, Name: 'Ada' }, fieldNames: { field_10: 'Name' } },
|
|
})
|
|
})
|
|
|
|
test('a client action cannot read a result from an action ordered after it', async () => {
|
|
// Client actions always run last, so every server result is in the
|
|
// response. Only the ones the clicker put before it may be read, or the
|
|
// browser would resolve what the dispatch refuses.
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 2,
|
|
order: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
client.post.mockResolvedValue({
|
|
data: {
|
|
results: [
|
|
{
|
|
workflow_action_id: 1,
|
|
order: 2,
|
|
status: 'completed',
|
|
data: { id: 99, Name: 'Ada' },
|
|
field_names: { field_10: 'Name' },
|
|
},
|
|
],
|
|
client_actions: [action],
|
|
},
|
|
})
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(
|
|
execute.mock.calls[0][0].applicationContext.previousActionResults
|
|
).toEqual({})
|
|
})
|
|
|
|
test('a client action reads a result that shares its order', async () => {
|
|
// Two actions created at once can be given the same `order`, which the
|
|
// dispatch then breaks by id. Comparing the orders alone would drop the
|
|
// earlier result, and the client action would fail on a valid reference.
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 2,
|
|
order: 1,
|
|
position: 2,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
client.post.mockResolvedValue({
|
|
data: {
|
|
results: [
|
|
{
|
|
workflow_action_id: 1,
|
|
order: 1,
|
|
position: 1,
|
|
status: 'completed',
|
|
data: { id: 99, Name: 'Ada' },
|
|
field_names: { field_10: 'Name' },
|
|
},
|
|
],
|
|
client_actions: [action],
|
|
},
|
|
})
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(
|
|
execute.mock.calls[0][0].applicationContext.previousActionResults
|
|
).toEqual({
|
|
1: {
|
|
data: { id: 99, Name: 'Ada' },
|
|
fieldNames: { field_10: 'Name' },
|
|
order: 1,
|
|
position: 1,
|
|
},
|
|
})
|
|
})
|
|
|
|
test('a failed dispatch raises a toast of its own', async () => {
|
|
// A network failure would otherwise be thrown out of an unawaited click
|
|
// handler, and the click would look like it did nothing.
|
|
client.post.mockRejectedValue(new Error('boom'))
|
|
const dispatch = vi.spyOn(testApp.store, 'dispatch')
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
// The test app has no translations loaded, so `$t` hands back the keys.
|
|
expect(dispatch).toHaveBeenCalledWith('toast/error', {
|
|
title: 'buttonField.dispatchErrorTitle',
|
|
message: 'buttonField.dispatchErrorMessage',
|
|
})
|
|
})
|
|
|
|
test('a handled API error is reported through the error handler', async () => {
|
|
// A handled error already carries the backend's message, so the generic
|
|
// toast must not replace it or be raised alongside it.
|
|
const notifyIf = vi.fn()
|
|
client.post.mockRejectedValue(
|
|
Object.assign(new Error('boom'), { handler: { notifyIf } })
|
|
)
|
|
const dispatch = vi.spyOn(testApp.store, 'dispatch')
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(notifyIf).toHaveBeenCalledWith('workflowAction')
|
|
expect(dispatch).not.toHaveBeenCalledWith('toast/error', expect.anything())
|
|
})
|
|
|
|
test('a refused click says so, rather than looking like nothing happened', async () => {
|
|
// The shared error handler stays quiet on a 429: it only speaks for
|
|
// Baserow API errors, network errors and 404s. Without this the rate limit
|
|
// would refuse a click with no sign of it on screen.
|
|
const notifyIf = vi.fn()
|
|
client.post.mockRejectedValue(
|
|
Object.assign(new Error('boom'), {
|
|
handler: { notifyIf, isTooManyRequests: () => true },
|
|
})
|
|
)
|
|
const dispatch = vi.spyOn(testApp.store, 'dispatch')
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('toast/error', {
|
|
title: 'buttonField.rateLimitedTitle',
|
|
message: 'buttonField.rateLimitedMessage',
|
|
})
|
|
expect(notifyIf).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('a failed dispatch leaves the button clickable', async () => {
|
|
client.post.mockRejectedValue(new Error('boom'))
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(client.post).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
test('no client action runs when the dispatch failed', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
client.post.mockRejectedValue(new Error('boom'))
|
|
const wrapper = await mountField()
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(execute).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('an accepted click waits on its job and then runs the client actions', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const job = {
|
|
id: 7,
|
|
type: 'button_field_dispatch',
|
|
state: 'pending',
|
|
progress_percentage: 0,
|
|
human_readable_error: '',
|
|
results: null,
|
|
client_actions: null,
|
|
}
|
|
const action = {
|
|
id: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
client.post.mockResolvedValue({ status: 202, data: job })
|
|
const wrapper = await mountField()
|
|
const store = wrapper.vm.$store
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
// Still waiting: the spinner stays and nothing has run.
|
|
expect(wrapper.vm.dispatching).toBe(true)
|
|
expect(wrapper.find('button').classes()).toContain('button--loading')
|
|
expect(execute).not.toHaveBeenCalled()
|
|
expect(store.getters['job/get'](job.id)).toBeTruthy()
|
|
|
|
await store.dispatch('job/forceUpdate', {
|
|
job: store.getters['job/get'](job.id),
|
|
data: {
|
|
...job,
|
|
state: 'finished',
|
|
results: [],
|
|
client_actions: [action],
|
|
},
|
|
})
|
|
await flushPromises()
|
|
|
|
expect(wrapper.vm.dispatching).toBe(false)
|
|
expect(wrapper.find('button').classes()).not.toContain('button--loading')
|
|
expect(execute).toHaveBeenCalledTimes(1)
|
|
expect(execute.mock.calls[0][0].workflowAction).toEqual(action)
|
|
})
|
|
})
|