1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00
budibase/packages/server/src/middleware/tests/selfhost.spec.js

44 lines
811 B
JavaScript
Raw Normal View History

const selfHostMiddleware = require("../selfhost")
2021-03-09 04:46:12 +13:00
const env = require("../../environment")
jest.mock("../../environment")
2021-03-06 03:13:43 +13:00
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()
}
}
2021-03-06 03:13:43 +13:00
describe("Self host middleware", () => {
let config
beforeEach(() => {
config = new TestConfiguration()
})
2021-03-06 03:13:43 +13:00
2021-03-09 04:46:12 +13:00
afterEach(() => {
config.afterEach()
2021-03-09 04:46:12 +13:00
})
it("calls next() when SELF_HOSTED env var is set", async () => {
2021-03-09 04:46:12 +13:00
env.SELF_HOSTED = 1
await config.executeMiddleware()
expect(config.next).toHaveBeenCalled()
2021-03-09 04:46:12 +13:00
})
2021-03-06 03:13:43 +13:00
})