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