Cleanup
This commit is contained in:
parent
0679880b5b
commit
11a7742d90
|
@ -2,16 +2,16 @@ require("../../../tests")
|
||||||
const { Writethrough } = require("../writethrough")
|
const { Writethrough } = require("../writethrough")
|
||||||
const { getDB } = require("../../db")
|
const { getDB } = require("../../db")
|
||||||
const tk = require("timekeeper")
|
const tk = require("timekeeper")
|
||||||
|
const { structures } = require("../../../tests")
|
||||||
|
|
||||||
const START_DATE = Date.now()
|
const START_DATE = Date.now()
|
||||||
tk.freeze(START_DATE)
|
tk.freeze(START_DATE)
|
||||||
|
|
||||||
const { newid } = require("../../newid")
|
|
||||||
|
|
||||||
const DELAY = 5000
|
const DELAY = 5000
|
||||||
|
|
||||||
const db = getDB(`db_${newid()}`)
|
const db = getDB(structures.db.id())
|
||||||
const db2 = getDB(`db_${newid()}`)
|
const db2 = getDB(structures.db.id())
|
||||||
const writethrough = new Writethrough(db, DELAY), writethrough2 = new Writethrough(db2, DELAY)
|
const writethrough = new Writethrough(db, DELAY), writethrough2 = new Writethrough(db2, DELAY)
|
||||||
|
|
||||||
describe("writethrough", () => {
|
describe("writethrough", () => {
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
require("../../../tests")
|
require("../../../tests")
|
||||||
const { newid } = require("../../newid")
|
const { structures } = require("../../../tests")
|
||||||
const { getDB } = require("../db")
|
const { getDB } = require("../db")
|
||||||
|
|
||||||
describe("db", () => {
|
describe("db", () => {
|
||||||
describe("getDB", () => {
|
describe("getDB", () => {
|
||||||
it("returns a db", async () => {
|
it("returns a db", async () => {
|
||||||
|
|
||||||
const dbName = `db_${newid()}`
|
const dbName = structures.db.id()
|
||||||
const db = getDB(dbName)
|
const db = getDB(dbName)
|
||||||
expect(db).toBeDefined()
|
expect(db).toBeDefined()
|
||||||
expect(db.name).toBe(dbName)
|
expect(db.name).toBe(dbName)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("uses the custom put function", async () => {
|
it("uses the custom put function", async () => {
|
||||||
const db = getDB(`db_${newid()}`)
|
const db = getDB(structures.db.id())
|
||||||
let doc = { _id: "test" }
|
let doc = { _id: "test" }
|
||||||
await db.put(doc)
|
await db.put(doc)
|
||||||
doc = await db.get(doc._id)
|
doc = await db.get(doc._id)
|
||||||
|
|
|
@ -64,7 +64,7 @@ const print = (fn: any, data: any[]) => {
|
||||||
message = message + ` [identityId=${identityId}]`
|
message = message + ` [identityId=${identityId}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn(message, data)
|
fn(message, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const logging = (ctx: any, next: any) => {
|
const logging = (ctx: any, next: any) => {
|
||||||
|
|
|
@ -6,8 +6,6 @@ const { DEFAULT_TENANT_ID } = require("../../../constants")
|
||||||
const { generateGlobalUserID } = require("../../../db/utils")
|
const { generateGlobalUserID } = require("../../../db/utils")
|
||||||
const { newid } = require("../../../utils")
|
const { newid } = require("../../../utils")
|
||||||
const { doWithGlobalDB, doInTenant } = require("../../../tenancy")
|
const { doWithGlobalDB, doInTenant } = require("../../../tenancy")
|
||||||
const { default: environment } = require("../../../environment")
|
|
||||||
environment._set("MULTI_TENANCY", 'TRUE')
|
|
||||||
|
|
||||||
const done = jest.fn()
|
const done = jest.fn()
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,8 @@ require("../../../tests")
|
||||||
const { runMigrations, getMigrationsDoc } = require("../index")
|
const { runMigrations, getMigrationsDoc } = require("../index")
|
||||||
const { getGlobalDBName, getDB } = require("../../db")
|
const { getGlobalDBName, getDB } = require("../../db")
|
||||||
|
|
||||||
const { default: environment } = require("../../environment")
|
const { structures, testEnv } = require("../../../tests")
|
||||||
const { newid } = require("../../newid")
|
testEnv.multiTenant()
|
||||||
environment._set("MULTI_TENANCY", 'TRUE')
|
|
||||||
|
|
||||||
let db
|
let db
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ describe("migrations", () => {
|
||||||
let tenantId
|
let tenantId
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tenantId = `tenant_${newid()}`
|
tenantId = structures.tenant.id()
|
||||||
db = getDB(getGlobalDBName(tenantId))
|
db = getDB(getGlobalDBName(tenantId))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,10 @@ import * as events from "../../events"
|
||||||
import * as db from "../../db"
|
import * as db from "../../db"
|
||||||
import { Header } from "../../constants"
|
import { Header } from "../../constants"
|
||||||
import { doInTenant } from "../../context"
|
import { doInTenant } from "../../context"
|
||||||
import environment from "../../environment"
|
|
||||||
import { newid } from "../../utils"
|
import { newid } from "../../utils"
|
||||||
|
|
||||||
describe("utils", () => {
|
describe("utils", () => {
|
||||||
describe("platformLogout", () => {
|
describe("platformLogout", () => {
|
||||||
beforeEach(() => {
|
|
||||||
environment._set("MULTI_TENANCY", "TRUE")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should call platform logout", async () => {
|
it("should call platform logout", async () => {
|
||||||
await doInTenant(structures.tenant.id(), async () => {
|
await doInTenant(structures.tenant.id(), async () => {
|
||||||
const ctx = structures.koa.newContext()
|
const ctx = structures.koa.newContext()
|
||||||
|
@ -23,10 +18,6 @@ describe("utils", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("getAppIdFromCtx", () => {
|
describe("getAppIdFromCtx", () => {
|
||||||
beforeEach(() => {
|
|
||||||
environment._set("MULTI_TENANCY", undefined)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("gets appId from header", async () => {
|
it("gets appId from header", async () => {
|
||||||
const ctx = structures.koa.newContext()
|
const ctx = structures.koa.newContext()
|
||||||
const expected = db.generateAppID()
|
const expected = db.generateAppID()
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { newid } from "../../../src/newid"
|
||||||
|
|
||||||
|
export function id() {
|
||||||
|
return `db_${newid()}`
|
||||||
|
}
|
|
@ -9,3 +9,4 @@ export * as koa from "./koa"
|
||||||
export * as licenses from "./licenses"
|
export * as licenses from "./licenses"
|
||||||
export * as plugins from "./plugins"
|
export * as plugins from "./plugins"
|
||||||
export * as tenant from "./tenants"
|
export * as tenant from "./tenants"
|
||||||
|
export * as db from "./db"
|
||||||
|
|
|
@ -47,6 +47,8 @@ describe("/webhooks", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
|
beforeAll(setupTest)
|
||||||
|
|
||||||
it("returns the correct routing for basic user", async () => {
|
it("returns the correct routing for basic user", async () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/webhooks`)
|
.get(`/api/webhooks`)
|
||||||
|
@ -67,6 +69,8 @@ describe("/webhooks", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("delete", () => {
|
describe("delete", () => {
|
||||||
|
beforeAll(setupTest)
|
||||||
|
|
||||||
it("should successfully delete", async () => {
|
it("should successfully delete", async () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.delete(`/api/webhooks/${webhook._id}/${webhook._rev}`)
|
.delete(`/api/webhooks/${webhook._id}/${webhook._rev}`)
|
||||||
|
|
Loading…
Reference in New Issue