More types.
This commit is contained in:
parent
bfb0064289
commit
a9392b2176
|
@ -25,6 +25,7 @@ import { getActionDefinitions as actionDefs } from "../../automations/actions"
|
|||
import sdk from "../../sdk"
|
||||
import { builderSocket } from "../../websockets"
|
||||
import env from "../../environment"
|
||||
import { DocumentDestroyResponse } from "@budibase/nano"
|
||||
|
||||
async function getActionDefinitions() {
|
||||
return removeDeprecated(await actionDefs())
|
||||
|
@ -209,7 +210,7 @@ export async function find(ctx: UserCtx) {
|
|||
ctx.body = await db.get(ctx.params.id)
|
||||
}
|
||||
|
||||
export async function destroy(ctx: UserCtx) {
|
||||
export async function destroy(ctx: UserCtx<void, DocumentDestroyResponse>) {
|
||||
const db = context.getAppDB()
|
||||
const automationId = ctx.params.id
|
||||
const oldAutomation = await db.get<Automation>(automationId)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { EMPTY_LAYOUT } from "../../constants/layouts"
|
||||
import { generateLayoutID, getScreenParams } from "../../db/utils"
|
||||
import { events, context } from "@budibase/backend-core"
|
||||
import { BBContext, Layout } from "@budibase/types"
|
||||
import { BBContext, Layout, UserCtx } from "@budibase/types"
|
||||
|
||||
export async function save(ctx: BBContext) {
|
||||
export async function save(ctx: UserCtx<Layout, Layout>) {
|
||||
const db = context.getAppDB()
|
||||
let layout = ctx.request.body
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ const _import = async (ctx: UserCtx) => {
|
|||
}
|
||||
export { _import as import }
|
||||
|
||||
export async function save(ctx: UserCtx) {
|
||||
export async function save(ctx: UserCtx<Query, Query>) {
|
||||
const db = context.getAppDB()
|
||||
const query: Query = ctx.request.body
|
||||
|
||||
|
|
|
@ -7,7 +7,13 @@ import {
|
|||
roles,
|
||||
} from "@budibase/backend-core"
|
||||
import { updateAppPackage } from "./application"
|
||||
import { Plugin, ScreenProps, BBContext, Screen } from "@budibase/types"
|
||||
import {
|
||||
Plugin,
|
||||
ScreenProps,
|
||||
BBContext,
|
||||
Screen,
|
||||
UserCtx,
|
||||
} from "@budibase/types"
|
||||
import { builderSocket } from "../../websockets"
|
||||
|
||||
export async function fetch(ctx: BBContext) {
|
||||
|
@ -31,7 +37,7 @@ export async function fetch(ctx: BBContext) {
|
|||
)
|
||||
}
|
||||
|
||||
export async function save(ctx: BBContext) {
|
||||
export async function save(ctx: UserCtx<Screen, Screen>) {
|
||||
const db = context.getAppDB()
|
||||
let screen = ctx.request.body
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ describe("/datasources", () => {
|
|||
})
|
||||
// check variables in cache
|
||||
let contents = await checkCacheForDynamicVariable(
|
||||
query._id,
|
||||
query._id!,
|
||||
"variable3"
|
||||
)
|
||||
expect(contents.rows.length).toEqual(1)
|
||||
|
@ -102,7 +102,7 @@ describe("/datasources", () => {
|
|||
expect(res.body.errors).toBeUndefined()
|
||||
|
||||
// check variables no longer in cache
|
||||
contents = await checkCacheForDynamicVariable(query._id, "variable3")
|
||||
contents = await checkCacheForDynamicVariable(query._id!, "variable3")
|
||||
expect(contents).toBe(null)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -467,7 +467,10 @@ describe("/queries", () => {
|
|||
queryString: "test={{ variable3 }}",
|
||||
})
|
||||
// check its in cache
|
||||
const contents = await checkCacheForDynamicVariable(base._id, "variable3")
|
||||
const contents = await checkCacheForDynamicVariable(
|
||||
base._id!,
|
||||
"variable3"
|
||||
)
|
||||
expect(contents.rows.length).toEqual(1)
|
||||
const responseBody = await preview(datasource, {
|
||||
path: "www.failonce.com",
|
||||
|
@ -490,7 +493,7 @@ describe("/queries", () => {
|
|||
queryString: "test={{ variable3 }}",
|
||||
})
|
||||
// check its in cache
|
||||
let contents = await checkCacheForDynamicVariable(base._id, "variable3")
|
||||
let contents = await checkCacheForDynamicVariable(base._id!, "variable3")
|
||||
expect(contents.rows.length).toEqual(1)
|
||||
|
||||
// delete the query
|
||||
|
@ -500,7 +503,7 @@ describe("/queries", () => {
|
|||
.expect(200)
|
||||
|
||||
// check variables no longer in cache
|
||||
contents = await checkCacheForDynamicVariable(base._id, "variable3")
|
||||
contents = await checkCacheForDynamicVariable(base._id!, "variable3")
|
||||
expect(contents).toBe(null)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -4,6 +4,7 @@ import { AppStatus } from "../../../../db/utils"
|
|||
import { roles, tenancy, context, db } from "@budibase/backend-core"
|
||||
import env from "../../../../environment"
|
||||
import Nano from "@budibase/nano"
|
||||
import TestConfiguration from "src/tests/utilities/TestConfiguration"
|
||||
|
||||
class Request {
|
||||
appId: any
|
||||
|
@ -52,10 +53,10 @@ export const clearAllApps = async (
|
|||
})
|
||||
}
|
||||
|
||||
export const clearAllAutomations = async (config: any) => {
|
||||
export const clearAllAutomations = async (config: TestConfiguration) => {
|
||||
const automations = await config.getAllAutomations()
|
||||
for (let auto of automations) {
|
||||
await context.doInAppContext(config.appId, async () => {
|
||||
await context.doInAppContext(config.getAppId(), async () => {
|
||||
await config.deleteAutomation(auto)
|
||||
})
|
||||
}
|
||||
|
@ -101,7 +102,12 @@ export const checkBuilderEndpoint = async ({
|
|||
method,
|
||||
url,
|
||||
body,
|
||||
}: any) => {
|
||||
}: {
|
||||
config: TestConfiguration
|
||||
method: string
|
||||
url: string
|
||||
body: any
|
||||
}) => {
|
||||
const headers = await config.login({
|
||||
userId: "us_fail",
|
||||
builder: false,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { Layout } from "@budibase/types"
|
||||
|
||||
export const BASE_LAYOUT_PROP_IDS = {
|
||||
PRIVATE: "layout_private_master",
|
||||
PUBLIC: "layout_public_master",
|
||||
}
|
||||
|
||||
export const EMPTY_LAYOUT = {
|
||||
export const EMPTY_LAYOUT: Layout = {
|
||||
componentLibraries: ["@budibase/standard-components"],
|
||||
title: "{{ name }}",
|
||||
favicon: "./_shared/favicon.png",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { roles } from "@budibase/backend-core"
|
||||
import { BASE_LAYOUT_PROP_IDS } from "./layouts"
|
||||
import { Screen } from "@budibase/types"
|
||||
|
||||
export function createHomeScreen(
|
||||
config: {
|
||||
|
@ -9,10 +10,8 @@ export function createHomeScreen(
|
|||
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
||||
route: "/",
|
||||
}
|
||||
) {
|
||||
): Screen {
|
||||
return {
|
||||
description: "",
|
||||
url: "",
|
||||
layoutId: BASE_LAYOUT_PROP_IDS.PRIVATE,
|
||||
props: {
|
||||
_id: "d834fea2-1b3e-4320-ab34-f9009f5ecc59",
|
||||
|
|
|
@ -53,9 +53,12 @@ import {
|
|||
Datasource,
|
||||
FieldType,
|
||||
INTERNAL_TABLE_SOURCE_ID,
|
||||
Layout,
|
||||
Query,
|
||||
RelationshipFieldMetadata,
|
||||
RelationshipType,
|
||||
Row,
|
||||
Screen,
|
||||
SearchParams,
|
||||
SourceName,
|
||||
Table,
|
||||
|
@ -63,6 +66,7 @@ import {
|
|||
User,
|
||||
UserCtx,
|
||||
View,
|
||||
Webhook,
|
||||
WithRequired,
|
||||
} from "@budibase/types"
|
||||
|
||||
|
@ -182,6 +186,15 @@ export default class TestConfiguration {
|
|||
return this.automation
|
||||
}
|
||||
|
||||
getDatasource() {
|
||||
if (!this.datasource) {
|
||||
throw new Error(
|
||||
"datasource has not been initialised, call config.init() first"
|
||||
)
|
||||
}
|
||||
return this.datasource
|
||||
}
|
||||
|
||||
async doInContext<T>(
|
||||
appId: string | undefined,
|
||||
task: () => Promise<T>
|
||||
|
@ -288,10 +301,10 @@ export default class TestConfiguration {
|
|||
|
||||
// UTILS
|
||||
|
||||
_req<Req extends Record<string, any>, Res>(
|
||||
_req<Req extends Record<string, any> | void, Res>(
|
||||
handler: (ctx: UserCtx<Req, Res>) => Promise<void>,
|
||||
body?: Req,
|
||||
params?: Record<string, string>
|
||||
params?: Record<string, string | undefined>
|
||||
): Promise<Res> {
|
||||
// create a fake request ctx
|
||||
const request: any = {}
|
||||
|
@ -399,7 +412,7 @@ export default class TestConfiguration {
|
|||
builder,
|
||||
prodApp,
|
||||
}: {
|
||||
roleId: string
|
||||
roleId?: string
|
||||
userId: string
|
||||
builder: boolean
|
||||
prodApp: boolean
|
||||
|
@ -415,7 +428,7 @@ export default class TestConfiguration {
|
|||
await this.globalUser({
|
||||
_id: userId,
|
||||
builder: { global: builder },
|
||||
roles: { [appId]: roleId },
|
||||
roles: { [appId]: roleId || roles.BUILTIN_ROLE_IDS.BASIC },
|
||||
})
|
||||
}
|
||||
await sessions.createASession(userId, {
|
||||
|
@ -772,7 +785,7 @@ export default class TestConfiguration {
|
|||
return this._req(automationController.fetch)
|
||||
}
|
||||
|
||||
async deleteAutomation(automation?: any) {
|
||||
async deleteAutomation(automation?: Automation) {
|
||||
automation = automation || this.automation
|
||||
if (!automation) {
|
||||
return
|
||||
|
@ -783,7 +796,7 @@ export default class TestConfiguration {
|
|||
})
|
||||
}
|
||||
|
||||
async createWebhook(config?: any) {
|
||||
async createWebhook(config?: Webhook) {
|
||||
if (!this.automation) {
|
||||
throw "Must create an automation before creating webhook."
|
||||
}
|
||||
|
@ -811,7 +824,7 @@ export default class TestConfiguration {
|
|||
return { ...this.datasource, _id: this.datasource!._id! }
|
||||
}
|
||||
|
||||
async restDatasource(cfg?: any) {
|
||||
async restDatasource(cfg?: Record<string, any>) {
|
||||
return this.createDatasource({
|
||||
datasource: {
|
||||
...basicDatasource().datasource,
|
||||
|
@ -868,24 +881,23 @@ export default class TestConfiguration {
|
|||
|
||||
// QUERY
|
||||
|
||||
async createQuery(config?: any) {
|
||||
if (!this.datasource && !config) {
|
||||
throw "No datasource created for query."
|
||||
}
|
||||
config = config || basicQuery(this.datasource!._id!)
|
||||
return this._req(queryController.save, config)
|
||||
async createQuery(config?: Query) {
|
||||
return this._req(
|
||||
queryController.save,
|
||||
config || basicQuery(this.getDatasource()._id!)
|
||||
)
|
||||
}
|
||||
|
||||
// SCREEN
|
||||
|
||||
async createScreen(config?: any) {
|
||||
async createScreen(config?: Screen) {
|
||||
config = config || basicScreen()
|
||||
return this._req(screenController.save, config)
|
||||
}
|
||||
|
||||
// LAYOUT
|
||||
|
||||
async createLayout(config?: any) {
|
||||
async createLayout(config?: Layout) {
|
||||
config = config || basicLayout()
|
||||
return await this._req(layoutController.save, config)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import {
|
|||
INTERNAL_TABLE_SOURCE_ID,
|
||||
TableSourceType,
|
||||
Query,
|
||||
Webhook,
|
||||
WebhookActionType,
|
||||
} from "@budibase/types"
|
||||
import { LoopInput, LoopStepType } from "../../definitions/automations"
|
||||
|
||||
|
@ -407,12 +409,12 @@ export function basicLayout() {
|
|||
return cloneDeep(EMPTY_LAYOUT)
|
||||
}
|
||||
|
||||
export function basicWebhook(automationId: string) {
|
||||
export function basicWebhook(automationId: string): Webhook {
|
||||
return {
|
||||
live: true,
|
||||
name: "webhook",
|
||||
action: {
|
||||
type: "automation",
|
||||
type: WebhookActionType.AUTOMATION,
|
||||
target: automationId,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { Document } from "../document"
|
||||
|
||||
export interface Layout extends Document {
|
||||
componentLibraries: string[]
|
||||
title: string
|
||||
favicon: string
|
||||
stylesheets: string[]
|
||||
props: any
|
||||
layoutId?: string
|
||||
name?: string
|
||||
}
|
||||
|
|
|
@ -22,4 +22,5 @@ export interface Screen extends Document {
|
|||
routing: ScreenRouting
|
||||
props: ScreenProps
|
||||
name?: string
|
||||
pluginAdded?: boolean
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue