DropboxWebhookControllerTests.coffee 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. SandboxedModule = require('sandboxed-module')
  2. assert = require('assert')
  3. require('chai').should()
  4. sinon = require('sinon')
  5. modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxWebhookController.js'
  6. describe 'DropboxWebhookController', ->
  7. beforeEach ->
  8. @DropboxWebhookController = SandboxedModule.require modulePath, requires:
  9. "./DropboxWebhookHandler": @DropboxWebhookHandler = {}
  10. 'logger-sharelatex':
  11. log:->
  12. err:->
  13. describe "verify", ->
  14. beforeEach ->
  15. @res =
  16. send: sinon.stub()
  17. @req.query =
  18. challenge: @challenge = "foo"
  19. @DropboxWebhookController.verify(@req, @res)
  20. it "should echo the challenge parameter back", ->
  21. @res.send.calledWith(@challenge).should.equal true
  22. describe "webhook", ->
  23. beforeEach ->
  24. @req.body =
  25. delta:
  26. users: @dropbox_uids = [
  27. "123456",
  28. "789123"
  29. ]
  30. @res.send = sinon.stub()
  31. @DropboxWebhookHandler.pollDropboxUids = sinon.stub().callsArg(1)
  32. @DropboxWebhookController.webhook(@req, @res)
  33. it "should poll the Dropbox uids", ->
  34. @DropboxWebhookHandler.pollDropboxUids
  35. .calledWith(@dropbox_uids)
  36. .should.equal true
  37. it "should return success", ->
  38. @res.send
  39. .calledWith(200)
  40. .should.equal true