1
0
Fork 0
mirror of synced 2024-09-19 18:59:06 +12:00

WIP: Remove Redis mocks.

This commit is contained in:
Sam Rose 2024-06-25 14:26:16 +01:00
parent 868b2aed7b
commit fc11c925ff
No known key found for this signature in database
2 changed files with 44 additions and 33 deletions

View file

@ -7,7 +7,6 @@ import {
import tk from "timekeeper"
import emitter from "../../../../src/events"
import { outputProcessing } from "../../../utilities/rowProcessor"
import * as setup from "./utilities"
import { context, InternalTable, tenancy } from "@budibase/backend-core"
import { quotas } from "@budibase/pro"
import {
@ -36,6 +35,7 @@ import { generator, mocks } from "@budibase/backend-core/tests"
import _, { merge } from "lodash"
import * as uuid from "uuid"
import { Knex } from "knex"
import TestConfiguration from "../../../../src/tests/utilities/TestConfiguration"
const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString()
tk.freeze(timestamp)
@ -63,21 +63,22 @@ async function waitForEvent(
}
describe.each([
["internal", undefined],
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
// ["internal", undefined],
// [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
// [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
])("/rows (%s)", (providerType, dsProvider) => {
const isInternal = dsProvider === undefined
const isMSSQL = providerType === DatabaseName.SQL_SERVER
const config = setup.getConfig()
let table: Table
let datasource: Datasource | undefined
let client: Knex | undefined
let config: TestConfiguration
beforeAll(async () => {
config = new TestConfiguration()
await config.init()
if (dsProvider) {
const rawDatasource = await dsProvider
@ -89,7 +90,7 @@ describe.each([
})
afterAll(async () => {
setup.afterAll()
await config.end()
})
function saveTableRequest(

View file

@ -69,6 +69,8 @@ import {
WithRequired,
} from "@budibase/types"
import { getServer } from "../../../src/app"
import API from "./api"
import { cloneDeep } from "lodash"
import jwt, { Secret } from "jsonwebtoken"
@ -95,7 +97,7 @@ export interface TableToBuild extends Omit<Table, "sourceId" | "sourceType"> {
export default class TestConfiguration {
server?: Server
request?: supertest.SuperTest<supertest.Test>
started: boolean
started: boolean = false
appId?: string
allApps: App[]
app?: App
@ -107,24 +109,21 @@ export default class TestConfiguration {
automation?: Automation
datasource?: Datasource
tenantId?: string
api: API
csrfToken?: string
openServer: boolean
private _api?: API
constructor(openServer = true) {
if (openServer) {
// use a random port because it doesn't matter
env.PORT = "0"
this.server = require("../../app").getServer()
// we need the request for logging in, involves cookies, hard to fake
this.request = supertest(this.server)
this.started = true
} else {
this.started = false
}
this.appId = undefined
this.openServer = openServer
this.allApps = []
}
this.api = new API(this)
get api(): API {
if (!this._api) {
throw new Error("API has not been initialised, call config.init() first")
}
return this._api
}
getRequest() {
@ -225,24 +224,35 @@ export default class TestConfiguration {
// use a new id as the name to avoid name collisions
async init(appName = newid()) {
if (this.openServer && !this.started) {
// use a random port because it doesn't matter
env.PORT = "0"
this.server = await getServer()
// we need the request for logging in, involves cookies, hard to fake
this.request = supertest(this.server)
this._api = new API(this)
this.started = true
}
if (!this.started) {
await startup()
this.started = true
}
return this.newTenant(appName)
return await this.newTenant(appName)
}
end() {
if (!this) {
return
}
if (this.server) {
this.server.close()
} else {
require("../../app").getServer().close()
}
if (this.allApps) {
cleanup(this.allApps.map(app => app.appId))
}
end(): Promise<void> {
return new Promise(resolve => {
if (this.allApps) {
cleanup(this.allApps.map(app => app.appId))
}
if (this.server) {
this.server.close(() => resolve())
} else {
resolve()
}
})
}
async withEnv(newEnvVars: Partial<typeof env>, f: () => Promise<void>) {