<commit_before>SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
require('chai').should()
modulePath = require('path').join __dirname, '../../../app/js/MongoManager'
ObjectId = require("mongojs").ObjectId
assert = require("chai").assert

describe "MongoManager", ->
	beforeEach ->
		@MongoManager = SandboxedModule.require modulePath, requires:
			"./mongojs":
				db: @db = { docs: {}, docOps: {} }
				ObjectId: ObjectId
			'metrics-sharelatex': {timeAsyncMethod: sinon.stub()}
		@project_id = ObjectId().toString()
		@doc_id = ObjectId().toString()
		@callback = sinon.stub()
		@stubbedErr = new Error("hello world")

	describe "findDoc", ->
		beforeEach ->
			@doc = { name: "mock-doc"}
			@db.docs.find = sinon.stub().callsArgWith(2, null, [@doc])
			@filter = { lines: true }
			@MongoManager.findDoc @project_id, @doc_id, @filter, @callback

		it "should find the doc", ->
			@db.docs.find
				.calledWith({
					_id: ObjectId(@doc_id)
					project_id: ObjectId(@project_id)
				}, @filter)
				.should.equal true

		it "should call the callback with the doc", ->
			@callback.calledWith(null, @doc).should.equal true

	describe "getProjectsDocs", ->
		beforeEach ->
			@filter = {lines: true}
			@doc1 = { name: "mock-doc1" }
			@doc2 = { name: "mock-doc2" }
			@doc3 = { name: "mock-doc3" }<commit_msg>Stub out logger in tests<commit_after>SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
require('chai').should()
modulePath = require('path').join __dirname, '../../../app/js/MongoManager'
ObjectId = require("mongojs").ObjectId
assert = require("chai").assert

describe "MongoManager", ->
	beforeEach ->
		@MongoManager = SandboxedModule.require modulePath, requires:
			"./mongojs":
				db: @db = { docs: {}, docOps: {} }
				ObjectId: ObjectId
			'metrics-sharelatex': {timeAsyncMethod: sinon.stub()}
			'logger-sharelatex': {log: ()->}
		@project_id = ObjectId().toString()
		@doc_id = ObjectId().toString()
		@callback = sinon.stub()
		@stubbedErr = new Error("hello world")

	describe "findDoc", ->
		beforeEach ->
			@doc = { name: "mock-doc"}
			@db.docs.find = sinon.stub().callsArgWith(2, null, [@doc])
			@filter = { lines: true }
			@MongoManager.findDoc @project_id, @doc_id, @filter, @callback

		it "should find the doc", ->
			@db.docs.find
				.calledWith({
					_id: ObjectId(@doc_id)
					project_id: ObjectId(@project_id)
				}, @filter)
				.should.equal true

		it "should call the callback with the doc", ->
			@callback.calledWith(null, @doc).should.equal true

	describe "getProjectsDocs", ->
		beforeEach ->
			@filter = {lines: true}
			@doc1 = { name: "mock-doc1" }
			@doc2 = { name: "mock-doc2" }
			@doc3 = { name: "mock-doc3" }
{'fraction_non_alphanumeric': 0.1781630394688307, 'fraction_numerical': 0.005164146071560309, 'mean_word_length': 3.766256590509666, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 20, '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': '6741580', 'n_tokens_mistral': 1078, 'n_tokens_neox': 958, 'n_words': 202}