builder / app / app preview served events
This commit is contained in:
parent
e725b1fb52
commit
eec094b581
|
@ -64,8 +64,10 @@ exports.Events = {
|
||||||
ROLE_ASSIGNED: "role:assigned",
|
ROLE_ASSIGNED: "role:assigned",
|
||||||
ROLE_UNASSIGNED: "role:unassigned",
|
ROLE_UNASSIGNED: "role:unassigned",
|
||||||
|
|
||||||
// APP / CLIENT
|
// SERVE
|
||||||
CLIENT_SERVED: "client:served",
|
SERVED_BUILDER: "served:builder",
|
||||||
|
SERVED_APP: "served:app",
|
||||||
|
SERVED_APP_PREVIEW: "served:app:preview",
|
||||||
|
|
||||||
// DATASOURCE
|
// DATASOURCE
|
||||||
DATASOURCE_CREATED: "datasource:created",
|
DATASOURCE_CREATED: "datasource:created",
|
||||||
|
@ -102,9 +104,6 @@ exports.Events = {
|
||||||
// ROW
|
// ROW
|
||||||
// ROW_CREATED: "row:created",
|
// ROW_CREATED: "row:created",
|
||||||
|
|
||||||
// BUILDER
|
|
||||||
BUILDER_SERVED: "builder:served",
|
|
||||||
|
|
||||||
// COMPONENT
|
// COMPONENT
|
||||||
COMPONENT_CREATED: "component:created",
|
COMPONENT_CREATED: "component:created",
|
||||||
COMPONENT_DELETED: "component:deleted",
|
COMPONENT_DELETED: "component:deleted",
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
const events = require("../events")
|
const events = require("../events")
|
||||||
const { Events } = require("../constants")
|
const { Events } = require("../constants")
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.created = () => {
|
exports.created = () => {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.SCREEN_CREATED, properties)
|
events.processEvent(Events.SCREEN_CREATED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.deleted = () => {
|
exports.deleted = () => {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.SCREEN_DELETED, properties)
|
events.processEvent(Events.SCREEN_DELETED, properties)
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
const events = require("../events")
|
const events = require("../events")
|
||||||
const { Events } = require("../constants")
|
const { Events } = require("../constants")
|
||||||
|
|
||||||
// TODO
|
/* eslint-disable */
|
||||||
exports.builderServed = () => {
|
|
||||||
|
exports.servedBuilder = version => {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.BUILDER_SERVED, properties)
|
events.processEvent(Events.SERVED_BUILDER, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
exports.servedApp = appMetadata => {
|
||||||
exports.clientServed = () => {
|
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.CLIENT_SERVED, properties)
|
events.processEvent(Events.SERVED_APP, properties)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.servedAppPreview = appMetadata => {
|
||||||
|
const properties = {}
|
||||||
|
events.processEvent(Events.SERVED_APP_PREVIEW, properties)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,11 @@ jest.mock("../../../events", () => {
|
||||||
passwordResetRequested: jest.fn(),
|
passwordResetRequested: jest.fn(),
|
||||||
passwordReset: jest.fn(),
|
passwordReset: jest.fn(),
|
||||||
},
|
},
|
||||||
serve: {},
|
serve: {
|
||||||
|
servedBuilder: jest.fn(),
|
||||||
|
servedApp: jest.fn(),
|
||||||
|
servedAppPreview: jest.fn(),
|
||||||
|
},
|
||||||
table: {},
|
table: {},
|
||||||
view: {},
|
view: {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,12 @@ const env = require("../../../environment")
|
||||||
const { clientLibraryPath } = require("../../../utilities")
|
const { clientLibraryPath } = require("../../../utilities")
|
||||||
const { upload } = require("../../../utilities/fileSystem")
|
const { upload } = require("../../../utilities/fileSystem")
|
||||||
const { attachmentsRelativeURL } = require("../../../utilities")
|
const { attachmentsRelativeURL } = require("../../../utilities")
|
||||||
const { DocumentTypes } = require("../../../db/utils")
|
const { DocumentTypes, isDevAppID } = require("../../../db/utils")
|
||||||
const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
|
const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
|
||||||
const AWS = require("aws-sdk")
|
const AWS = require("aws-sdk")
|
||||||
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
||||||
|
const { events } = require("@budibase/backend-core")
|
||||||
|
const version = require("../../../../package.json").version
|
||||||
|
|
||||||
async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
||||||
const response = await upload({
|
const response = await upload({
|
||||||
|
@ -57,6 +59,7 @@ async function getAppIdFromUrl(ctx) {
|
||||||
exports.serveBuilder = async function (ctx) {
|
exports.serveBuilder = async function (ctx) {
|
||||||
let builderPath = resolve(TOP_LEVEL_PATH, "builder")
|
let builderPath = resolve(TOP_LEVEL_PATH, "builder")
|
||||||
await send(ctx, ctx.file, { root: builderPath })
|
await send(ctx, ctx.file, { root: builderPath })
|
||||||
|
events.serve.servedBuilder(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.uploadFile = async function (ctx) {
|
exports.uploadFile = async function (ctx) {
|
||||||
|
@ -82,10 +85,11 @@ exports.uploadFile = async function (ctx) {
|
||||||
|
|
||||||
exports.serveApp = async function (ctx) {
|
exports.serveApp = async function (ctx) {
|
||||||
let appId = await getAppIdFromUrl(ctx)
|
let appId = await getAppIdFromUrl(ctx)
|
||||||
const App = require("./templates/BudibaseApp.svelte").default
|
|
||||||
const db = getAppDB({ skip_setup: true })
|
const db = getAppDB({ skip_setup: true })
|
||||||
const appInfo = await db.get(DocumentTypes.APP_METADATA)
|
const appInfo = await db.get(DocumentTypes.APP_METADATA)
|
||||||
|
|
||||||
|
if (!env.isJest()) {
|
||||||
|
const App = require("./templates/BudibaseApp.svelte").default
|
||||||
const { head, html, css } = App.render({
|
const { head, html, css } = App.render({
|
||||||
title: appInfo.name,
|
title: appInfo.name,
|
||||||
production: env.isProd(),
|
production: env.isProd(),
|
||||||
|
@ -100,6 +104,16 @@ exports.serveApp = async function (ctx) {
|
||||||
style: css.code,
|
style: css.code,
|
||||||
appId,
|
appId,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// just return the app info for jest to assert on
|
||||||
|
ctx.body = appInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDevAppID(appInfo.appId)) {
|
||||||
|
events.serve.servedAppPreview(appInfo)
|
||||||
|
} else {
|
||||||
|
events.serve.servedApp(appInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.serveClientLibrary = async function (ctx) {
|
exports.serveClientLibrary = async function (ctx) {
|
||||||
|
|
|
@ -72,11 +72,9 @@ router.use(async (ctx, next) => {
|
||||||
validationErrors: err.validation,
|
validationErrors: err.validation,
|
||||||
error,
|
error,
|
||||||
}
|
}
|
||||||
if (env.NODE_ENV !== "jest") {
|
|
||||||
ctx.log.error(err)
|
ctx.log.error(err)
|
||||||
console.trace(err)
|
console.trace(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get("/health", ctx => (ctx.status = 200))
|
router.get("/health", ctx => (ctx.status = 200))
|
||||||
|
|
|
@ -14,8 +14,10 @@ jest.mock("aws-sdk", () => ({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const setup = require("./utilities")
|
const setup = require("./utilities")
|
||||||
|
const { events } = require("@budibase/backend-core")
|
||||||
|
const version = require("../../../../package.json").version
|
||||||
|
|
||||||
describe("/attachments", () => {
|
describe("/static", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let app
|
let app
|
||||||
|
@ -26,6 +28,64 @@ describe("/attachments", () => {
|
||||||
app = await config.init()
|
app = await config.init()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("/builder", () => {
|
||||||
|
it("should serve the builder", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get("/builder/portal")
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect("Content-Type", /text\/html/)
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.text).toContain("<title>Budibase</title>")
|
||||||
|
expect(events.serve.servedBuilder).toBeCalledTimes(1)
|
||||||
|
expect(events.serve.servedBuilder).toBeCalledWith(version)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/app", () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should serve the app by id", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`/${config.prodAppId}`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.body.appId).toBe(config.prodAppId)
|
||||||
|
expect(events.serve.servedApp).toBeCalledTimes(1)
|
||||||
|
expect(events.serve.servedApp).toBeCalledWith(res.body)
|
||||||
|
expect(events.serve.servedAppPreview).not.toBeCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should serve the app by url", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`${config.prodApp.url}`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.body.appId).toBe(config.prodAppId)
|
||||||
|
expect(events.serve.servedApp).toBeCalledTimes(1)
|
||||||
|
expect(events.serve.servedApp).toBeCalledWith(res.body)
|
||||||
|
expect(events.serve.servedAppPreview).not.toBeCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should serve the app preview by id", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`/${config.appId}`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.body.appId).toBe(config.appId)
|
||||||
|
expect(events.serve.servedAppPreview).toBeCalledTimes(1)
|
||||||
|
expect(events.serve.servedAppPreview).toBeCalledWith(res.body)
|
||||||
|
expect(events.serve.servedApp).not.toBeCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/attachments", () => {
|
||||||
describe("generateSignedUrls", () => {
|
describe("generateSignedUrls", () => {
|
||||||
let datasource
|
let datasource
|
||||||
|
|
||||||
|
@ -96,3 +156,5 @@ describe("/attachments", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
function isTest() {
|
function isTest() {
|
||||||
|
return isCypress() || isJest()
|
||||||
|
}
|
||||||
|
|
||||||
|
function isJest() {
|
||||||
return (
|
return (
|
||||||
process.env.NODE_ENV === "jest" ||
|
process.env.NODE_ENV === "jest" ||
|
||||||
process.env.NODE_ENV === "cypress" ||
|
|
||||||
(process.env.JEST_WORKER_ID != null &&
|
(process.env.JEST_WORKER_ID != null &&
|
||||||
process.env.JEST_WORKER_ID !== "null")
|
process.env.JEST_WORKER_ID !== "null")
|
||||||
)
|
)
|
||||||
|
@ -73,6 +76,7 @@ module.exports = {
|
||||||
module.exports[key] = value
|
module.exports[key] = value
|
||||||
},
|
},
|
||||||
isTest,
|
isTest,
|
||||||
|
isJest,
|
||||||
isCypress,
|
isCypress,
|
||||||
isDev,
|
isDev,
|
||||||
isProd: () => {
|
isProd: () => {
|
||||||
|
|
Loading…
Reference in New Issue