setDocVersionInMongo.coffee 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "logger-sharelatex": @logger = {log: sinon.stub(), err: sinon.stub()}
  20. @doc_id = ObjectId().toString()
  21. @callback = sinon.stub()
  22. describe "setDocVersionInMongo", ->
  23. beforeEach ->
  24. @version = 42
  25. @db.docOps.update = sinon.stub().callsArg(3)
  26. @PersistenceManager.setDocVersionInMongo @doc_id, @version, @callback
  27. it "should update the doc version", ->
  28. @db.docOps.update
  29. .calledWith({
  30. doc_id: ObjectId(@doc_id)
  31. }, {
  32. $set:
  33. version: @version
  34. }, {
  35. upsert: true
  36. })
  37. .should.equal true
  38. it "should call the callback", ->
  39. @callback.called.should.equal true