mirror of https://github.com/Budibase/budibase.git
nocodelowcodelow-codedockerdocker-composeinternal-projectinternal-toolinternal-toolslow-code-developmentlow-code-development-platformopensourceselfhostedweb-devweb-developmentweb-development-toolswebdevwebdevelopmentworkflow-automationautomationdeveloper-tools
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
3.1 KiB
146 lines
3.1 KiB
const env = require("../../../../environment")
|
|
const controllers = require("./controllers")
|
|
const supertest = require("supertest")
|
|
const { jwt } = require("@budibase/auth").auth
|
|
const { Cookies } = require("@budibase/auth").constants
|
|
const { Configs, LOGO_URL } = require("../../../../constants")
|
|
|
|
class TestConfiguration {
|
|
constructor(openServer = true) {
|
|
if (openServer) {
|
|
env.PORT = 4003
|
|
this.server = require("../../../../index")
|
|
// we need the request for logging in, involves cookies, hard to fake
|
|
this.request = supertest(this.server)
|
|
}
|
|
}
|
|
|
|
getRequest() {
|
|
return this.request
|
|
}
|
|
|
|
async _req(config, params, controlFunc) {
|
|
const request = {}
|
|
// fake cookies, we don't need them
|
|
request.cookies = { set: () => {}, get: () => {} }
|
|
request.config = { jwtSecret: env.JWT_SECRET }
|
|
request.appId = this.appId
|
|
request.user = { appId: this.appId }
|
|
request.query = {}
|
|
request.request = {
|
|
body: config,
|
|
}
|
|
if (params) {
|
|
request.params = params
|
|
}
|
|
await controlFunc(request)
|
|
return request.body
|
|
}
|
|
|
|
async init() {
|
|
// create a test user
|
|
await this._req(
|
|
{
|
|
email: "test@test.com",
|
|
password: "test",
|
|
_id: "us_uuid1",
|
|
builder: {
|
|
global: true,
|
|
},
|
|
},
|
|
null,
|
|
controllers.users.save
|
|
)
|
|
}
|
|
|
|
defaultHeaders() {
|
|
const user = {
|
|
_id: "us_uuid1",
|
|
userId: "us_uuid1",
|
|
}
|
|
const authToken = jwt.sign(user, env.JWT_SECRET)
|
|
return {
|
|
Accept: "application/json",
|
|
Cookie: [`${Cookies.Auth}=${authToken}`],
|
|
}
|
|
}
|
|
|
|
async deleteConfig(type) {
|
|
try {
|
|
const cfg = await this._req(
|
|
null,
|
|
{
|
|
type,
|
|
},
|
|
controllers.config.find
|
|
)
|
|
if (cfg) {
|
|
await this._req(
|
|
null,
|
|
{
|
|
id: cfg._id,
|
|
rev: cfg._rev,
|
|
},
|
|
controllers.config.destroy
|
|
)
|
|
}
|
|
} catch (err) {
|
|
// don't need to handle error
|
|
}
|
|
}
|
|
|
|
async saveSettingsConfig() {
|
|
await this.deleteConfig(Configs.SETTINGS)
|
|
await this._req(
|
|
{
|
|
type: Configs.SETTINGS,
|
|
config: {
|
|
platformUrl: "http://localhost:10000",
|
|
logoUrl: LOGO_URL,
|
|
company: "Budibase",
|
|
},
|
|
},
|
|
null,
|
|
controllers.config.save
|
|
)
|
|
}
|
|
|
|
async saveSmtpConfig() {
|
|
await this.deleteConfig(Configs.SMTP)
|
|
await this._req(
|
|
{
|
|
type: Configs.SMTP,
|
|
config: {
|
|
port: 12345,
|
|
host: "smtptesthost.com",
|
|
from: "testfrom@test.com",
|
|
subject: "Hello!",
|
|
},
|
|
},
|
|
null,
|
|
controllers.config.save
|
|
)
|
|
}
|
|
|
|
async saveEtherealSmtpConfig() {
|
|
await this.deleteConfig(Configs.SMTP)
|
|
await this._req(
|
|
{
|
|
type: Configs.SMTP,
|
|
config: {
|
|
port: 587,
|
|
host: "smtp.ethereal.email",
|
|
secure: false,
|
|
auth: {
|
|
user: "don.bahringer@ethereal.email",
|
|
pass: "yCKSH8rWyUPbnhGYk9",
|
|
},
|
|
},
|
|
},
|
|
null,
|
|
controllers.config.save
|
|
)
|
|
}
|
|
}
|
|
|
|
module.exports = TestConfiguration
|
|
|