<commit_before>should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/User/UserUpdater"
expect = require("chai").expect
tk = require('timekeeper')

describe "UserUpdater", ->

	beforeEach ->
		tk.freeze(Date.now())
		@mongojs = 
			db:{}
			ObjectId:(id)-> return id
		@UserGetter =
			getUserEmail: sinon.stub()
			getUserByAnyEmail: sinon.stub()
			ensureUniqueEmailAddress: sinon.stub()
		@logger = err: sinon.stub(), log: ->
		@addAffiliation = sinon.stub().yields()
		@removeAffiliation = sinon.stub().callsArgWith(2, null)
		@UserUpdater = SandboxedModule.require modulePath, requires:
			"logger-sharelatex": @logger
			"./UserGetter": @UserGetter
			'./UserAffiliationsManager':
				addAffiliation: @addAffiliation
				removeAffiliation: @removeAffiliation
			"../../infrastructure/mongojs":@mongojs
			"metrics-sharelatex": timeAsyncMethod: sinon.stub()

		@stubbedUser = 
			_id: "3131231"
			name:"bob"
			email:"<EMAIL>"
		@newEmail = "<EMAIL>"

	afterEach ->
		tk.reset()

	describe 'changeEmailAddress', ->
		beforeEach ->
			@UserGetter.getUserEmail.callsArgWith(1, null, @stubbedUser.email)
			@UserUpdater.addEmailAddress = sinon.stub().callsArgWith(2)
			@UserUpdater.setDefaultEmailAddress = sinon.stub().callsArgWith(2)
			@UserUpdater.removeEmailAddress = sinon.stub().callsArgWith(2)

		it 'change email', (done)->
			@UserUpdater.changeEmailAddress @stubbedUser._id, @newEmail, (err)=>
				should.not.exist(err)
				@UserUpdater.addEmailAddress.calledWith(
					@stubbedUser._id, @newEmail<commit_msg>Add some missing unit test mocks<commit_after>should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/User/UserUpdater"
expect = require("chai").expect
tk = require('timekeeper')

describe "UserUpdater", ->

	beforeEach ->
		tk.freeze(Date.now())
		@mongojs = 
			db:{}
			ObjectId:(id)-> return id
		@UserGetter =
			getUserEmail: sinon.stub()
			getUserByAnyEmail: sinon.stub()
			ensureUniqueEmailAddress: sinon.stub()
		@logger = err: sinon.stub(), log: ->
		@addAffiliation = sinon.stub().yields()
		@removeAffiliation = sinon.stub().callsArgWith(2, null)
		@UserUpdater = SandboxedModule.require modulePath, requires:
			"logger-sharelatex": @logger
			"./UserGetter": @UserGetter
			'./UserAffiliationsManager':
				addAffiliation: @addAffiliation
				removeAffiliation: @removeAffiliation
			"../../infrastructure/mongojs":@mongojs
			"metrics-sharelatex": timeAsyncMethod: sinon.stub()
			"settings-sharelatex": @settings = {}
			"request": @request = {}

		@stubbedUser = 
			_id: "3131231"
			name:"bob"
			email:"<EMAIL>"
		@newEmail = "<EMAIL>"

	afterEach ->
		tk.reset()

	describe 'changeEmailAddress', ->
		beforeEach ->
			@UserGetter.getUserEmail.callsArgWith(1, null, @stubbedUser.email)
			@UserUpdater.addEmailAddress = sinon.stub().callsArgWith(2)
			@UserUpdater.setDefaultEmailAddress = sinon.stub().callsArgWith(2)
			@UserUpdater.removeEmailAddress = sinon.stub().callsArgWith(2)

		it 'change email', (done)->
			@UserUpdater.changeEmailAddress @stubbedUser._id, @newEmail, (err)=>
				should.not.exist(err)
				@UserUpdater.addEmailAddress.calledWith(
					@stubbedUser._id, @newEmail
{'fraction_non_alphanumeric': 0.15973425765453494, 'fraction_numerical': 0.006932409012131715, 'mean_word_length': 4.576489533011272, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 25, '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': '134988', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1224, 'n_words': 194}