Files
Eric Mc Sween 8f0913fafe Merge pull request #27936 from overleaf/em-unit-tests-mongo
Make Mongo available to unit tests in all services

GitOrigin-RevId: b65bbb69883d5bba31d09802b89f35bdc523fe4d
2025-08-25 08:05:19 +00:00

34 lines
976 B
JavaScript

import Metrics from '@overleaf/metrics'
import MongoUtils from '@overleaf/mongo-utils'
import Settings from '@overleaf/settings'
import mongodb from 'mongodb-legacy'
const { MongoClient, ObjectId } = mongodb
/**
* @import { ProjectHistoryFailure } from './mongo-types'
*/
export { ObjectId }
export const mongoClient = new MongoClient(
Settings.mongo.url,
Settings.mongo.options
)
const mongoDb = mongoClient.db()
Metrics.mongodb.monitor(mongoClient)
async function cleanupTestDatabase() {
await MongoUtils.cleanupTestDatabase(mongoClient)
}
export const db = {
deletedProjects: mongoDb.collection('deletedProjects'),
projects: mongoDb.collection('projects'),
/** @type {mongodb.Collection<ProjectHistoryFailure>} */
projectHistoryFailures: mongoDb.collection('projectHistoryFailures'),
projectHistoryLabels: mongoDb.collection('projectHistoryLabels'),
projectHistorySyncState: mongoDb.collection('projectHistorySyncState'),
cleanupTestDatabase,
}