Merge pull request #10959 from Budibase/fix/integration-tests
Integration test updates and improved logging
This commit is contained in:
commit
c5270ee323
|
@ -31,4 +31,6 @@ const config: Config.InitialOptions = {
|
|||
coverageReporters: ["lcov", "json", "clover"],
|
||||
}
|
||||
|
||||
process.env.DISABLE_PINO_LOGGER = "1"
|
||||
|
||||
export default config
|
||||
|
|
|
@ -489,7 +489,11 @@ class MongoIntegration implements IntegrationBase {
|
|||
|
||||
switch (query.extra.actionType) {
|
||||
case "find": {
|
||||
if (json) {
|
||||
return await collection.find(json).toArray()
|
||||
} else {
|
||||
return await collection.find().toArray()
|
||||
}
|
||||
}
|
||||
case "findOne": {
|
||||
return await collection.findOne(json)
|
||||
|
|
|
@ -38,7 +38,7 @@ const MAX_USERS_UPLOAD_LIMIT = 1000
|
|||
|
||||
export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
|
||||
try {
|
||||
const currentUserId = ctx.user._id
|
||||
const currentUserId = ctx.user?._id
|
||||
const requestUser = ctx.request.body
|
||||
|
||||
const user = await userSdk.save(requestUser, { currentUserId })
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"setup": "yarn && node scripts/createEnv.js",
|
||||
"user": "yarn && node scripts/createEnv.js && node scripts/createUser.js",
|
||||
"test": "jest --runInBand --json --outputFile=testResults.json --forceExit",
|
||||
"test:watch": "yarn run test --watch",
|
||||
"test:debug": "DEBUG=1 yarn run test",
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
const dotenv = require("dotenv")
|
||||
const { join } = require("path")
|
||||
const fs = require("fs")
|
||||
const fetch = require("node-fetch")
|
||||
|
||||
function getVarFromDotEnv(path, varName) {
|
||||
const parsed = dotenv.parse(fs.readFileSync(path))
|
||||
return parsed[varName]
|
||||
}
|
||||
|
||||
async function createUser() {
|
||||
const serverPath = join(__dirname, "..", "..", "packages", "server", ".env")
|
||||
const qaCorePath = join(__dirname, "..", ".env")
|
||||
const apiKey = getVarFromDotEnv(serverPath, "INTERNAL_API_KEY")
|
||||
const username = getVarFromDotEnv(qaCorePath, "BB_ADMIN_USER_EMAIL")
|
||||
const password = getVarFromDotEnv(qaCorePath, "BB_ADMIN_USER_PASSWORD")
|
||||
const url = getVarFromDotEnv(qaCorePath, "BUDIBASE_URL")
|
||||
const resp = await fetch(`${url}/api/public/v1/users`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-budibase-api-key": apiKey,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email: username,
|
||||
password,
|
||||
builder: {
|
||||
global: true,
|
||||
},
|
||||
admin: {
|
||||
global: true,
|
||||
},
|
||||
roles: {},
|
||||
}),
|
||||
})
|
||||
if (resp.status !== 200) {
|
||||
throw new Error(await resp.text())
|
||||
} else {
|
||||
return await resp.json()
|
||||
}
|
||||
}
|
||||
|
||||
createUser()
|
||||
.then(() => {
|
||||
console.log("User created - ready to use")
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Failed to create user - ", err)
|
||||
})
|
|
@ -67,11 +67,12 @@ export default class AccountInternalAPIClient {
|
|||
}
|
||||
const message = `${method} ${url} - ${response.status}`
|
||||
|
||||
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||
if (response.status > 499) {
|
||||
console.error(message, data)
|
||||
} else if (response.status >= 400) {
|
||||
console.warn(message, data)
|
||||
} else {
|
||||
} else if (isDebug) {
|
||||
console.debug(message, data)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,12 @@ class BudibaseInternalAPIClient {
|
|||
}
|
||||
const message = `${method} ${url} - ${response.status}`
|
||||
|
||||
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||
if (response.status > 499) {
|
||||
console.error(message, data)
|
||||
} else if (response.status >= 400) {
|
||||
console.warn(message, data)
|
||||
} else {
|
||||
} else if (isDebug) {
|
||||
console.debug(message, data)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import TestConfiguration from "../../config/TestConfiguration"
|
|||
import * as fixtures from "../../fixtures"
|
||||
import { Query } from "@budibase/types"
|
||||
|
||||
describe("Internal API - Data Sources: MongoDB", () => {
|
||||
xdescribe("Internal API - Data Sources: MongoDB", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
beforeAll(async () => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
process.env.DISABLE_PINO_LOGGER = "1"
|
||||
import { DEFAULT_TENANT_ID, logging } from "@budibase/backend-core"
|
||||
import { AccountInternalAPI } from "../account-api"
|
||||
import * as fixtures from "../internal-api/fixtures"
|
||||
|
|
|
@ -57,11 +57,12 @@ class BudibasePublicAPIClient {
|
|||
}
|
||||
const message = `${method} ${url} - ${response.status}`
|
||||
|
||||
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||
if (response.status > 499) {
|
||||
console.error(message, data)
|
||||
} else if (response.status >= 400) {
|
||||
console.warn(message, data)
|
||||
} else {
|
||||
} else if (isDebug) {
|
||||
console.debug(message, data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue