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 * as auth from "../auth"
import * as events from "../../events"

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ import { getCouchInfo } from "./connections"
import { directCouchCall } from "./utils"
import { getPouchDB } from "./pouchDB"
import { WriteStream, ReadStream } from "fs"
import { newid } from "../../newid"
import { newid } from "../../docIds/newid"
function buildNano(couchInfo: { url: string; cookie: string }) {
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 "./utils"
export * from "./views"
export * from "./conversions"
export * from "../docIds/conversions"
export { default as Replication } from "./Replication"
// exports to support old export structure
export * from "../constants/db"

View File

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

View File

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

View File

@ -1,16 +1,12 @@
import env from "../environment"
import {
DEFAULT_TENANT_ID,
SEPARATOR,
DocumentType,
} from "../constants"
import { DEFAULT_TENANT_ID, SEPARATOR, DocumentType } from "../constants"
import { getTenantId, getGlobalDBName } from "../context"
import { doWithDB, directCouchAllDbs } from "./db"
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 { getStartEndKeyURL } from "./documents"
export * from "./documents"
import { getStartEndKeyURL } from "../docIds"
export * from "../docIds"
/**
* 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,
InternalTable,
SEPARATOR,
} from "../../constants"
import { newid } from "../../newid"
} from "../constants"
import { newid } from "./newid"
/**
* 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,
UNICODE_MAX,
ViewName,
} from "../../constants"
import { getProdAppID } from "../conversions"
} from "../constants"
import { getProdAppID } from "./conversions"
/**
* 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}`
}
/**
* Check if a given ID is that of a table.
* @returns {boolean}
@ -122,7 +121,6 @@ export function getUserMetadataParams(userId?: string | null, otherProps = {}) {
return getRowParams(InternalTable.USER_METADATA, userId, otherProps)
}
export function getUsersByAppParams(appId: any, otherProps: any = {}) {
const prodAppId = getProdAppID(appId)
return {

View File

@ -1,4 +1,4 @@
import { testEnv } from "../../../../../tests"
import { testEnv } from "../../../../../tests/extra"
import PosthogProcessor from "../PosthogProcessor"
import { Event, IdentityType, Hosting } from "@budibase/types"
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 { 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 context from "../../context"
import { MigrationType } from "@budibase/types"

View File

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

View File

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

View File

@ -1,5 +1,6 @@
import * as plugins from "../plugins"
import { structures, testEnv } from "../../../../tests"
import { structures } from "../../../../tests"
import { testEnv } from "../../../../tests/extra"
describe("plugins", () => {
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"
describe("tenants", () => {

View File

@ -1,5 +1,5 @@
import env from "../environment"
export * from "../newid"
export * from "../docIds/newid"
const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
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 db from "../../db"
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 = () => {
jest.mock("node-fetch", () => mockFetch)

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { generator } from "."
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 {
return {

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
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 * as context from "../../src/context"
import * as structures from "../core"
import * as structures from "../core/utilities/structures"
// 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 { cleanup } from "../src/timers"
import { mocks, testContainerUtils } from "./utilities"
import { mocks, testContainerUtils } from "./core/utilities"
// must explicitly enable fetch mock
mocks.fetch.enable()