FileConverterTests.coffee 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. @sourcePath = "/this/path/here.eps"
  17. @format = "png"
  18. @error = "Error"
  19. describe "convert", ->
  20. it "should convert the source to the requested format", (done)->
  21. @safe_exec.callsArgWith(2)
  22. @converter.convert @sourcePath, @format, (err)=>
  23. args = @safe_exec.args[0][0]
  24. args.indexOf(@sourcePath).should.not.equal -1
  25. args.indexOf(@format).should.not.equal -1
  26. done()
  27. it "should return the dest path", (done)->
  28. @safe_exec.callsArgWith(2)
  29. @converter.convert @sourcePath, @format, (err, destPath)=>
  30. destPath.should.equal "#{@sourcePath}.#{@format}"
  31. done()
  32. it "should return the error from convert", (done)->
  33. @safe_exec.callsArgWith(2, @error)
  34. @converter.convert @sourcePath, @format, (err)=>
  35. err.should.equal @error
  36. done()
  37. it "should not accapt an non aproved format", (done)->
  38. @safe_exec.callsArgWith(2)
  39. @converter.convert @sourcePath, "ahhhhh", (err)=>
  40. expect(err).to.exist
  41. done()
  42. describe "thumbnail", ->
  43. it "should call converter resize with args", (done)->
  44. @safe_exec.callsArgWith(2)
  45. @converter.thumbnail @sourcePath, (err)=>
  46. args = @safe_exec.args[0][0]
  47. args.indexOf(@sourcePath).should.not.equal -1
  48. done()
  49. describe "preview", ->
  50. it "should call converter resize with args", (done)->
  51. @safe_exec.callsArgWith(2)
  52. @converter.preview @sourcePath, (err)=>
  53. args = @safe_exec.args[0][0]
  54. args.indexOf(@sourcePath).should.not.equal -1
  55. done()