Fixing all broken test cases after breaking out context fully from jestSetup/backend-core jest loading.

This commit is contained in:
mike12345567 2023-03-30 16:35:25 +01:00
parent 47897c8afa
commit 24fc72657d
39 changed files with 56 additions and 58 deletions

View File

@ -1,4 +1,4 @@
import { structures } from "../../../tests/core" import { structures } from "../../../tests"
import { testEnv } from "../../../tests/extra" import { testEnv } from "../../../tests/extra"
import * as auth from "../auth" import * as auth from "../auth"
import * as events from "../../events" import * as events from "../../events"

View File

@ -1,8 +1,5 @@
import { import { structures, expectFunctionWasCalledTimesWith } from "../../../tests"
structures, import { DBTestConfiguration } from "../../../tests/extra"
DBTestConfiguration,
expectFunctionWasCalledTimesWith,
} from "../../../tests"
import { Writethrough } from "../writethrough" import { Writethrough } from "../writethrough"
import { getDB } from "../../db" import { getDB } from "../../db"
import tk from "timekeeper" import tk from "timekeeper"

View File

@ -1,9 +1,5 @@
import { import { generator, structures } from "../../../tests"
DBTestConfiguration, import { DBTestConfiguration, testEnv } from "../../../tests/extra"
generator,
testEnv,
structures,
} from "../../../tests"
import { ConfigType } from "@budibase/types" import { ConfigType } from "@budibase/types"
import env from "../../environment" import env from "../../environment"
import * as configs from "../configs" import * as configs from "../configs"

View File

@ -2,7 +2,7 @@
// store an app ID to pretend there is a context // store an app ID to pretend there is a context
import env from "../environment" import env from "../environment"
import Context from "./Context" import Context from "./Context"
import * as conversions from "../db/conversions" import * as conversions from "../docIds/conversions"
import { getDB } from "../db/db" import { getDB } from "../db/db"
import { import {
DocumentType, DocumentType,

View File

@ -1,4 +1,4 @@
import { testEnv } from "../../../tests" import { testEnv } from "../../../tests/extra"
const context = require("../") const context = require("../")
const { DEFAULT_TENANT_ID } = require("../../constants") const { DEFAULT_TENANT_ID } = require("../../constants")

View File

@ -15,7 +15,7 @@ import { getCouchInfo } from "./connections"
import { directCouchCall } from "./utils" import { directCouchCall } from "./utils"
import { getPouchDB } from "./pouchDB" import { getPouchDB } from "./pouchDB"
import { WriteStream, ReadStream } from "fs" import { WriteStream, ReadStream } from "fs"
import { newid } from "../../newid" import { newid } from "../../docIds/newid"
function buildNano(couchInfo: { url: string; cookie: string }) { function buildNano(couchInfo: { url: string; cookie: string }) {
return Nano({ return Nano({

View File

@ -1,2 +0,0 @@
export * from "./ids"
export * from "./params"

View File

@ -2,7 +2,7 @@ export * from "./couch"
export * from "./db" export * from "./db"
export * from "./utils" export * from "./utils"
export * from "./views" export * from "./views"
export * from "./conversions" export * from "../docIds/conversions"
export { default as Replication } from "./Replication" export { default as Replication } from "./Replication"
// exports to support old export structure // exports to support old export structure
export * from "../constants/db" export * from "../constants/db"

View File

@ -1,4 +1,4 @@
import { newid } from "../../newid" import { newid } from "../../docIds/newid"
import { getDB } from "../db" import { getDB } from "../db"
import { Database } from "@budibase/types" import { Database } from "@budibase/types"
import { QueryBuilder, paginatedSearch, fullSearch } from "../lucene" import { QueryBuilder, paginatedSearch, fullSearch } from "../lucene"

View File

@ -3,7 +3,7 @@ import {
getProdAppID, getProdAppID,
isDevAppID, isDevAppID,
isProdAppID, isProdAppID,
} from "../conversions" } from "../../docIds/conversions"
import { generateAppID } from "../utils" import { generateAppID } from "../utils"
describe("utils", () => { describe("utils", () => {

View File

@ -1,16 +1,12 @@
import env from "../environment" import env from "../environment"
import { import { DEFAULT_TENANT_ID, SEPARATOR, DocumentType } from "../constants"
DEFAULT_TENANT_ID,
SEPARATOR,
DocumentType,
} from "../constants"
import { getTenantId, getGlobalDBName } from "../context" import { getTenantId, getGlobalDBName } from "../context"
import { doWithDB, directCouchAllDbs } from "./db" import { doWithDB, directCouchAllDbs } from "./db"
import { getAppMetadata } from "../cache/appMetadata" import { getAppMetadata } from "../cache/appMetadata"
import { isDevApp, isDevAppID, getProdAppID } from "./conversions" import { isDevApp, isDevAppID, getProdAppID } from "../docIds/conversions"
import { App, Database } from "@budibase/types" import { App, Database } from "@budibase/types"
import { getStartEndKeyURL } from "./documents" import { getStartEndKeyURL } from "../docIds"
export * from "./documents" export * from "../docIds"
/** /**
* if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing * if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing

View File

@ -3,8 +3,8 @@ import {
DocumentType, DocumentType,
InternalTable, InternalTable,
SEPARATOR, SEPARATOR,
} from "../../constants" } from "../constants"
import { newid } from "../../newid" import { newid } from "./newid"
/** /**
* Generates a new app ID. * Generates a new app ID.

View File

@ -0,0 +1,2 @@
export * from "./ids"
export * from "./params"

View File

@ -4,8 +4,8 @@ import {
SEPARATOR, SEPARATOR,
UNICODE_MAX, UNICODE_MAX,
ViewName, ViewName,
} from "../../constants" } from "../constants"
import { getProdAppID } from "../conversions" import { getProdAppID } from "./conversions"
/** /**
* If creating DB allDocs/query params with only a single top level ID this can be used, this * If creating DB allDocs/query params with only a single top level ID this can be used, this
@ -63,7 +63,6 @@ export function getQueryIndex(viewName: ViewName) {
return `database/${viewName}` return `database/${viewName}`
} }
/** /**
* Check if a given ID is that of a table. * Check if a given ID is that of a table.
* @returns {boolean} * @returns {boolean}
@ -122,7 +121,6 @@ export function getUserMetadataParams(userId?: string | null, otherProps = {}) {
return getRowParams(InternalTable.USER_METADATA, userId, otherProps) return getRowParams(InternalTable.USER_METADATA, userId, otherProps)
} }
export function getUsersByAppParams(appId: any, otherProps: any = {}) { export function getUsersByAppParams(appId: any, otherProps: any = {}) {
const prodAppId = getProdAppID(appId) const prodAppId = getProdAppID(appId)
return { return {

View File

@ -1,4 +1,4 @@
import { testEnv } from "../../../../../tests" import { testEnv } from "../../../../../tests/extra"
import PosthogProcessor from "../PosthogProcessor" import PosthogProcessor from "../PosthogProcessor"
import { Event, IdentityType, Hosting } from "@budibase/types" import { Event, IdentityType, Hosting } from "@budibase/types"
const tk = require("timekeeper") const tk = require("timekeeper")

View File

@ -1,4 +1,5 @@
import { structures, testEnv, mocks } from "../../../../../tests" import { structures, mocks } from "../../../../../tests"
import { testEnv } from "../../../../../tests/extra"
import { SSOAuthDetails, User } from "@budibase/types" import { SSOAuthDetails, User } from "@budibase/types"
import { HTTPError } from "../../../../errors" import { HTTPError } from "../../../../errors"

View File

@ -1,4 +1,4 @@
import { testEnv, DBTestConfiguration } from "../../../tests" import { testEnv, DBTestConfiguration } from "../../../tests/extra"
import * as migrations from "../index" import * as migrations from "../index"
import * as context from "../../context" import * as context from "../../context"
import { MigrationType } from "@budibase/types" import { MigrationType } from "@budibase/types"

View File

@ -1,6 +1,6 @@
import * as app from "../app" import * as app from "../app"
import { getAppFileUrl } from "../app" import { getAppFileUrl } from "../app"
import { testEnv } from "../../../../tests" import { testEnv } from "../../../../tests/extra"
describe("app", () => { describe("app", () => {
beforeEach(() => { beforeEach(() => {

View File

@ -1,5 +1,5 @@
import * as global from "../global" import * as global from "../global"
import { testEnv } from "../../../../tests" import { testEnv } from "../../../../tests/extra"
describe("global", () => { describe("global", () => {
describe("getGlobalFileUrl", () => { describe("getGlobalFileUrl", () => {

View File

@ -1,5 +1,6 @@
import * as plugins from "../plugins" import * as plugins from "../plugins"
import { structures, testEnv } from "../../../../tests" import { structures } from "../../../../tests"
import { testEnv } from "../../../../tests/extra"
describe("plugins", () => { describe("plugins", () => {
describe("enrichPluginURLs", () => { describe("enrichPluginURLs", () => {

View File

@ -1,4 +1,5 @@
import { DBTestConfiguration, structures } from "../../../tests" import { structures } from "../../../tests"
import { DBTestConfiguration } from "../../../tests/extra"
import * as tenants from "../tenants" import * as tenants from "../tenants"
describe("tenants", () => { describe("tenants", () => {

View File

@ -1,5 +1,5 @@
import env from "../environment" import env from "../environment"
export * from "../newid" export * from "../docIds/newid"
const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt") const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
const SALT_ROUNDS = env.SALT_ROUNDS || 10 const SALT_ROUNDS = env.SALT_ROUNDS || 10

View File

@ -1,4 +1,5 @@
import { structures, DBTestConfiguration } from "../../../tests" import { structures } from "../../../tests"
import { DBTestConfiguration } from "../../../tests/extra"
import * as utils from "../../utils" import * as utils from "../../utils"
import * as db from "../../db" import * as db from "../../db"
import { Header } from "../../constants" import { Header } from "../../constants"

View File

@ -1 +0,0 @@
export * from "./utilities"

View File

@ -1 +1 @@
jest.mock("../../../src/events") jest.mock("../../../../src/events")

View File

@ -1,4 +1,11 @@
const mockFetch = jest.fn() const mockFetch = jest.fn((url: any, opts: any) => {
const fetch = jest.requireActual("node-fetch")
const env = jest.requireActual("../../../../src/environment").default
if (url.includes(env.COUCH_DB_URL)) {
return fetch(url, opts)
}
return undefined
})
const enable = () => { const enable = () => {
jest.mock("node-fetch", () => mockFetch) jest.mock("node-fetch", () => mockFetch)

View File

@ -1,5 +1,5 @@
jest.mock("../../../src/accounts") jest.mock("../../../../src/accounts")
import * as _accounts from "../../../src/accounts" import * as _accounts from "../../../../src/accounts"
export const accounts = jest.mocked(_accounts) export const accounts = jest.mocked(_accounts)
export * as date from "./date" export * as date from "./date"

View File

@ -1,5 +1,5 @@
import { generator, uuid } from "." import { generator, uuid } from "."
import { generateGlobalUserID } from "../../../src/db/documents" import { generateGlobalUserID } from "../../../../src/docIds"
import { import {
Account, Account,
AccountSSOProvider, AccountSSOProvider,

View File

@ -1,6 +1,6 @@
import { generator } from "." import { generator } from "."
import { App } from "@budibase/types" import { App } from "@budibase/types"
import { DEFAULT_TENANT_ID, DocumentType } from "../../../src/constants" import { DEFAULT_TENANT_ID, DocumentType } from "../../../../src/constants"
export function app(id: string): App { export function app(id: string): App {
return { return {

View File

@ -1,5 +1,5 @@
import { structures } from ".." import { structures } from ".."
import { newid } from "../../../src/newid" import { newid } from "../../../../src/docIds/newid"
export function id() { export function id() {
return `db_${newid()}` return `db_${newid()}`

View File

@ -1,4 +1,4 @@
import { newid } from "../../../src/newid" import { newid } from "../../../../src/docIds/newid"
export function id() { export function id() {
return `tenant-${newid()}` return `tenant-${newid()}`

View File

@ -1,5 +1,5 @@
import "./mocks" import "../core/utilities/mocks"
import * as structures from "./structures" import * as structures from "../core/utilities/structures"
import * as testEnv from "./testEnv" import * as testEnv from "./testEnv"
import * as context from "../../src/context" import * as context from "../../src/context"

View File

@ -1,2 +1,2 @@
export * as testEnv from "./testEnv" export * as testEnv from "./testEnv"
export * as DBTestConfiguration from "./DBTestConfiguration" export { default as DBTestConfiguration } from "./DBTestConfiguration"

View File

@ -1,6 +1,6 @@
import env from "../../src/environment" import env from "../../src/environment"
import * as context from "../../src/context" import * as context from "../../src/context"
import * as structures from "../core" import * as structures from "../core/utilities/structures"
// TENANCY // TENANCY

View File

@ -0,0 +1 @@
export * from "./core/utilities"

View File

@ -1,7 +1,7 @@
import "./logging" import "./core/logging"
import env from "../src/environment" import env from "../src/environment"
import { cleanup } from "../src/timers" import { cleanup } from "../src/timers"
import { mocks, testContainerUtils } from "./utilities" import { mocks, testContainerUtils } from "./core/utilities"
// must explicitly enable fetch mock // must explicitly enable fetch mock
mocks.fetch.enable() mocks.fetch.enable()