1
0
Fork 0
mirror of synced 2024-06-02 18:44:54 +12:00
budibase/packages/server/__mocks__/mongodb.ts
2022-08-08 17:01:56 +01:00

38 lines
1,006 B
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.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,
count: this.count,
deleteOne: this.deleteOne,
deleteMany: this.deleteMany,
updateOne: this.updateOne,
updateMany: this.updateMany,
}))
this.db = () => ({
collection: this.collection,
})
}
mongodb.ObjectID = require("mongodb").ObjectID
module.exports = mongodb
}