unit tests

This commit is contained in:
Martin McKeaveney 2021-05-06 10:54:01 +01:00
parent f82754a544
commit 7d09bd8d70
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,38 @@
const setup = require("./utilities")
// mock the email system
const sendMailMock = jest.fn()
jest.mock("nodemailer")
const nodemailer = require("nodemailer")
nodemailer.createTransport.mockReturnValue({
verify: jest.fn()
})
describe("/api/admin/configs/checklist", () => {
let request = setup.getRequest()
let config = setup.getConfig()
beforeAll(async () => {
await config.init()
})
afterAll(setup.afterAll)
it("should return the correct checklist status based on the state of the budibase installation", async () => {
// initially configure settings
await config.saveAdminUser()
await config.saveSmtpConfig()
const res = await request
.get(`/api/admin/configs/checklist`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const checklist = res.body
expect(checklist.apps).toBe(0)
expect(checklist.smtp).toBe(true)
expect(checklist.adminUser).toBe(true)
})
})

View File

@ -105,6 +105,22 @@ class TestConfiguration {
)
}
async saveOAuthConfig() {
await this.deleteConfig(Configs.GOOGLE)
await this._req(
{
type: Configs.GOOGLE,
config: {
callbackURL: "http://somecallbackurl",
clientID: "clientId",
clientSecret: "clientSecret",
},
},
null,
controllers.config.save
)
}
async saveSmtpConfig() {
await this.deleteConfig(Configs.SMTP)
await this._req(
@ -141,6 +157,17 @@ class TestConfiguration {
controllers.config.save
)
}
async saveAdminUser() {
await this._req(
{
email: "testuser@test.com",
password: "test@test.com"
},
null,
controllers.users.adminUser
)
}
}
module.exports = TestConfiguration