setDocVersionInMongo.coffee 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/PersistenceManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. Errors = require "../../../../app/js/Errors"
  7. {ObjectId} = require("mongojs")
  8. describe "PersistenceManager.getDocVersionInMongo", ->
  9. beforeEach ->
  10. @PersistenceManager = SandboxedModule.require modulePath, requires:
  11. "request": @request = sinon.stub()
  12. "settings-sharelatex": @Settings = {}
  13. "./Metrics": @Metrics =
  14. Timer: class Timer
  15. done: sinon.stub()
  16. "./mongojs":
  17. db: @db = { docOps: {} }
  18. ObjectId: ObjectId
  19. @doc_id = ObjectId().toString()
  20. @callback = sinon.stub()
  21. describe "setDocVersionInMongo", ->
  22. beforeEach ->
  23. @version = 42
  24. @db.docOps.update = sinon.stub().callsArg(3)
  25. @PersistenceManager.setDocVersionInMongo @doc_id, @version, @callback
  26. it "should update the doc version", ->
  27. @db.docOps.update
  28. .calledWith({
  29. doc_id: ObjectId(@doc_id)
  30. }, {
  31. $set:
  32. version: @version
  33. }, {
  34. upsert: true
  35. })
  36. .should.equal true
  37. it "should call the callback", ->
  38. @callback.called.should.equal true