 
 				it "should return an error", ->
 					@callback
+						.calledWith(new Errors.InvalidNameError("file already exists"))
+						.should.equal true
+
+			describe "when the destination folder is inside the moving folder", ->
+				beforeEach ->
+					@path.fileSystem = "/one/two"
+					@pathToMoveTo.fileSystem = "/one/two/three"
+
+					@projectLocator.findElement.withArgs({project: @project, element_id: @move_to_folder_id, type: 'folder'})
+						.callsArgWith(1, null, @folder_to_move_to, @pathToMoveTo)
+					@callback = sinon.stub()
+					@ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", userId, @callback
+
+				it 'should find the folder we are moving to element', ->
+					@projectLocator.findElement
+						.calledWith({
+							element_id: @move_to_folder_id,
+							type: "folder",
+							project: @project
+						})
+						.should.equal true
+
+				it "should return an error", ->
+					@callback
 						.calledWith(new Error("destination folder is a child folder of me"))
 						.should.equal true
 

		@ProjectGetter =
			getProjectWithOnlyFolders : (project_id, callback)=> callback(null, @project)
			getProjectWithoutDocLines : (project_id, callback)=> callback(null, @project)
			getProject:sinon.stub()
		@projectUpdater = markAsUpdated:sinon.stub()
		@projectLocator =
			findElement : sinon.stub()

						})
						.should.equal true

			describe "when the destination folder contains a file with the same name", ->
				beforeEach ->
					@path.fileSystem = "/one/src_dir"
					@pathToMoveTo.fileSystem = "/two/dest_dir"
					@folder_to_move_to = { name: "folder to move to", fileRefs: [ {name: "folder"}] }
					@projectLocator.findElement.withArgs({project: @project, element_id: @move_to_folder_id, type: 'folder'})
						.callsArgWith(1, null, @folder_to_move_to, @pathToMoveTo)
					@callback = sinon.stub()
					@ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", userId, @callback

