Просмотр исходного кода

Upgrade sinonjs, and fix unit tests.

- use `sinon.match.has` for error matching
- restore previous use of `calledWith`
Shane Kilkelly 9 лет назад
Родитель
Сommit
65697cb2f6

+ 1 - 1
services/docstore/package.json

@@ -26,7 +26,7 @@
     "grunt": "~0.4.4",
     "grunt": "~0.4.4",
     "bunyan": "~0.22.3",
     "bunyan": "~0.22.3",
     "grunt-bunyan": "~0.5.0",
     "grunt-bunyan": "~0.5.0",
-    "sinon": "~1.5.2",
+    "sinon": "~3.2.1",
     "sandboxed-module": "~0.3.0",
     "sandboxed-module": "~0.3.0",
     "chai": "~1.9.1",
     "chai": "~1.9.1",
     "grunt-forever": "~0.4.4",
     "grunt-forever": "~0.4.4",

+ 6 - 6
services/docstore/test/unit/coffee/DocManagerTests.coffee

@@ -184,7 +184,7 @@ describe "DocManager", ->
 
 
 			it "should return a NotFoundError", ->
 			it "should return a NotFoundError", ->
 				@callback
 				@callback
-					.calledWith(new Errors.NotFoundError("No such doc: #{@doc_id} in project #{@project_id}"))
+					.calledWith(sinon.match.has('message', "No such doc: #{@doc_id} in project #{@project_id}"))
 					.should.equal true
 					.should.equal true
 
 
 	describe "getAllNonDeletedDocs", ->
 	describe "getAllNonDeletedDocs", ->
@@ -212,7 +212,7 @@ describe "DocManager", ->
 
 
 			it "should return a NotFoundError", ->
 			it "should return a NotFoundError", ->
 				@callback
 				@callback
-					.calledWith(new Errors.NotFoundError("No docs for project #{@project_id}"))
+					.calledWith(sinon.match.has('message', "No docs for project #{@project_id}"))
 					.should.equal true
 					.should.equal true
 
 
 	describe "deleteDoc", ->
 	describe "deleteDoc", ->
@@ -244,7 +244,7 @@ describe "DocManager", ->
 
 
 			it "should return a NotFoundError", ->
 			it "should return a NotFoundError", ->
 				@callback
 				@callback
-					.calledWith(new Errors.NotFoundError("No such doc: #{@doc_id}"))
+					.calledWith(sinon.match.has('message', "No such project/doc to delete: #{@project_id}/#{@doc_id}"))
 					.should.equal true
 					.should.equal true
 
 
 	describe "updateDoc", ->
 	describe "updateDoc", ->
@@ -349,21 +349,21 @@ describe "DocManager", ->
 				@DocManager.updateDoc @project_id, @doc_id, @newDocLines, null, @originalRanges, @callback
 				@DocManager.updateDoc @project_id, @doc_id, @newDocLines, null, @originalRanges, @callback
 
 
 			it "should return an error", ->
 			it "should return an error", ->
-				@callback.calledWith(new Error("no lines, version or ranges provided")).should.equal true
+				@callback.calledWith(sinon.match.has('message', "no lines, version or ranges provided")).should.equal true
 
 
 		describe "when the lines are null", ->
 		describe "when the lines are null", ->
 			beforeEach ->
 			beforeEach ->
 				@DocManager.updateDoc @project_id, @doc_id, null, @version, @originalRanges, @callback
 				@DocManager.updateDoc @project_id, @doc_id, null, @version, @originalRanges, @callback
 
 
 			it "should return an error", ->
 			it "should return an error", ->
-				@callback.calledWith(new Error("no lines, version or ranges provided")).should.equal true
+				@callback.calledWith(sinon.match.has('message', "no lines, version or ranges provided")).should.equal true
 
 
 		describe "when the ranges are null", ->
 		describe "when the ranges are null", ->
 			beforeEach ->
 			beforeEach ->
 				@DocManager.updateDoc @project_id, @doc_id, @newDocLines, @version, null, @callback
 				@DocManager.updateDoc @project_id, @doc_id, @newDocLines, @version, null, @callback
 
 
 			it "should return an error", ->
 			it "should return an error", ->
-				@callback.calledWith(new Error("no lines, version or ranges provided")).should.equal true
+				@callback.calledWith(sinon.match.has('message', "no lines, version or ranges provided")).should.equal true
 
 
 		describe "when there is a generic error getting the doc", ->
 		describe "when there is a generic error getting the doc", ->
 			beforeEach ->
 			beforeEach ->

+ 2 - 2
services/docstore/test/unit/coffee/HttpControllerTests.coffee

@@ -174,7 +174,7 @@ describe "HttpController", ->
 			it "should log out an error", ->
 			it "should log out an error", ->
 				@logger.error
 				@logger.error
 					.calledWith(
 					.calledWith(
-						err: new Error("null doc")
+						err: sinon.match.has('message', "null doc")
 						project_id: @project_id
 						project_id: @project_id
 						"encountered null doc"
 						"encountered null doc"
 					)
 					)
@@ -325,4 +325,4 @@ describe "HttpController", ->
 		it "should return a 204 (No Content)", ->
 		it "should return a 204 (No Content)", ->
 			@res.send
 			@res.send
 				.calledWith(204)
 				.calledWith(204)
-				.should.equal true
+				.should.equal true

+ 30 - 20
services/docstore/test/unit/coffee/MongoManagerTests.coffee

@@ -26,10 +26,12 @@ describe "MongoManager", ->
 			@MongoManager.findDoc @project_id, @doc_id, @filter, @callback
 			@MongoManager.findDoc @project_id, @doc_id, @filter, @callback
 
 
 		it "should find the doc", ->
 		it "should find the doc", ->
-			@db.docs.find.lastCall.args.slice(0,2).should.deep.equal([
-				{_id: ObjectId(@doc_id), project_id: ObjectId(@project_id)},
-				@filter
-			])
+			@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", ->
 		it "should call the callback with the doc", ->
 			@callback.calledWith(null, @doc).should.equal true
 			@callback.calledWith(null, @doc).should.equal true
@@ -48,9 +50,12 @@ describe "MongoManager", ->
 				@MongoManager.getProjectsDocs @project_id, include_deleted: false, @filter, @callback
 				@MongoManager.getProjectsDocs @project_id, include_deleted: false, @filter, @callback
 
 
 			it "should find the non-deleted docs via the project_id", ->
 			it "should find the non-deleted docs via the project_id", ->
-				@db.docs.find.lastCall.args.slice(0,1).should.deep.equal([
-					{project_id: ObjectId(@project_id), deleted: {$ne: true}}
-				])
+				@db.docs.find
+					.calledWith({
+						project_id: ObjectId(@project_id)
+						deleted: { $ne: true }
+					}, @filter)
+					.should.equal true
 
 
 			it "should call the callback with the docs", ->
 			it "should call the callback with the docs", ->
 				@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
 				@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
@@ -60,10 +65,11 @@ describe "MongoManager", ->
 				@MongoManager.getProjectsDocs @project_id, include_deleted: true, @filter, @callback
 				@MongoManager.getProjectsDocs @project_id, include_deleted: true, @filter, @callback
 
 
 			it "should find all via the project_id", ->
 			it "should find all via the project_id", ->
-				@db.docs.find.lastCall.args.slice(0,2).should.deep.equal([
-					{project_id: ObjectId(@project_id)},
-					@filter
-				])
+				@db.docs.find
+					.calledWith({
+						project_id: ObjectId(@project_id)
+					}, @filter)
+					.should.equal true
 
 
 			it "should call the callback with the docs", ->
 			it "should call the callback with the docs", ->
 				@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
 				@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
@@ -113,10 +119,9 @@ describe "MongoManager", ->
 				@MongoManager.getDocVersion @doc_id, @callback
 				@MongoManager.getDocVersion @doc_id, @callback
 
 
 			it "should look for the doc in the database", ->
 			it "should look for the doc in the database", ->
-				@db.docOps.find.lastCall.args.slice(0,2).should.deep.equal([
-					{ doc_id: ObjectId(@doc_id) },
-					{version: 1}
-				])
+				@db.docOps.find
+					.calledWith({ doc_id: ObjectId(@doc_id) }, {version: 1})
+					.should.equal true
 
 
 			it "should call the callback with the version", ->
 			it "should call the callback with the version", ->
 				@callback.calledWith(null, @version).should.equal true
 				@callback.calledWith(null, @version).should.equal true
@@ -136,11 +141,16 @@ describe "MongoManager", ->
 			@MongoManager.setDocVersion @doc_id, @version, @callback
 			@MongoManager.setDocVersion @doc_id, @version, @callback
 
 
 		it "should update the doc version", ->
 		it "should update the doc version", ->
-			@db.docOps.update.lastCall.args.slice(0,3).should.deep.equal([
-				{doc_id: ObjectId(@doc_id)},
-				{$set: {version: @version}},
-				{upsert: true}
-			])
+			@db.docOps.update
+				.calledWith({
+					doc_id: ObjectId(@doc_id)
+				}, {
+					$set:
+						version: @version
+				}, {
+					upsert: true 
+				})
+				.should.equal true
 
 
 		it "should call the callback", ->
 		it "should call the callback", ->
 			@callback.called.should.equal true
 			@callback.called.should.equal true