layout events + tests

This commit is contained in:
Rory Powell 2022-04-06 22:07:21 +01:00
parent cd0e37d2c1
commit deaf0de349
4 changed files with 11 additions and 4 deletions

View File

@ -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)

View File

@ -44,6 +44,10 @@ jest.mock("../../../events", () => {
SMTPCreated: jest.fn(),
SMTPUpdated: jest.fn(),
},
layout: {
created: jest.fn(),
deleted: jest.fn(),
},
}
})

View File

@ -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
}

View File

@ -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 () => {