1
0
Fork 0
mirror of synced 2024-06-22 04:10:54 +12:00
budibase/packages/server/src/middleware/tests/selfhost.spec.js

44 lines
811 B
JavaScript

const selfHostMiddleware = require("../selfhost")
const env = require("../../environment")
jest.mock("../../environment")
class TestConfiguration {
constructor() {
this.next = jest.fn()
this.throw = jest.fn()
this.middleware = selfHostMiddleware
this.ctx = {
next: this.next,
throw: this.throw
}
}
executeMiddleware() {
return this.middleware(this.ctx, this.next)
}
afterEach() {
jest.clearAllMocks()
}
}
describe("Self host middleware", () => {
let config
beforeEach(() => {
config = new TestConfiguration()
})
afterEach(() => {
config.afterEach()
})
it("calls next() when SELF_HOSTED env var is set", async () => {
env.SELF_HOSTED = 1
await config.executeMiddleware()
expect(config.next).toHaveBeenCalled()
})
})