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"],
|
coverageReporters: ["lcov", "json", "clover"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.env.DISABLE_PINO_LOGGER = "1"
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
|
|
@ -489,7 +489,11 @@ class MongoIntegration implements IntegrationBase {
|
||||||
|
|
||||||
switch (query.extra.actionType) {
|
switch (query.extra.actionType) {
|
||||||
case "find": {
|
case "find": {
|
||||||
return await collection.find(json).toArray()
|
if (json) {
|
||||||
|
return await collection.find(json).toArray()
|
||||||
|
} else {
|
||||||
|
return await collection.find().toArray()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "findOne": {
|
case "findOne": {
|
||||||
return await collection.findOne(json)
|
return await collection.findOne(json)
|
||||||
|
|
|
@ -38,7 +38,7 @@ const MAX_USERS_UPLOAD_LIMIT = 1000
|
||||||
|
|
||||||
export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
|
export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
|
||||||
try {
|
try {
|
||||||
const currentUserId = ctx.user._id
|
const currentUserId = ctx.user?._id
|
||||||
const requestUser = ctx.request.body
|
const requestUser = ctx.request.body
|
||||||
|
|
||||||
const user = await userSdk.save(requestUser, { currentUserId })
|
const user = await userSdk.save(requestUser, { currentUserId })
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "yarn && node scripts/createEnv.js",
|
"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": "jest --runInBand --json --outputFile=testResults.json --forceExit",
|
||||||
"test:watch": "yarn run test --watch",
|
"test:watch": "yarn run test --watch",
|
||||||
"test:debug": "DEBUG=1 yarn run test",
|
"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 message = `${method} ${url} - ${response.status}`
|
||||||
|
|
||||||
|
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||||
if (response.status > 499) {
|
if (response.status > 499) {
|
||||||
console.error(message, data)
|
console.error(message, data)
|
||||||
} else if (response.status >= 400) {
|
} else if (response.status >= 400) {
|
||||||
console.warn(message, data)
|
console.warn(message, data)
|
||||||
} else {
|
} else if (isDebug) {
|
||||||
console.debug(message, data)
|
console.debug(message, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,12 @@ class BudibaseInternalAPIClient {
|
||||||
}
|
}
|
||||||
const message = `${method} ${url} - ${response.status}`
|
const message = `${method} ${url} - ${response.status}`
|
||||||
|
|
||||||
|
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||||
if (response.status > 499) {
|
if (response.status > 499) {
|
||||||
console.error(message, data)
|
console.error(message, data)
|
||||||
} else if (response.status >= 400) {
|
} else if (response.status >= 400) {
|
||||||
console.warn(message, data)
|
console.warn(message, data)
|
||||||
} else {
|
} else if (isDebug) {
|
||||||
console.debug(message, data)
|
console.debug(message, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import TestConfiguration from "../../config/TestConfiguration"
|
||||||
import * as fixtures from "../../fixtures"
|
import * as fixtures from "../../fixtures"
|
||||||
import { Query } from "@budibase/types"
|
import { Query } from "@budibase/types"
|
||||||
|
|
||||||
describe("Internal API - Data Sources: MongoDB", () => {
|
xdescribe("Internal API - Data Sources: MongoDB", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
process.env.DISABLE_PINO_LOGGER = "1"
|
||||||
import { DEFAULT_TENANT_ID, logging } from "@budibase/backend-core"
|
import { DEFAULT_TENANT_ID, logging } from "@budibase/backend-core"
|
||||||
import { AccountInternalAPI } from "../account-api"
|
import { AccountInternalAPI } from "../account-api"
|
||||||
import * as fixtures from "../internal-api/fixtures"
|
import * as fixtures from "../internal-api/fixtures"
|
||||||
|
|
|
@ -57,11 +57,12 @@ class BudibasePublicAPIClient {
|
||||||
}
|
}
|
||||||
const message = `${method} ${url} - ${response.status}`
|
const message = `${method} ${url} - ${response.status}`
|
||||||
|
|
||||||
|
const isDebug = process.env.LOG_LEVEL === "debug"
|
||||||
if (response.status > 499) {
|
if (response.status > 499) {
|
||||||
console.error(message, data)
|
console.error(message, data)
|
||||||
} else if (response.status >= 400) {
|
} else if (response.status >= 400) {
|
||||||
console.warn(message, data)
|
console.warn(message, data)
|
||||||
} else {
|
} else if (isDebug) {
|
||||||
console.debug(message, data)
|
console.debug(message, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue