mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
don't create notification if user is already part of group
This commit is contained in:
parent
c8084406d3
commit
fc4bd94a6e
3 changed files with 84 additions and 7 deletions
|
@ -22,4 +22,4 @@ module.exports =
|
|||
Subscription.findOne _id:subscription_id, callback
|
||||
|
||||
getSubscriptionByMemberIdAndId: (user_id, subscription_id, callback)->
|
||||
Subscription.findOne member_ids: user_id, _id:subscription_id, callback
|
||||
Subscription.findOne member_ids: user_id, _id:subscription_id, {_id:1}, callback
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler")
|
||||
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
||||
SubscriptionGroupHandler = require("../Subscription/SubscriptionGroupHandler")
|
||||
|
||||
module.exports = UserHandler =
|
||||
|
||||
module.exports =
|
||||
_populateGroupLicenceInvite: (user, callback)->
|
||||
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
||||
if !licence?
|
||||
return callback()
|
||||
|
||||
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
|
||||
if err? or alreadyPartOfGroup
|
||||
return callback(err)
|
||||
else
|
||||
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
||||
|
||||
setupLoginData: (user, callback = ->)->
|
||||
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
|
||||
if licence?
|
||||
NotificationsBuilder.groupPlan(user, licence).create(callback)
|
||||
else
|
||||
return callback()
|
||||
_populateGroupLicenceInvite user, callback
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
modulePath = "../../../../app/js/Features/User/UserHandler.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe "UserHandler", ->
|
||||
|
||||
beforeEach ->
|
||||
@user =
|
||||
_id:"12390i"
|
||||
email: "bob@bob.com"
|
||||
remove: sinon.stub().callsArgWith(0)
|
||||
|
||||
@licence =
|
||||
subscription_id: 12323434
|
||||
@SubscriptionDomainHandler =
|
||||
getLicenceUserCanJoin: sinon.stub()
|
||||
|
||||
@SubscriptionGroupHandler =
|
||||
isUserPartOfGroup:sinon.stub()
|
||||
@createStub = sinon.stub().callsArgWith(0)
|
||||
@NotificationsBuilder =
|
||||
groupPlan:sinon.stub().returns({create:@createStub})
|
||||
|
||||
@UserHandler = SandboxedModule.require modulePath, requires:
|
||||
"logger-sharelatex": @logger = { log: sinon.stub() }
|
||||
"../Notifications/NotificationsBuilder":@NotificationsBuilder
|
||||
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
|
||||
"../Subscription/SubscriptionGroupHandler":@SubscriptionGroupHandler
|
||||
|
||||
describe "_populateGroupLicenceInvite", ->
|
||||
|
||||
describe "no licence", ->
|
||||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
|
||||
@UserHandler._populateGroupLicenceInvite @user, done
|
||||
|
||||
it "should not call NotificationsBuilder", (done)->
|
||||
@NotificationsBuilder.groupPlan.called.should.equal false
|
||||
done()
|
||||
|
||||
it "should not call isUserPartOfGroup", (done)->
|
||||
@SubscriptionGroupHandler.isUserPartOfGroup.called.should.equal false
|
||||
done()
|
||||
|
||||
describe "with matching licence user is not in", ->
|
||||
|
||||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
||||
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
|
||||
@UserHandler._populateGroupLicenceInvite @user, done
|
||||
|
||||
it "should create notifcation", (done)->
|
||||
@NotificationsBuilder.groupPlan.calledWith(@user, @licence).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
|
||||
describe "with matching licence user is already in", ->
|
||||
|
||||
beforeEach (done)->
|
||||
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
||||
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
|
||||
@UserHandler._populateGroupLicenceInvite @user, done
|
||||
|
||||
it "should create notifcation", (done)->
|
||||
@NotificationsBuilder.groupPlan.called.should.equal false
|
||||
done()
|
Loading…
Reference in a new issue