Alberto Fernández Capel vor 8 Jahren
Ursprung
Commit
18ded60619

+ 1 - 1
services/web/app/coffee/Features/User/UserGetter.coffee

@@ -62,7 +62,7 @@ module.exports = UserGetter =
 			user_ids = user_ids.map (u) -> ObjectId(u.toString())
 		catch error
 			return callback error
-
+		
 		db.users.find { _id: { $in: user_ids} }, projection, callback
 
 	getUserOrUserStubById: (user_id, projection, callback = (error, user) ->) ->

+ 12 - 11
services/web/test/unit/coffee/Referal/ReferalFeaturesTests.coffee

@@ -8,7 +8,7 @@ describe 'ReferalFeatures', ->
 
 	beforeEach ->
 		@ReferalFeatures = SandboxedModule.require modulePath, requires:
-			'../User/UserGetter': @UserGetter = {}
+			'../../models/User': User: @User = {}
 			"settings-sharelatex": @Settings = {}
 			'logger-sharelatex':
 				log:->
@@ -27,17 +27,17 @@ describe 'ReferalFeatures', ->
 						collaborators: 3
 						dropbox: false
 						versioning: false
-				stubbedUser = {
-					refered_user_count: @refered_user_count,
-					features:{collaborators:1, dropbox:false, versioning:false}
+				stubbedUser = { 
+					refered_user_count: @refered_user_count, 
+					features:{collaborators:1, dropbox:false, versioning:false} 
 				}
 
-				@UserGetter.getUserOrUserStubById = sinon.stub().yields null, stubbedUser
+				@User.findOne = sinon.stub().callsArgWith 1, null, stubbedUser
 				@ReferalFeatures.getBonusFeatures @user_id, @callback
 
 			it "should get the users number of refered user", ->
-				@UserGetter.getUserOrUserStubById
-					.calledWith(@user_id, null)
+				@User.findOne
+					.calledWith(_id: @user_id)
 					.should.equal true
 
 			it "should call the callback with the features", ->
@@ -51,14 +51,15 @@ describe 'ReferalFeatures', ->
 						collaborators: 3
 						dropbox: false
 						versioning: false
-				@UserGetter.getUserOrUserStubById =
-					sinon.stub().yields null, { refered_user_count: @refered_user_count }
+				@User.findOne = sinon.stub().callsArgWith 1, null, { refered_user_count: @refered_user_count }
 				@ReferalFeatures.getBonusFeatures @user_id, @callback
 
 			it "should get the users number of refered user", ->
-				@UserGetter.getUserOrUserStubById
-					.calledWith(@user_id, null)
+				@User.findOne
+					.calledWith(_id: @user_id)
 					.should.equal true
 
 			it "should call the callback with no features", ->
 				@callback.calledWith(null, {}).should.equal true
+
+

+ 18 - 6
services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee

@@ -58,6 +58,11 @@ describe "SubscriptionUpdater", ->
 		@PlansLocator =
 			findLocalPlanInSettings: sinon.stub().returns({})
 
+		@UserGetter =
+			getUsers: (memberIds, projection, callback) ->
+				users = memberIds.map (id) -> { _id: id }
+				callback(null, users)
+
 		@ReferalFeatures = getBonusFeatures: sinon.stub().callsArgWith(1)
 		@Modules = {hooks: {fire: sinon.stub().callsArgWith(2, null, null)}}
 		@SubscriptionUpdater = SandboxedModule.require modulePath, requires:
@@ -74,7 +79,6 @@ describe "SubscriptionUpdater", ->
 	describe "syncSubscription", ->
 
 		beforeEach ->
-
 			@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
 			@SubscriptionUpdater._updateSubscriptionFromRecurly = sinon.stub().callsArgWith(2)
 
@@ -88,7 +92,6 @@ describe "SubscriptionUpdater", ->
 				done()
 
 		it "should not call updateFeatures with group subscription if recurly subscription is not expired", (done)->
-
 			@SubscriptionUpdater.syncSubscription @recurlySubscription, @adminUser._id, (err)=>
 				@SubscriptionLocator.getUsersSubscription.calledWith(@adminUser._id).should.equal true
 				@SubscriptionUpdater._updateSubscriptionFromRecurly.called.should.equal true
@@ -144,7 +147,6 @@ describe "SubscriptionUpdater", ->
 				done()
 
 
-
 	describe "_createNewSubscription", ->
 		it "should create a new subscription then update the subscription", (done)->
 			@SubscriptionUpdater._createNewSubscription @adminUser._id, =>
@@ -155,14 +157,24 @@ describe "SubscriptionUpdater", ->
 
 	describe "addUserToGroup", ->
 		beforeEach ->
-			@FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
+			@SubscriptionUpdater.addUsersToGroup = sinon.stub().yields(null)
 
-		it "should add the users id to the group as a set", (done)->
+		it "delegates to addUsersToGroup", (done)->
 			@SubscriptionUpdater.addUserToGroup @adminUser._id, @otherUserId, =>
+				@SubscriptionUpdater.addUsersToGroup
+					.calledWith(@adminUser._id, [@otherUserId]).should.equal true
+				done()
+
+	describe "addUsersToGroup", ->
+		beforeEach ->
+			@FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
+
+		it "should add the user ids to the group as a set", (done)->
+			@SubscriptionUpdater.addUsersToGroup @adminUser._id, [@otherUserId], =>
 				searchOps =
 					admin_id: @adminUser._id
 				insertOperation =
-					"$addToSet": {member_ids:@otherUserId}
+					{ $push: { member_ids: { $each: [@otherUserId] } } }
 				@findAndModifyStub.calledWith(searchOps, insertOperation).should.equal true
 				done()