1
0
Fork 0
mirror of synced 2024-05-06 21:43:08 +12:00
budibase/packages/server/__mocks__/mongodb.ts
2022-10-03 19:10:01 +01:00

40 lines
1.1 KiB
TypeScript

module MongoMock {
const mongodb: any = {}
mongodb.MongoClient = function () {
this.connect = jest.fn()
this.close = jest.fn()
this.insertOne = jest.fn()
this.insertMany = jest.fn(() => ({ toArray: () => [] }))
this.find = jest.fn(() => ({ toArray: () => [] }))
this.findOne = jest.fn()
this.findOneAndUpdate = jest.fn()
this.count = jest.fn()
this.deleteOne = jest.fn()
this.deleteMany = jest.fn(() => ({ toArray: () => [] }))
this.updateOne = jest.fn()
this.updateMany = jest.fn(() => ({ toArray: () => [] }))
this.collection = jest.fn(() => ({
insertOne: this.insertOne,
find: this.find,
insertMany: this.insertMany,
findOne: this.findOne,
findOneAndUpdate: this.findOneAndUpdate,
count: this.count,
deleteOne: this.deleteOne,
deleteMany: this.deleteMany,
updateOne: this.updateOne,
updateMany: this.updateMany,
}))
this.db = () => ({
collection: this.collection,
})
}
mongodb.ObjectId = jest.requireActual("mongodb").ObjectId
module.exports = mongodb
}