<commit_before>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 ->

		@child_process =
			exec : sinon.stub()
		@converter = SandboxedModule.require modulePath, requires:
			'child_process': @child_process
			"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)->
			@child_process.exec.callsArgWith(2)
			@converter.convert @sourcePath, @format, (err)=>
				args = @child_process.exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				args.indexOf(@format).should.not.equal -1 
				done()

		it "should return the dest path", (done)->
			@child_process.exec.callsArgWith(2)
			@converter.convert @sourcePath, @format, (err, destPath)=>
				destPath.should.equal "#{@sourcePath}.#{@format}"
				done()

		it "should return the error from convert", (done)->
			@child_process.exec.callsArgWith(2, @error)
			@converter.convert @sourcePath, @format, (err)=>
				err.should.equal @error
				done()

		it "should not accapt an non aproved format", (done)->
			@child_process.exec.callsArgWith(2)
			@converter.convert @sourcePath, "ahhhhh", (err)=>
				expect(err).to.exist
				done()

	describe "thumbnail", ->
		it "should call converter resize with args", (done)->
			@child_process.exec.callsArgWith(2)
			@converter.thumbnail @sourcePath, (err)=>
				args = @child_process.exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				done()

	describe "preview", ->
		it "should call converter resize with args", (done)->
			@child_process.exec.callsArgWith(2)
			@converter.preview @sourcePath, (err)=>
				args = @child_process.exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				done()<commit_msg>update tests to use safe_exec<commit_after>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 ->

		@safe_exec = sinon.stub()
		@converter = SandboxedModule.require modulePath, requires:
			"./SafeExec": @safe_exec
			"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)->
			@safe_exec.callsArgWith(2)
			@converter.convert @sourcePath, @format, (err)=>
				args = @safe_exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				args.indexOf(@format).should.not.equal -1 
				done()

		it "should return the dest path", (done)->
			@safe_exec.callsArgWith(2)
			@converter.convert @sourcePath, @format, (err, destPath)=>
				destPath.should.equal "#{@sourcePath}.#{@format}"
				done()

		it "should return the error from convert", (done)->
			@safe_exec.callsArgWith(2, @error)
			@converter.convert @sourcePath, @format, (err)=>
				err.should.equal @error
				done()

		it "should not accapt an non aproved format", (done)->
			@safe_exec.callsArgWith(2)
			@converter.convert @sourcePath, "ahhhhh", (err)=>
				expect(err).to.exist
				done()

	describe "thumbnail", ->
		it "should call converter resize with args", (done)->
			@safe_exec.callsArgWith(2)
			@converter.thumbnail @sourcePath, (err)=>
				args = @safe_exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				done()

	describe "preview", ->
		it "should call converter resize with args", (done)->
			@safe_exec.callsArgWith(2)
			@converter.preview @sourcePath, (err)=>
				args = @safe_exec.args[0][0]
				args.indexOf(@sourcePath).should.not.equal -1 
				done()
{'fraction_non_alphanumeric': 0.16480730223123732, 'fraction_numerical': 0.008113590263691683, 'mean_word_length': 3.8404907975460123, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3422521', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1348, 'n_words': 294}