More types.
This commit is contained in:
parent
fde5825589
commit
bfb0064289
|
@ -72,7 +72,9 @@ function cleanAutomationInputs(automation: Automation) {
|
||||||
return automation
|
return automation
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create(ctx: UserCtx) {
|
export async function create(
|
||||||
|
ctx: UserCtx<Automation, { message: string; automation: Automation }>
|
||||||
|
) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
let automation = ctx.request.body
|
let automation = ctx.request.body
|
||||||
automation.appId = ctx.appId
|
automation.appId = ctx.appId
|
||||||
|
|
|
@ -394,7 +394,7 @@ describe("/automations", () => {
|
||||||
it("deletes a automation by its ID", async () => {
|
it("deletes a automation by its ID", async () => {
|
||||||
const automation = await config.createAutomation()
|
const automation = await config.createAutomation()
|
||||||
const res = await request
|
const res = await request
|
||||||
.delete(`/api/automations/${automation.id}/${automation.rev}`)
|
.delete(`/api/automations/${automation._id}/${automation._rev}`)
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
@ -408,7 +408,7 @@ describe("/automations", () => {
|
||||||
await checkBuilderEndpoint({
|
await checkBuilderEndpoint({
|
||||||
config,
|
config,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
url: `/api/automations/${automation.id}/${automation._rev}`,
|
url: `/api/automations/${automation._id}/${automation._rev}`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -44,7 +44,7 @@ describe("/backups", () => {
|
||||||
|
|
||||||
expect(headers["content-disposition"]).toEqual(
|
expect(headers["content-disposition"]).toEqual(
|
||||||
`attachment; filename="${
|
`attachment; filename="${
|
||||||
config.getApp()!.name
|
config.getApp().name
|
||||||
}-export-${mocks.date.MOCK_DATE.getTime()}.tar.gz"`
|
}-export-${mocks.date.MOCK_DATE.getTime()}.tar.gz"`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,7 +36,7 @@ describe("/webhooks", () => {
|
||||||
const automation = await config.createAutomation()
|
const automation = await config.createAutomation()
|
||||||
const res = await request
|
const res = await request
|
||||||
.put(`/api/webhooks`)
|
.put(`/api/webhooks`)
|
||||||
.send(basicWebhook(automation._id))
|
.send(basicWebhook(automation._id!))
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
@ -145,7 +145,7 @@ describe("/webhooks", () => {
|
||||||
let automation = collectAutomation()
|
let automation = collectAutomation()
|
||||||
let newAutomation = await config.createAutomation(automation)
|
let newAutomation = await config.createAutomation(automation)
|
||||||
let syncWebhook = await config.createWebhook(
|
let syncWebhook = await config.createWebhook(
|
||||||
basicWebhook(newAutomation._id)
|
basicWebhook(newAutomation._id!)
|
||||||
)
|
)
|
||||||
|
|
||||||
// replicate changes before checking webhook
|
// replicate changes before checking webhook
|
||||||
|
|
|
@ -61,7 +61,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
User,
|
User,
|
||||||
UserRoles,
|
UserCtx,
|
||||||
View,
|
View,
|
||||||
WithRequired,
|
WithRequired,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -70,7 +70,6 @@ import API from "./api"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
import jwt, { Secret } from "jsonwebtoken"
|
import jwt, { Secret } from "jsonwebtoken"
|
||||||
import { Server } from "http"
|
import { Server } from "http"
|
||||||
import { userDetailListType } from "aws-sdk/clients/iam"
|
|
||||||
|
|
||||||
mocks.licenses.init(pro)
|
mocks.licenses.init(pro)
|
||||||
|
|
||||||
|
@ -89,14 +88,14 @@ export default class TestConfiguration {
|
||||||
request?: supertest.SuperTest<supertest.Test>
|
request?: supertest.SuperTest<supertest.Test>
|
||||||
started: boolean
|
started: boolean
|
||||||
appId?: string
|
appId?: string
|
||||||
allApps: any[]
|
allApps: App[]
|
||||||
app?: App
|
app?: App
|
||||||
prodApp?: App
|
prodApp?: App
|
||||||
prodAppId?: string
|
prodAppId?: string
|
||||||
user?: User
|
user?: User
|
||||||
userMetadataId?: string
|
userMetadataId?: string
|
||||||
table?: Table
|
table?: Table
|
||||||
automation: any
|
automation?: Automation
|
||||||
datasource?: Datasource
|
datasource?: Datasource
|
||||||
tenantId?: string
|
tenantId?: string
|
||||||
api: API
|
api: API
|
||||||
|
@ -124,16 +123,26 @@ export default class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
getApp() {
|
getApp() {
|
||||||
|
if (!this.app) {
|
||||||
|
throw new Error("app has not been initialised, call config.init() first")
|
||||||
|
}
|
||||||
return this.app
|
return this.app
|
||||||
}
|
}
|
||||||
|
|
||||||
getProdApp() {
|
getProdApp() {
|
||||||
|
if (!this.prodApp) {
|
||||||
|
throw new Error(
|
||||||
|
"prodApp has not been initialised, call config.init() first"
|
||||||
|
)
|
||||||
|
}
|
||||||
return this.prodApp
|
return this.prodApp
|
||||||
}
|
}
|
||||||
|
|
||||||
getAppId() {
|
getAppId() {
|
||||||
if (!this.appId) {
|
if (!this.appId) {
|
||||||
throw new Error("appId has not been initialised properly")
|
throw new Error(
|
||||||
|
"appId has not been initialised, call config.init() first"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return this.appId
|
return this.appId
|
||||||
}
|
}
|
||||||
|
@ -164,6 +173,15 @@ export default class TestConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAutomation() {
|
||||||
|
if (!this.automation) {
|
||||||
|
throw new Error(
|
||||||
|
"automation has not been initialised, call config.init() first"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return this.automation
|
||||||
|
}
|
||||||
|
|
||||||
async doInContext<T>(
|
async doInContext<T>(
|
||||||
appId: string | undefined,
|
appId: string | undefined,
|
||||||
task: () => Promise<T>
|
task: () => Promise<T>
|
||||||
|
@ -270,11 +288,11 @@ export default class TestConfiguration {
|
||||||
|
|
||||||
// UTILS
|
// UTILS
|
||||||
|
|
||||||
_req<Req extends Record<string, any>, Res, Context extends Ctx<Req, Res>>(
|
_req<Req extends Record<string, any>, Res>(
|
||||||
handler: (ctx: Context) => Promise<void>,
|
handler: (ctx: UserCtx<Req, Res>) => Promise<void>,
|
||||||
body?: Req,
|
body?: Req,
|
||||||
params?: Record<string, string>
|
params?: Record<string, string>
|
||||||
) {
|
): Promise<Res> {
|
||||||
// create a fake request ctx
|
// create a fake request ctx
|
||||||
const request: any = {}
|
const request: any = {}
|
||||||
const appId = this.appId
|
const appId = this.appId
|
||||||
|
@ -539,19 +557,20 @@ export default class TestConfiguration {
|
||||||
// create dev app
|
// create dev app
|
||||||
// clear any old app
|
// clear any old app
|
||||||
this.appId = undefined
|
this.appId = undefined
|
||||||
this.app = await context.doInTenant(this.tenantId!, async () => {
|
this.app = await context.doInTenant(
|
||||||
const app = (await this._req(appController.create, {
|
this.tenantId!,
|
||||||
name: appName,
|
async () =>
|
||||||
})) as App
|
(await this._req(appController.create, {
|
||||||
this.appId = app.appId!
|
name: appName,
|
||||||
return app
|
})) as App
|
||||||
})
|
)
|
||||||
|
this.appId = this.app.appId
|
||||||
return await context.doInAppContext(this.app.appId!, async () => {
|
return await context.doInAppContext(this.app.appId!, async () => {
|
||||||
// create production app
|
// create production app
|
||||||
this.prodApp = await this.publish()
|
this.prodApp = await this.publish()
|
||||||
|
|
||||||
this.allApps.push(this.prodApp)
|
this.allApps.push(this.prodApp)
|
||||||
this.allApps.push(this.app)
|
this.allApps.push(this.app!)
|
||||||
|
|
||||||
return this.app!
|
return this.app!
|
||||||
})
|
})
|
||||||
|
@ -739,14 +758,13 @@ export default class TestConfiguration {
|
||||||
|
|
||||||
// AUTOMATION
|
// AUTOMATION
|
||||||
|
|
||||||
async createAutomation(config?: any) {
|
async createAutomation(config?: Automation) {
|
||||||
config = config || basicAutomation()
|
config = config || basicAutomation()
|
||||||
if (config._rev) {
|
if (config._rev) {
|
||||||
delete config._rev
|
delete config._rev
|
||||||
}
|
}
|
||||||
this.automation = (
|
const res = await this._req(automationController.create, config)
|
||||||
await this._req(automationController.create, config)
|
this.automation = res.automation
|
||||||
).automation
|
|
||||||
return this.automation
|
return this.automation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +787,7 @@ export default class TestConfiguration {
|
||||||
if (!this.automation) {
|
if (!this.automation) {
|
||||||
throw "Must create an automation before creating webhook."
|
throw "Must create an automation before creating webhook."
|
||||||
}
|
}
|
||||||
config = config || basicWebhook(this.automation._id)
|
config = config || basicWebhook(this.automation._id!)
|
||||||
|
|
||||||
return (await this._req(webhookController.save, config)).webhook
|
return (await this._req(webhookController.save, config)).webhook
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue