<commit_before>SandboxedModule = require('sandboxed-module')
assert = require('assert')
chai = require('chai')
expect = chai.expect
sinon = require('sinon')
modulePath = require('path').join __dirname, '../../../../app/js/Features/Exports/ExportsController.js'


describe 'ExportsController', ->
	project_id = "123njdskj9jlk"
	user_id = "123nd3ijdks"
	brand_variation_id = 22
	firstName = 'first'
	lastName = 'last'
	title = "title"
	description = "description"
	author = "author"
	license = "other"
	show_source = true

	beforeEach ->
		@handler =
			getUserNotifications: sinon.stub().callsArgWith(1)
		@req =
			params:
				project_id: project_id
				brand_variation_id: brand_variation_id
			body:
				firstName: firstName
				lastName: lastName
			session:
				user:
					_id:user_id
			i18n:
				translate:->
		@AuthenticationController =
			getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
		@controller = SandboxedModule.require modulePath, requires:
			"./ExportsHandler":@handler
			'logger-sharelatex':
				log:->
				err:->
			'../Authentication/AuthenticationController': @AuthenticationController

	describe "without gallery fields",->
		it 'should ask the handler to perform the export', (done) ->
			@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
			expected =
				project_id: project_id
				user_id: user_id
				brand_variation_id: brand_variation_id
				first_name: firstName
				last_name: lastName
			@controller.exportProject @req, send:(body) =>
				expect(@handler.exportProject.args[0][0]).to.deep.equal expected
				expect(body).to.deep.equal {export_v1_id: 897}
				done()

	describe "with gallery fields",->
		beforeEach ->
			@req.body.title = title
			@req.body.description = description
			@req.body.author = author
			@req.body.license = license
			@req.body.show_source = true

		it 'should ask the handler to perform the export', (done) ->
			@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
			expected =
				project_id: project_id
				user_id: user_id
				brand_variation_id: brand_variation_id
				first_name: firstName
				last_name: lastName
				title: title
				description: description
				author: author
				license: license
				show_source: show_source
			@controller.exportProject @req, send:(body) =>
				expect(@handler.exportProject.args[0][0]).to.deep.equal expected
				expect(body).to.deep.equal {export_v1_id: 897}
				done()

	it 'should ask the handler to return the status of an export', (done) ->
		@handler.fetchExport = sinon.stub().yields(
			null,
			"{\"id\":897, \"status_summary\":\"completed\"}")

		@req.params = {project_id: project_id, export_id: 897}
		@controller.exportStatus @req, send:(body) =>
			expect(body).to.deep.equal {export_json: {
				status_summary: 'completed', status_detail: undefined
			}}
			done()<commit_msg>fixing broken exports test<commit_after>SandboxedModule = require('sandboxed-module')
assert = require('assert')
chai = require('chai')
expect = chai.expect
sinon = require('sinon')
modulePath = require('path').join __dirname, '../../../../app/js/Features/Exports/ExportsController.js'


describe 'ExportsController', ->
	project_id = "123njdskj9jlk"
	user_id = "123nd3ijdks"
	brand_variation_id = 22
	firstName = 'first'
	lastName = 'last'
	title = "title"
	description = "description"
	author = "author"
	license = "other"
	show_source = true

	beforeEach ->
		@handler =
			getUserNotifications: sinon.stub().callsArgWith(1)
		@req =
			params:
				project_id: project_id
				brand_variation_id: brand_variation_id
			body:
				firstName: firstName
				lastName: lastName
			session:
				user:
					_id:user_id
			i18n:
				translate:->
		@AuthenticationController =
			getLoggedInUserId: sinon.stub().returns(@req.session.user._id)
		@controller = SandboxedModule.require modulePath, requires:
			"./ExportsHandler":@handler
			'logger-sharelatex':
				log:->
				err:->
			'../Authentication/AuthenticationController': @AuthenticationController

	describe "without gallery fields",->
		it 'should ask the handler to perform the export', (done) ->
			@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
			expected =
				project_id: project_id
				user_id: user_id
				brand_variation_id: brand_variation_id
				first_name: firstName
				last_name: lastName
			@controller.exportProject @req, send:(body) =>
				expect(@handler.exportProject.args[0][0]).to.deep.equal expected
				expect(body).to.deep.equal {export_v1_id: 897}
				done()

	describe "with gallery fields",->
		beforeEach ->
			@req.body.title = title
			@req.body.description = description
			@req.body.author = author
			@req.body.license = license
			@req.body.show_source = true

		it 'should ask the handler to perform the export', (done) ->
			@handler.exportProject = sinon.stub().yields(null, {iAmAnExport: true, v1_id: 897})
			expected =
				project_id: project_id
				user_id: user_id
				brand_variation_id: brand_variation_id
				first_name: firstName
				last_name: lastName
				title: title
				description: description
				author: author
				license: license
				show_source: show_source
			@controller.exportProject @req, send:(body) =>
				expect(@handler.exportProject.args[0][0]).to.deep.equal expected
				expect(body).to.deep.equal {export_v1_id: 897}
				done()

	it 'should ask the handler to return the status of an export', (done) ->
		@handler.fetchExport = sinon.stub().yields(
			null,
			"{\"id\":897, \"status_summary\":\"completed\"}")

		@req.params = {project_id: project_id, export_id: 897}
		@controller.exportStatus @req, send:(body) =>
			expect(body).to.deep.equal {export_json: {
				status_summary: 'completed', status_detail: undefined, partner_submission_id: undefined, token: undefined
			}}
			done()
{'fraction_non_alphanumeric': 0.12969634585692227, 'fraction_numerical': 0.013381369016984045, 'mean_word_length': 3.9914383561643834, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 31, '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': '7059959', 'n_tokens_mistral': 2292, 'n_tokens_neox': 1921, 'n_words': 412}