overleaf/services/web/test/acceptance/src/helpers/Institution.js
Eric Mc Sween 3791b8d288 Merge pull request #2104 from overleaf/ta-user-membership-acceptance-tests
Acceptance Tests for UserMembership Authorization

GitOrigin-RevId: caad99727fd2fedc91f2b2063ed83a1e02d9ea1d
2019-09-03 15:24:53 +00:00

38 lines
887 B
JavaScript

const { ObjectId } = require('../../../../app/src/infrastructure/mongojs')
const InstitutionModel = require('../../../../app/src/models/Institution')
.Institution
let count = parseInt(Math.random() * 999999)
class Institution {
constructor(options = {}) {
this.v1Id = options.v1Id || count
this.managerIds = []
count += 1
}
ensureExists(callback) {
const filter = { v1Id: this.v1Id }
const options = { upsert: true, new: true, setDefaultsOnInsert: true }
InstitutionModel.findOneAndUpdate(
filter,
{},
options,
(error, institution) => {
this._id = institution._id
callback(error)
}
)
}
setManagerIds(managerIds, callback) {
return InstitutionModel.findOneAndUpdate(
{ _id: ObjectId(this._id) },
{ managerIds: managerIds },
callback
)
}
}
module.exports = Institution