1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

DatabaseImpl.docExists test

This commit is contained in:
Adria Navarro 2024-02-29 15:17:18 +01:00
parent 7d50a70d03
commit 3af2da3b7d

View file

@ -0,0 +1,55 @@
import _ from "lodash"
import { AnyDocument } from "@budibase/types"
import { generator } from "../../../tests"
import { DatabaseImpl } from "../couch"
import { newid } from "../../utils"
describe("DatabaseImpl", () => {
const database = new DatabaseImpl(generator.word())
const documents: AnyDocument[] = []
beforeAll(async () => {
const docsToCreate = Array.from({ length: 10 }).map(() => ({
_id: newid(),
}))
const createdDocs = await database.bulkDocs(docsToCreate)
documents.push(...createdDocs.map((x: any) => ({ _id: x.id, _rev: x.rev })))
})
describe("docExists", () => {
it("can check existing docs by id", async () => {
const existingDoc = _.sample(documents)
const result = await database.docExists(existingDoc!._id!)
expect(result).toBe(true)
})
it("can check non existing docs by id", async () => {
const result = await database.docExists(newid())
expect(result).toBe(false)
})
it("can check an existing doc by id multiple times", async () => {
const existingDoc = _.sample(documents)
const id = existingDoc!._id!
const results = []
results.push(await database.docExists(id))
results.push(await database.docExists(id))
results.push(await database.docExists(id))
expect(results).toEqual([true, true, true])
})
it("returns false after the doc is deleted", async () => {
const existingDoc = _.sample(documents)
const id = existingDoc!._id!
expect(await database.docExists(id)).toBe(true)
await database.remove(existingDoc!)
expect(await database.docExists(id)).toBe(false)
})
})
})