ReferencesSearchHandlerTests.coffee 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. SandboxedModule = require('sandboxed-module')
  2. should = require('chai').should()
  3. expect = require('chai').expect
  4. sinon = require 'sinon'
  5. assert = require("chai").assert
  6. modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchHandler"
  7. describe 'ReferencesSearchHandler', ->
  8. # beforeEach ->
  9. # @project_id = '222'
  10. # @file_id = '111111'
  11. # @handler = SandboxedModule.require modulePath, requires:
  12. # 'logger-sharelatex': {
  13. # log: ->
  14. # err: ->
  15. # }
  16. # 'settings-sharelatex': @settings = {
  17. # apis:
  18. # references: {url: 'http://some.url'}
  19. # web: {url: 'http://some.url'}
  20. # }
  21. # 'request': @request = {
  22. # get: sinon.stub()
  23. # post: sinon.stub()
  24. # }
  25. # '../../models/Project': @Project = {
  26. # Project: {
  27. # findById: sinon.stub().callsArgWith(2, null, {owner_ref: '111'})
  28. # }
  29. # }
  30. # '../User/UserGetter': @UserGetter = {
  31. # getUser: sinon.stub().callsArgWith(2, null, {features: {references: false}})
  32. # }
  33. # describe 'indexFile', ->
  34. # describe 'full index or not', ->
  35. # beforeEach ->
  36. # @request.post.callsArgWith(1, null, {statusCode: 200}, {})
  37. # describe 'when full index is not required', ->
  38. # beforeEach ->
  39. # @UserGetter.getUser.callsArgWith(2, null, {features: {references: false}})
  40. # it 'should set fullIndex to true', (done) ->
  41. # @handler.indexFile @project_id, @file_id, (err) =>
  42. # @request.post.calledOnce.should.equal true
  43. # options = @request.post.firstCall.args[0]
  44. # options.json.fullIndex.should.equal false
  45. # done()
  46. # describe 'when full index is required', ->
  47. # beforeEach ->
  48. # @UserGetter.getUser.callsArgWith(2, null, {features: {references: true}})
  49. # it 'should set fullIndex to true', (done) ->
  50. # @handler.indexFile @project_id, @file_id, (err) =>
  51. # @request.post.calledOnce.should.equal true
  52. # options = @request.post.firstCall.args[0]
  53. # options.json.fullIndex.should.equal true
  54. # done()
  55. # describe 'when index operation is successful', ->
  56. # beforeEach ->
  57. # @request.post.callsArgWith(1, null, {statusCode: 201}, {})
  58. # it 'should not produce an error', (done) ->
  59. # @handler.indexFile @project_id, @file_id, (err) =>
  60. # expect(err).to.equal null
  61. # @request.post.calledOnce.should.equal true
  62. # options = @request.post.firstCall.args[0]
  63. # options.json.fullIndex.should.equal false
  64. # options.json.referencesUrl.should.not.be.undefined
  65. # options.url.should.not.be.undefined
  66. # done()
  67. # describe 'when index operation fails', ->
  68. # beforeEach ->
  69. # @request.post.callsArgWith(1, null, {statusCode: 500}, {})
  70. # it 'should produce an error', (done) ->
  71. # @handler.indexFile @project_id, @file_id, (err) =>
  72. # expect(err).to.not.equal null
  73. # done()
  74. # describe 'getKeys', ->
  75. # describe 'when request is successful', ->
  76. # beforeEach ->
  77. # @data =
  78. # projectId: @projectId
  79. # keys: ['a', 'b', 'c']
  80. # @request.get.callsArgWith(1, null, {statusCode: 200}, @data)
  81. # it 'should not produce an error', ->
  82. # @handler.getKeys @project_id, (err, result) =>
  83. # expect(err).to.equal null
  84. # it 'should produce a result object', ->
  85. # @handler.getKeys @project_id, (err, result) =>
  86. # expect(result).to.not.equal null
  87. # expect(result).to.deep.equal @data
  88. # describe 'when request fails', ->
  89. # beforeEach ->
  90. # @data =
  91. # projectId: @project_Id
  92. # keys: ['a', 'b', 'c']
  93. # @request.get.callsArgWith(1, null, {statusCode: 500}, null)
  94. # it 'should produce an error', ->
  95. # @handler.getKeys @project_id, (err, result) =>
  96. # expect(err).to.not.equal null
  97. # it 'should not produce a result', ->
  98. # @handler.getKeys @project_id, (err, result) =>
  99. # expect(result).to.not.equal null