FileConverterTests.coffee 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. assert = require("chai").assert
  2. sinon = require('sinon')
  3. chai = require('chai')
  4. should = chai.should()
  5. expect = chai.expect
  6. modulePath = "../../../app/js/FileConverter.js"
  7. SandboxedModule = require('sandboxed-module')
  8. describe "FileConverter", ->
  9. beforeEach ->
  10. @easyimage =
  11. convert:sinon.stub()
  12. exec: sinon.stub()
  13. @child_process =
  14. exec : sinon.stub()
  15. @converter = SandboxedModule.require modulePath, requires:
  16. "easyimage":@easyimage
  17. 'child_process': @child_process
  18. "logger-sharelatex":
  19. log:->
  20. err:->
  21. @sourcePath = "/this/path/here.eps"
  22. @format = "png"
  23. @error = "Error"
  24. describe "convert", ->
  25. it "should convert the source to the requested format", (done)->
  26. @child_process.exec.callsArgWith(2)
  27. @converter.convert @sourcePath, @format, (err)=>
  28. args = @child_process.exec.args[0][0]
  29. args.indexOf(@sourcePath).should.not.equal -1
  30. args.indexOf(@format).should.not.equal -1
  31. done()
  32. it "should return the dest path", (done)->
  33. @child_process.exec.callsArgWith(2)
  34. @converter.convert @sourcePath, @format, (err, destPath)=>
  35. destPath.should.equal "#{@sourcePath}.#{@format}"
  36. done()
  37. it "should return the error from convert", (done)->
  38. @child_process.exec.callsArgWith(2, @error)
  39. @converter.convert @sourcePath, @format, (err)=>
  40. err.should.equal @error
  41. done()
  42. it "should not accapt an non aproved format", (done)->
  43. @child_process.exec.callsArgWith(2)
  44. @converter.convert @sourcePath, "ahhhhh", (err)=>
  45. expect(err).to.exist
  46. done()
  47. describe "thumbnail", ->
  48. it "should call easy image resize with args", (done)->
  49. @child_process.exec.callsArgWith(2)
  50. @converter.thumbnail @sourcePath, (err)=>
  51. args = @child_process.exec.args[0][0]
  52. args.indexOf(@sourcePath).should.not.equal -1
  53. done()
  54. describe "preview", ->
  55. it "should call easy image resize with args", (done)->
  56. @child_process.exec.callsArgWith(2)
  57. @converter.preview @sourcePath, (err)=>
  58. args = @child_process.exec.args[0][0]
  59. args.indexOf(@sourcePath).should.not.equal -1
  60. done()