Add tests for base db config
This commit is contained in:
parent
2a5df40ffa
commit
0aa141e7c6
|
@ -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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
// Mock data
|
require("../../../tests/utilities/TestConfiguration")
|
||||||
|
|
||||||
require("../../../tests/utilities/dbConfig")
|
|
||||||
|
|
||||||
const database = require("../../../db")
|
const database = require("../../../db")
|
||||||
const { authenticateThirdParty } = require("../third-party-common")
|
const { authenticateThirdParty } = require("../third-party-common")
|
||||||
const { data } = require("./utilities/mock-data")
|
const { data } = require("./utilities/mock-data")
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
exports[`migrations should match snapshot 1`] = `
|
exports[`migrations should match snapshot 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"_id": "migrations",
|
"_id": "migrations",
|
||||||
"_rev": "1-6277abc4e3db950221768e5a2618a059",
|
"_rev": "1-a32b0b708e59eeb006ed5e063cfeb36a",
|
||||||
"test": 1487076708000,
|
"createdAt": "2020-01-01T00:00:00.000Z",
|
||||||
|
"test": 1577836800000,
|
||||||
|
"updatedAt": "2020-01-01T00:00:00.000Z",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
require("../../tests/utilities/dbConfig")
|
const { MOCK_DATE_TIMESTAMP, MOCK_DATE } = require("../../tests/utilities/TestConfiguration")
|
||||||
|
|
||||||
const { runMigrations, getMigrationsDoc } = require("../index")
|
const { runMigrations, getMigrationsDoc } = require("../index")
|
||||||
const { getDB } = require("../../db")
|
const { getDB } = require("../../db")
|
||||||
const {
|
const {
|
||||||
StaticDatabases,
|
StaticDatabases,
|
||||||
} = require("../../db/utils")
|
} = require("../../db/utils")
|
||||||
|
|
||||||
Date.now = jest.fn(() => 1487076708000)
|
Date = jest.fn(() => MOCK_DATE)
|
||||||
|
Date.now = jest.fn(() => MOCK_DATE_TIMESTAMP)
|
||||||
let db
|
let db
|
||||||
|
|
||||||
describe("migrations", () => {
|
describe("migrations", () => {
|
||||||
|
|
|
@ -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 core = require("../../index")
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
inMemory: true,
|
inMemory: true,
|
||||||
|
allDbs: true,
|
||||||
}
|
}
|
||||||
core.init({ db: dbConfig })
|
core.init({ db: dbConfig })
|
Loading…
Reference in New Issue