diff --git a/packages/backend-core/src/events/handlers/layout.js b/packages/backend-core/src/events/handlers/layout.js index 682a0e6655..fdeda28d60 100644 --- a/packages/backend-core/src/events/handlers/layout.js +++ b/packages/backend-core/src/events/handlers/layout.js @@ -1,15 +1,11 @@ const events = require("../events") const { Events } = require("../constants") -// LAYOUT - -// TODO exports.created = () => { const properties = {} events.processEvent(Events.LAYOUT_CREATED, properties) } -// TODO exports.deleted = () => { const properties = {} events.processEvent(Events.LAYOUT_DELETED, properties) diff --git a/packages/backend-core/src/tests/utilities/mocks/events.js b/packages/backend-core/src/tests/utilities/mocks/events.js index 74e62ef73c..0ee2eb0b27 100644 --- a/packages/backend-core/src/tests/utilities/mocks/events.js +++ b/packages/backend-core/src/tests/utilities/mocks/events.js @@ -44,6 +44,10 @@ jest.mock("../../../events", () => { SMTPCreated: jest.fn(), SMTPUpdated: jest.fn(), }, + layout: { + created: jest.fn(), + deleted: jest.fn(), + }, } }) diff --git a/packages/server/src/api/controllers/layout.js b/packages/server/src/api/controllers/layout.js index a92eec424a..1809fce344 100644 --- a/packages/server/src/api/controllers/layout.js +++ b/packages/server/src/api/controllers/layout.js @@ -4,6 +4,7 @@ const { } = require("../../constants/layouts") const { generateLayoutID, getScreenParams } = require("../../db/utils") const { getAppDB } = require("@budibase/backend-core/context") +const { events } = require("@budibase/backend-core") exports.save = async function (ctx) { const db = getAppDB() @@ -19,6 +20,7 @@ exports.save = async function (ctx) { layout._id = layout._id || generateLayoutID() const response = await db.put(layout) + events.layout.created() layout._rev = response.rev ctx.body = layout @@ -46,6 +48,7 @@ exports.destroy = async function (ctx) { } await db.remove(layoutId, layoutRev) + events.layout.deleted() ctx.body = { message: "Layout deleted successfully" } ctx.status = 200 } diff --git a/packages/server/src/api/routes/tests/layout.spec.js b/packages/server/src/api/routes/tests/layout.spec.js index 4842b2cc8e..c149a0fec5 100644 --- a/packages/server/src/api/routes/tests/layout.spec.js +++ b/packages/server/src/api/routes/tests/layout.spec.js @@ -1,6 +1,7 @@ const { checkBuilderEndpoint } = require("./utilities/TestFunctions") const setup = require("./utilities") const { basicLayout } = setup.structures +const { events } = require("@budibase/backend-core") describe("/layouts", () => { let request = setup.getRequest() @@ -12,6 +13,7 @@ describe("/layouts", () => { beforeEach(async () => { await config.init() layout = await config.createLayout() + jest.clearAllMocks() }) describe("save", () => { @@ -23,6 +25,7 @@ describe("/layouts", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body._rev).toBeDefined() + expect(events.layout.created).toBeCalledTimes(1) }) it("should apply authorization to endpoint", async () => { @@ -42,6 +45,7 @@ describe("/layouts", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.message).toBeDefined() + expect(events.layout.deleted).toBeCalledTimes(1) }) it("should apply authorization to endpoint", async () => {