2021-03-25 07:21:23 +13:00
|
|
|
const selfHostMiddleware = require("../selfhost")
|
2021-03-09 04:46:12 +13:00
|
|
|
const env = require("../../environment")
|
2021-05-15 02:43:41 +12:00
|
|
|
jest.mock("../../environment")
|
2021-03-06 03:13:43 +13:00
|
|
|
|
2021-03-10 00:33:16 +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", () => {
|
2021-03-10 00:33:16 +13:00
|
|
|
let config
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
config = new TestConfiguration()
|
|
|
|
})
|
2021-03-06 03:13:43 +13:00
|
|
|
|
2021-03-09 04:46:12 +13:00
|
|
|
afterEach(() => {
|
2021-03-10 00:33:16 +13:00
|
|
|
config.afterEach()
|
2021-03-09 04:46:12 +13:00
|
|
|
})
|
|
|
|
|
2021-03-25 07:21:23 +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
|
|
|
|
|
2021-03-10 00:33:16 +13:00
|
|
|
await config.executeMiddleware()
|
|
|
|
expect(config.next).toHaveBeenCalled()
|
2021-03-09 04:46:12 +13:00
|
|
|
})
|
2021-03-06 03:13:43 +13:00
|
|
|
})
|