FileConverterTests.coffee 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. @safe_exec = sinon.stub()
  11. @converter = SandboxedModule.require modulePath, requires:
  12. "./SafeExec": @safe_exec
  13. "logger-sharelatex":
  14. log:->
  15. err:->
  16. "metrics-sharelatex":
  17. inc:->
  18. Timer:->
  19. done:->
  20. "settings-sharelatex": @Settings =
  21. commands:
  22. convertCommandPrefix: []
  23. @sourcePath = "/this/path/here.eps"
  24. @format = "png"
  25. @error = "Error"
  26. describe "convert", ->
  27. it "should convert the source to the requested format", (done)->
  28. @safe_exec.callsArgWith(2)
  29. @converter.convert @sourcePath, @format, (err)=>
  30. args = @safe_exec.args[0][0]
  31. args.indexOf("#{@sourcePath}[0]").should.not.equal -1
  32. args.indexOf("#{@sourcePath}.#{@format}").should.not.equal -1
  33. done()
  34. it "should return the dest path", (done)->
  35. @safe_exec.callsArgWith(2)
  36. @converter.convert @sourcePath, @format, (err, destPath)=>
  37. destPath.should.equal "#{@sourcePath}.#{@format}"
  38. done()
  39. it "should return the error from convert", (done)->
  40. @safe_exec.callsArgWith(2, @error)
  41. @converter.convert @sourcePath, @format, (err)=>
  42. err.should.equal @error
  43. done()
  44. it "should not accapt an non aproved format", (done)->
  45. @safe_exec.callsArgWith(2)
  46. @converter.convert @sourcePath, "ahhhhh", (err)=>
  47. expect(err).to.exist
  48. done()
  49. it "should prefix the command with Settings.commands.convertCommandPrefix", (done) ->
  50. @safe_exec.callsArgWith(2)
  51. @Settings.commands.convertCommandPrefix = ["nice"]
  52. @converter.convert @sourcePath, @format, (err)=>
  53. command = @safe_exec.args[0][0]
  54. command[0].should.equal "nice"
  55. done()
  56. describe "thumbnail", ->
  57. it "should call converter resize with args", (done)->
  58. @safe_exec.callsArgWith(2)
  59. @converter.thumbnail @sourcePath, (err)=>
  60. args = @safe_exec.args[0][0]
  61. args.indexOf("#{@sourcePath}[0]").should.not.equal -1
  62. done()
  63. describe "preview", ->
  64. it "should call converter resize with args", (done)->
  65. @safe_exec.callsArgWith(2)
  66. @converter.preview @sourcePath, (err)=>
  67. args = @safe_exec.args[0][0]
  68. args.indexOf("#{@sourcePath}[0]").should.not.equal -1
  69. done()