diff --git a/packages/backend-core/jest.config.ts b/packages/backend-core/jest.config.ts index 1e69797e71..8d64b24a2f 100644 --- a/packages/backend-core/jest.config.ts +++ b/packages/backend-core/jest.config.ts @@ -31,4 +31,6 @@ const config: Config.InitialOptions = { coverageReporters: ["lcov", "json", "clover"], } +process.env.DISABLE_PINO_LOGGER = "1" + export default config diff --git a/packages/server/src/integrations/mongodb.ts b/packages/server/src/integrations/mongodb.ts index f076536344..0a2dfd856c 100644 --- a/packages/server/src/integrations/mongodb.ts +++ b/packages/server/src/integrations/mongodb.ts @@ -489,7 +489,11 @@ class MongoIntegration implements IntegrationBase { switch (query.extra.actionType) { case "find": { - return await collection.find(json).toArray() + if (json) { + return await collection.find(json).toArray() + } else { + return await collection.find().toArray() + } } case "findOne": { return await collection.findOne(json) diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index 33335379c0..320f7be01a 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -38,7 +38,7 @@ const MAX_USERS_UPLOAD_LIMIT = 1000 export const save = async (ctx: UserCtx) => { try { - const currentUserId = ctx.user._id + const currentUserId = ctx.user?._id const requestUser = ctx.request.body const user = await userSdk.save(requestUser, { currentUserId }) diff --git a/qa-core/package.json b/qa-core/package.json index 1d36d179ee..13f2e80332 100644 --- a/qa-core/package.json +++ b/qa-core/package.json @@ -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", diff --git a/qa-core/scripts/createUser.js b/qa-core/scripts/createUser.js new file mode 100644 index 0000000000..200bf91fc4 --- /dev/null +++ b/qa-core/scripts/createUser.js @@ -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) + }) diff --git a/qa-core/src/account-api/api/AccountInternalAPIClient.ts b/qa-core/src/account-api/api/AccountInternalAPIClient.ts index df58ab0ce3..85807fd87a 100644 --- a/qa-core/src/account-api/api/AccountInternalAPIClient.ts +++ b/qa-core/src/account-api/api/AccountInternalAPIClient.ts @@ -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) } diff --git a/qa-core/src/internal-api/api/BudibaseInternalAPIClient.ts b/qa-core/src/internal-api/api/BudibaseInternalAPIClient.ts index a6921a75b2..ba70bb5ce0 100644 --- a/qa-core/src/internal-api/api/BudibaseInternalAPIClient.ts +++ b/qa-core/src/internal-api/api/BudibaseInternalAPIClient.ts @@ -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) } diff --git a/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts b/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts index 27fc143554..ace9ef32c5 100644 --- a/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts @@ -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 () => { diff --git a/qa-core/src/jest/globalSetup.ts b/qa-core/src/jest/globalSetup.ts index 12d227df02..040a65ecef 100644 --- a/qa-core/src/jest/globalSetup.ts +++ b/qa-core/src/jest/globalSetup.ts @@ -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" diff --git a/qa-core/src/public-api/api/BudibasePublicAPIClient.ts b/qa-core/src/public-api/api/BudibasePublicAPIClient.ts index f4fe978812..b75393bdaa 100644 --- a/qa-core/src/public-api/api/BudibasePublicAPIClient.ts +++ b/qa-core/src/public-api/api/BudibasePublicAPIClient.ts @@ -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) } diff --git a/yarn.lock b/yarn.lock index b15c549640..de64f7d4bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2489,6 +2489,11 @@ minimatch "^3.0.4" strip-json-comments "^3.1.1" +"@fontsource/source-sans-pro@^5.0.3": + version "5.0.3" + resolved "https://registry.yarnpkg.com/@fontsource/source-sans-pro/-/source-sans-pro-5.0.3.tgz#7d6e84a8169ba12fa5e6ce70757aa2ca7e74d855" + integrity sha512-mQnjuif/37VxwRloHZ+wQdoozd2VPWutbFSt1AuSkk7nFXIBQxHJLw80rgCF/osL0t7N/3Gx1V7UJuOX2zxzhQ== + "@fortawesome/fontawesome-common-types@6.3.0": version "6.3.0" resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.3.0.tgz#51f734e64511dbc3674cd347044d02f4dd26e86b" @@ -8406,7 +8411,7 @@ chmodr@1.2.0: resolved "https://registry.yarnpkg.com/chmodr/-/chmodr-1.2.0.tgz#720e96caa09b7f1cdbb01529b7d0ab6bc5e118b9" integrity sha512-Y5uI7Iq/Az6HgJEL6pdw7THVd7jbVOTPwsmcPOBjQL8e3N+pz872kzK5QxYGEy21iRys+iHWV0UZQXDFJo1hyA== -chokidar@3.5.3, chokidar@^3.0.0, chokidar@^3.5.1, chokidar@^3.5.2: +chokidar@3.5.3, chokidar@^3.0.0, chokidar@^3.5.1, chokidar@^3.5.2, chokidar@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== @@ -11850,7 +11855,7 @@ fast-glob@3.2.7: merge2 "^1.3.0" micromatch "^4.0.4" -fast-glob@^3.0.3: +fast-glob@^3.0.3, fast-glob@^3.2.11: version "3.2.12" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w== @@ -25423,6 +25428,16 @@ vite-node@0.29.8: picocolors "^1.0.0" vite "^3.0.0 || ^4.0.0" +vite-plugin-static-copy@^0.16.0: + version "0.16.0" + resolved "https://registry.yarnpkg.com/vite-plugin-static-copy/-/vite-plugin-static-copy-0.16.0.tgz#2f65227037f17fc99c0782fd0b344e962935e69e" + integrity sha512-dMVEg5Z2SwYRgQnHZaeokvSKB4p/TOTf65JU4sP3U6ccSBsukqdtDOjpmT+xzTFHAA8WJjcS31RMLjUdWQCBzw== + dependencies: + chokidar "^3.5.3" + fast-glob "^3.2.11" + fs-extra "^11.1.0" + picocolors "^1.0.0" + "vite@^3.0.0 || ^4.0.0": version "4.2.2" resolved "https://registry.yarnpkg.com/vite/-/vite-4.2.2.tgz#014c30e5163844f6e96d7fe18fbb702236516dc6"