layout events + tests
This commit is contained in:
parent
e3cf9b0661
commit
7846fff25d
|
@ -1,15 +1,11 @@
|
||||||
const events = require("../events")
|
const events = require("../events")
|
||||||
const { Events } = require("../constants")
|
const { Events } = require("../constants")
|
||||||
|
|
||||||
// LAYOUT
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.created = () => {
|
exports.created = () => {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.LAYOUT_CREATED, properties)
|
events.processEvent(Events.LAYOUT_CREATED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.deleted = () => {
|
exports.deleted = () => {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
events.processEvent(Events.LAYOUT_DELETED, properties)
|
events.processEvent(Events.LAYOUT_DELETED, properties)
|
||||||
|
|
|
@ -44,6 +44,10 @@ jest.mock("../../../events", () => {
|
||||||
SMTPCreated: jest.fn(),
|
SMTPCreated: jest.fn(),
|
||||||
SMTPUpdated: jest.fn(),
|
SMTPUpdated: jest.fn(),
|
||||||
},
|
},
|
||||||
|
layout: {
|
||||||
|
created: jest.fn(),
|
||||||
|
deleted: jest.fn(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ const {
|
||||||
} = require("../../constants/layouts")
|
} = require("../../constants/layouts")
|
||||||
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
const { getAppDB } = require("@budibase/backend-core/context")
|
||||||
|
const { events } = require("@budibase/backend-core")
|
||||||
|
|
||||||
exports.save = async function (ctx) {
|
exports.save = async function (ctx) {
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
|
@ -19,6 +20,7 @@ exports.save = async function (ctx) {
|
||||||
|
|
||||||
layout._id = layout._id || generateLayoutID()
|
layout._id = layout._id || generateLayoutID()
|
||||||
const response = await db.put(layout)
|
const response = await db.put(layout)
|
||||||
|
events.layout.created()
|
||||||
layout._rev = response.rev
|
layout._rev = response.rev
|
||||||
|
|
||||||
ctx.body = layout
|
ctx.body = layout
|
||||||
|
@ -46,6 +48,7 @@ exports.destroy = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.remove(layoutId, layoutRev)
|
await db.remove(layoutId, layoutRev)
|
||||||
|
events.layout.deleted()
|
||||||
ctx.body = { message: "Layout deleted successfully" }
|
ctx.body = { message: "Layout deleted successfully" }
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
const setup = require("./utilities")
|
const setup = require("./utilities")
|
||||||
const { basicLayout } = setup.structures
|
const { basicLayout } = setup.structures
|
||||||
|
const { events } = require("@budibase/backend-core")
|
||||||
|
|
||||||
describe("/layouts", () => {
|
describe("/layouts", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
|
@ -12,6 +13,7 @@ describe("/layouts", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
layout = await config.createLayout()
|
layout = await config.createLayout()
|
||||||
|
jest.clearAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("save", () => {
|
describe("save", () => {
|
||||||
|
@ -23,6 +25,7 @@ describe("/layouts", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body._rev).toBeDefined()
|
expect(res.body._rev).toBeDefined()
|
||||||
|
expect(events.layout.created).toBeCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
@ -42,6 +45,7 @@ describe("/layouts", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body.message).toBeDefined()
|
expect(res.body.message).toBeDefined()
|
||||||
|
expect(events.layout.deleted).toBeCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
|
Loading…
Reference in New Issue