Fix backend-core tests.

This commit is contained in:
Sam Rose 2024-08-15 16:21:12 +01:00
parent 71000ea967
commit c12a96b4d8
No known key found for this signature in database
3 changed files with 33 additions and 25 deletions

View File

@ -1,24 +0,0 @@
require("../../../tests")
const { structures } = require("../../../tests")
const { getDB } = require("../db")
describe("db", () => {
describe("getDB", () => {
it("returns a db", async () => {
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(structures.db.id())
let doc = { _id: "test" }
await db.put(doc)
doc = await db.get(doc._id)
expect(doc.createdAt).toBe(new Date().toISOString())
expect(doc.updatedAt).toBe(new Date().toISOString())
await db.destroy()
})
})
})

View File

@ -0,0 +1,32 @@
import { context } from "../.."
import { structures } from "../../../tests"
import { getDB } from "../db"
interface Doc {
_id: string
createdAt?: string
updatedAt?: string
}
describe("db", () => {
describe("getDB", () => {
it("returns a db", async () => {
const dbName = structures.db.id()
const db = getDB(dbName)
expect(db).toBeDefined()
expect(db.name).toBe(dbName)
})
it("uses the custom put function", async () => {
await context.doInTenant("foo", async () => {
const db = getDB(structures.db.id())
let doc: Doc = { _id: "test" }
await db.put(doc)
doc = await db.get(doc._id)
expect(doc.createdAt).toBe(new Date().toISOString())
expect(doc.updatedAt).toBe(new Date().toISOString())
await db.destroy()
})
})
})
})

View File

@ -147,13 +147,13 @@ describe("feature flags", () => {
}) => { }) => {
const env: Partial<typeof environment> = { const env: Partial<typeof environment> = {
TENANT_FEATURE_FLAGS: environmentFlags, TENANT_FEATURE_FLAGS: environmentFlags,
SELF_HOSTED: false,
} }
if (posthogFlags) { if (posthogFlags) {
mockPosthogFlags(posthogFlags) mockPosthogFlags(posthogFlags)
env.POSTHOG_TOKEN = "test" env.POSTHOG_TOKEN = "test"
env.POSTHOG_API_HOST = "https://us.i.posthog.com" env.POSTHOG_API_HOST = "https://us.i.posthog.com"
env.POSTHOG_PERSONAL_TOKEN = "test"
} }
const ctx = { user: { license: { features: licenseFlags || [] } } } const ctx = { user: { license: { features: licenseFlags || [] } } }