This commit is contained in:
adrinr 2023-02-03 19:23:36 +00:00
parent 0679880b5b
commit 11a7742d90
9 changed files with 20 additions and 22 deletions

View File

@ -2,16 +2,16 @@ require("../../../tests")
const { Writethrough } = require("../writethrough")
const { getDB } = require("../../db")
const tk = require("timekeeper")
const { structures } = require("../../../tests")
const START_DATE = Date.now()
tk.freeze(START_DATE)
const { newid } = require("../../newid")
const DELAY = 5000
const db = getDB(`db_${newid()}`)
const db2 = getDB(`db_${newid()}`)
const db = getDB(structures.db.id())
const db2 = getDB(structures.db.id())
const writethrough = new Writethrough(db, DELAY), writethrough2 = new Writethrough(db2, DELAY)
describe("writethrough", () => {

View File

@ -1,19 +1,19 @@
require("../../../tests")
const { newid } = require("../../newid")
const { structures } = require("../../../tests")
const { getDB } = require("../db")
describe("db", () => {
describe("getDB", () => {
it("returns a db", async () => {
const dbName = `db_${newid()}`
const dbName = structures.db.id()
const db = getDB(dbName)
expect(db).toBeDefined()
expect(db.name).toBe(dbName)
})
it("uses the custom put function", async () => {
const db = getDB(`db_${newid()}`)
const db = getDB(structures.db.id())
let doc = { _id: "test" }
await db.put(doc)
doc = await db.get(doc._id)

View File

@ -64,7 +64,7 @@ const print = (fn: any, data: any[]) => {
message = message + ` [identityId=${identityId}]`
}
// fn(message, data)
fn(message, data)
}
const logging = (ctx: any, next: any) => {

View File

@ -6,8 +6,6 @@ const { DEFAULT_TENANT_ID } = require("../../../constants")
const { generateGlobalUserID } = require("../../../db/utils")
const { newid } = require("../../../utils")
const { doWithGlobalDB, doInTenant } = require("../../../tenancy")
const { default: environment } = require("../../../environment")
environment._set("MULTI_TENANCY", 'TRUE')
const done = jest.fn()

View File

@ -2,9 +2,8 @@ require("../../../tests")
const { runMigrations, getMigrationsDoc } = require("../index")
const { getGlobalDBName, getDB } = require("../../db")
const { default: environment } = require("../../environment")
const { newid } = require("../../newid")
environment._set("MULTI_TENANCY", 'TRUE')
const { structures, testEnv } = require("../../../tests")
testEnv.multiTenant()
let db
@ -21,7 +20,7 @@ describe("migrations", () => {
let tenantId
beforeEach(() => {
tenantId = `tenant_${newid()}`
tenantId = structures.tenant.id()
db = getDB(getGlobalDBName(tenantId))
})

View File

@ -4,15 +4,10 @@ import * as events from "../../events"
import * as db from "../../db"
import { Header } from "../../constants"
import { doInTenant } from "../../context"
import environment from "../../environment"
import { newid } from "../../utils"
describe("utils", () => {
describe("platformLogout", () => {
beforeEach(() => {
environment._set("MULTI_TENANCY", "TRUE")
})
it("should call platform logout", async () => {
await doInTenant(structures.tenant.id(), async () => {
const ctx = structures.koa.newContext()
@ -23,10 +18,6 @@ describe("utils", () => {
})
describe("getAppIdFromCtx", () => {
beforeEach(() => {
environment._set("MULTI_TENANCY", undefined)
})
it("gets appId from header", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()

View File

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

View File

@ -9,3 +9,4 @@ export * as koa from "./koa"
export * as licenses from "./licenses"
export * as plugins from "./plugins"
export * as tenant from "./tenants"
export * as db from "./db"

View File

@ -47,6 +47,8 @@ describe("/webhooks", () => {
})
describe("fetch", () => {
beforeAll(setupTest)
it("returns the correct routing for basic user", async () => {
const res = await request
.get(`/api/webhooks`)
@ -67,6 +69,8 @@ describe("/webhooks", () => {
})
describe("delete", () => {
beforeAll(setupTest)
it("should successfully delete", async () => {
const res = await request
.delete(`/api/webhooks/${webhook._id}/${webhook._rev}`)