2014-02-14 11:39:05 -05:00
|
|
|
assert = require("chai").assert
|
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../app/js/FileConverter.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "FileConverter", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec = sinon.stub()
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter = SandboxedModule.require modulePath, requires:
|
2015-03-13 05:31:43 -04:00
|
|
|
"./SafeExec": @safe_exec
|
2014-02-14 11:39:05 -05:00
|
|
|
"logger-sharelatex":
|
|
|
|
log:->
|
|
|
|
err:->
|
|
|
|
|
|
|
|
@sourcePath = "/this/path/here.eps"
|
|
|
|
@format = "png"
|
|
|
|
@error = "Error"
|
|
|
|
|
|
|
|
describe "convert", ->
|
|
|
|
|
|
|
|
it "should convert the source to the requested format", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.convert @sourcePath, @format, (err)=>
|
2015-03-13 05:31:43 -04:00
|
|
|
args = @safe_exec.args[0][0]
|
2014-02-18 12:43:21 -05:00
|
|
|
args.indexOf(@sourcePath).should.not.equal -1
|
|
|
|
args.indexOf(@format).should.not.equal -1
|
2014-02-14 11:39:05 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "should return the dest path", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.convert @sourcePath, @format, (err, destPath)=>
|
|
|
|
destPath.should.equal "#{@sourcePath}.#{@format}"
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should return the error from convert", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2, @error)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.convert @sourcePath, @format, (err)=>
|
|
|
|
err.should.equal @error
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should not accapt an non aproved format", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.convert @sourcePath, "ahhhhh", (err)=>
|
|
|
|
expect(err).to.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "thumbnail", ->
|
2014-06-17 07:47:53 -04:00
|
|
|
it "should call converter resize with args", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.thumbnail @sourcePath, (err)=>
|
2015-03-13 05:31:43 -04:00
|
|
|
args = @safe_exec.args[0][0]
|
2014-02-14 11:39:05 -05:00
|
|
|
args.indexOf(@sourcePath).should.not.equal -1
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "preview", ->
|
2014-06-17 07:47:53 -04:00
|
|
|
it "should call converter resize with args", (done)->
|
2015-03-13 05:31:43 -04:00
|
|
|
@safe_exec.callsArgWith(2)
|
2014-02-14 11:39:05 -05:00
|
|
|
@converter.preview @sourcePath, (err)=>
|
2015-03-13 05:31:43 -04:00
|
|
|
args = @safe_exec.args[0][0]
|
2014-02-14 11:39:05 -05:00
|
|
|
args.indexOf(@sourcePath).should.not.equal -1
|
|
|
|
done()
|