Files
Verso/services/web/test/acceptance/src/helpers/Publisher.js
T
andrew rumbleandCopybot 032deaf05c Switch to mongodb-legacy
GitOrigin-RevId: 11e09528c153de6b7766d18c3c90d94962190371
2024-08-21 08:04:24 +00:00

39 lines
998 B
JavaScript

const { ObjectId } = require('mongodb-legacy')
const PublisherModel = require('../../../../app/src/models/Publisher').Publisher
const { callbackifyClass } = require('@overleaf/promise-utils')
let count = parseInt(Math.random() * 999999)
class PromisifiedPublisher {
constructor(options = {}) {
this.slug = options.slug || `publisher-slug-${count}`
this.managerIds = []
count += 1
}
async ensureExists() {
const filter = { slug: this.slug }
const options = { upsert: true, new: true, setDefaultsOnInsert: true }
const publisher = await PublisherModel.findOneAndUpdate(
filter,
{},
options
).exec()
this._id = publisher._id
}
async setManagerIds(managerIds) {
return await PublisherModel.findOneAndUpdate(
{ _id: new ObjectId(this._id) },
{ managerIds }
).exec()
}
}
const Publisher = callbackifyClass(PromisifiedPublisher)
Publisher.promises = class extends PromisifiedPublisher {}
module.exports = Publisher