1
0
Fork 0
mirror of synced 2024-05-19 11:53:53 +12:00
budibase/packages/server/__mocks__/mongodb.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

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()
2022-08-09 04:53:17 +12:00
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,
2022-08-09 04:53:17 +12:00
findOneAndUpdate: this.findOneAndUpdate,
count: this.count,
deleteOne: this.deleteOne,
deleteMany: this.deleteMany,
updateOne: this.updateOne,
updateMany: this.updateMany,
}))
this.db = () => ({
collection: this.collection,
})
}
2022-10-04 07:10:01 +13:00
mongodb.ObjectId = jest.requireActual("mongodb").ObjectId
2022-08-09 04:01:56 +12:00
module.exports = mongodb
}