Add tests
This commit is contained in:
parent
868d193015
commit
5cd3b9dc88
|
@ -26,7 +26,7 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
|||
return
|
||||
}
|
||||
|
||||
const { actions } = await sdk.rowActions.get(table._id!)
|
||||
const { actions } = await sdk.rowActions.getAll(table._id!)
|
||||
const result: RowActionsResponse = {
|
||||
actions: Object.entries(actions).reduce<Record<string, RowActionResponse>>(
|
||||
(acc, [key, action]) => ({
|
||||
|
|
|
@ -687,32 +687,24 @@ describe("/rowsActions", () => {
|
|||
rowAction = await createRowAction(tableId, createRowActionRequest())
|
||||
|
||||
await config.publish()
|
||||
tk.travel(Date.now() + 100)
|
||||
})
|
||||
|
||||
unauthorisedTests((expectations, testConfig) =>
|
||||
config.api.rowAction.trigger(
|
||||
tableId,
|
||||
rowAction.id,
|
||||
{
|
||||
rowId: row._id!,
|
||||
},
|
||||
expectations,
|
||||
{ ...testConfig, useProdApp: true }
|
||||
)
|
||||
)
|
||||
|
||||
it("can trigger an automation given valid data", async () => {
|
||||
await config.api.rowAction.trigger(tableId, rowAction.id, {
|
||||
rowId: row._id!,
|
||||
})
|
||||
|
||||
async function getAutomationLogs() {
|
||||
const { data: automationLogs } = await config.doInContext(
|
||||
config.getProdAppId(),
|
||||
async () =>
|
||||
automations.logs.logSearch({
|
||||
startDate: await automations.logs.oldestLogDate(),
|
||||
})
|
||||
automations.logs.logSearch({ startDate: new Date().toISOString() })
|
||||
)
|
||||
return automationLogs
|
||||
}
|
||||
|
||||
it("can trigger an automation given valid data", async () => {
|
||||
await config.api.rowAction.trigger(tableId, rowAction.id, {
|
||||
rowId: row._id!,
|
||||
})
|
||||
|
||||
const automationLogs = await getAutomationLogs()
|
||||
expect(automationLogs).toEqual([
|
||||
expect.objectContaining({
|
||||
automationId: rowAction.automationId,
|
||||
|
@ -743,28 +735,36 @@ describe("/rowsActions", () => {
|
|||
{
|
||||
status: 403,
|
||||
body: {
|
||||
message: `Row action '${rowAction.id}' is not enabled for view '${viewId}'"`,
|
||||
message: `Row action '${rowAction.id}' is not enabled for view '${viewId}'`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { data: automationLogs } = await config.doInContext(
|
||||
config.getProdAppId(),
|
||||
async () =>
|
||||
automations.logs.logSearch({
|
||||
startDate: await automations.logs.oldestLogDate(),
|
||||
})
|
||||
const automationLogs = await getAutomationLogs()
|
||||
expect(automationLogs).toEqual([])
|
||||
})
|
||||
|
||||
it("triggers from an allowed view", async () => {
|
||||
const viewId = (
|
||||
await config.api.viewV2.create(
|
||||
setup.structures.viewV2.createRequest(tableId)
|
||||
)
|
||||
).id
|
||||
|
||||
await config.api.rowAction.setViewPermission(
|
||||
tableId,
|
||||
viewId,
|
||||
rowAction.id
|
||||
)
|
||||
|
||||
await config.api.rowAction.trigger(tableId, rowAction.id, {
|
||||
rowId: row._id!,
|
||||
})
|
||||
|
||||
const automationLogs = await getAutomationLogs()
|
||||
expect(automationLogs).toEqual([
|
||||
expect.objectContaining({
|
||||
automationId: rowAction.automationId,
|
||||
trigger: expect.objectContaining({
|
||||
outputs: {
|
||||
fields: {},
|
||||
row: await config.api.row.get(tableId, row._id!),
|
||||
table: await config.api.table.get(tableId),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
|
|
@ -99,7 +99,7 @@ export async function get(tableId: string, rowActionId: string) {
|
|||
return rowAction
|
||||
}
|
||||
|
||||
async function getAll(tableId: string) {
|
||||
export async function getAll(tableId: string) {
|
||||
const db = context.getAppDB()
|
||||
const rowActionsId = generateRowActionsID(tableId)
|
||||
return await db.get<TableRowActions>(rowActionsId)
|
||||
|
|
Loading…
Reference in New Issue