mirror of https://github.com/Budibase/budibase.git
6 changed files with 54 additions and 9 deletions
@ -0,0 +1,41 @@ |
|||
const { MOCK_DATE } = require("../../tests/utilities/TestConfiguration") |
|||
const { getDB, allDbs } = require("../") |
|||
|
|||
Date = jest.fn(() => MOCK_DATE) |
|||
|
|||
describe("db", () => { |
|||
|
|||
describe("getDB", () => { |
|||
it("returns a db", async () => { |
|||
const db = getDB("test") |
|||
expect(db).toBeDefined() |
|||
expect(db._adapter).toBe("memory") |
|||
expect(db.prefix).toBe("_pouch_") |
|||
expect(db.name).toBe("test") |
|||
}) |
|||
|
|||
it("uses the custom put function", async () => { |
|||
const db = getDB("test") |
|||
let doc = { _id: "test" } |
|||
await db.put(doc) |
|||
doc = await db.get(doc._id) |
|||
expect(doc.createdAt).toBe(MOCK_DATE.toISOString()) |
|||
expect(doc.updatedAt).toBe(MOCK_DATE.toISOString()) |
|||
await db.destroy() |
|||
}) |
|||
}) |
|||
|
|||
describe("allDbs", () => { |
|||
it("returns all dbs", async () => { |
|||
let all = await allDbs() |
|||
expect(all).toStrictEqual([]) |
|||
const db1 = getDB("test1") |
|||
await db1.put({ _id: "test1" }) |
|||
const db2 = getDB("test2") |
|||
await db2.put({ _id: "test2" }) |
|||
all = await allDbs() |
|||
expect(all.length).toBe(2) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
@ -0,0 +1,4 @@ |
|||
require("./db") |
|||
|
|||
exports.MOCK_DATE = new Date("2020-01-01T00:00:00.000Z") |
|||
exports.MOCK_DATE_TIMESTAMP = 1577836800000 |
|||
@ -1,5 +1,6 @@ |
|||
const core = require("../../index") |
|||
const dbConfig = { |
|||
inMemory: true, |
|||
allDbs: true, |
|||
} |
|||
core.init({ db: dbConfig }) |
|||
Loading…
Reference in new issue