Ver código fonte

In _summarizeUpdates, allow null users through.

A null value represents a deleted or otherwise missing user record.
Shane Kilkelly 11 anos atrás
pai
commit
8387383cb4

+ 8 - 13
services/track-changes/app/coffee/UpdatesManager.coffee

@@ -188,14 +188,13 @@ module.exports = UpdatesManager =
 		for update in updates
 			earliestUpdate = summarizedUpdates[summarizedUpdates.length - 1]
 			if earliestUpdate and earliestUpdate.meta.start_ts - update.meta.end_ts < @TIME_BETWEEN_DISTINCT_UPDATES
-				if update.meta.user?
-					userExists = false
-					for user in earliestUpdate.meta.users
-						if user.id == update.meta.user.id
-							userExists = true
-							break
-					if !userExists
-						earliestUpdate.meta.users.push update.meta.user
+				userExists = false
+				for user in earliestUpdate.meta.users
+					if (!user and !update.meta.user) or (user.id == update.meta.user?.id)
+						userExists = true
+						break
+				if !userExists
+					earliestUpdate.meta.users.push update.meta.user
 
 				doc_id = update.doc_id.toString()
 				doc = earliestUpdate.docs[doc_id]
@@ -220,11 +219,7 @@ module.exports = UpdatesManager =
 				newUpdate.docs[update.doc_id.toString()] =
 					fromV: update.v
 					toV: update.v
-
-				if update.meta.user?
-					newUpdate.meta.users.push update.meta.user
-
+				newUpdate.meta.users.push update.meta.user
 				summarizedUpdates.push newUpdate
 
 		return summarizedUpdates
-

+ 61 - 0
services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee

@@ -627,3 +627,64 @@ describe "UpdatesManager", ->
 					start_ts: @now
 					end_ts:   @now + 50
 			}]
+
+		it "should include null user values", ->
+			result = @UpdatesManager._summarizeUpdates [{
+				doc_id: "doc-id-1"
+				meta:
+					user: @user_1
+					start_ts: @now + 20
+					end_ts:   @now + 30
+				v: 5
+			}, {
+				doc_id: "doc-id-1"
+				meta:
+					user: null
+					start_ts: @now
+					end_ts:   @now + 10
+				v: 4
+			}]
+			expect(result).to.deep.equal [{
+				docs:
+					"doc-id-1":
+						fromV: 4
+						toV: 5
+				meta:
+					users: [@user_1, null]
+					start_ts: @now
+					end_ts:   @now + 30
+			}]
+
+		it "should roll several null user values into one", ->
+			result = @UpdatesManager._summarizeUpdates [{
+				doc_id: "doc-id-1"
+				meta:
+					user: @user_1
+					start_ts: @now + 20
+					end_ts:   @now + 30
+				v: 5
+			}, {
+				doc_id: "doc-id-1"
+				meta:
+					user: null
+					start_ts: @now
+					end_ts:   @now + 10
+				v: 4
+			}, {
+				doc_id: "doc-id-1"
+				meta:
+					user: null
+					start_ts: @now + 2
+					end_ts:   @now + 4
+				v: 4
+			}]
+			expect(result).to.deep.equal [{
+				docs:
+					"doc-id-1":
+						fromV: 4
+						toV: 5
+				meta:
+					users: [@user_1, null]
+					start_ts: @now
+					end_ts:   @now + 30
+			}]