2016-02-18 05:06:21 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/Features/User/UserHandler.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "UserHandler", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2018-06-01 06:28:06 -04:00
|
|
|
@user =
|
2016-02-18 05:06:21 -05:00
|
|
|
_id:"12390i"
|
|
|
|
email: "bob@bob.com"
|
|
|
|
remove: sinon.stub().callsArgWith(0)
|
|
|
|
|
2018-06-01 06:28:06 -04:00
|
|
|
@licence =
|
2016-02-18 05:06:21 -05:00
|
|
|
subscription_id: 12323434
|
|
|
|
@SubscriptionDomainHandler =
|
|
|
|
getLicenceUserCanJoin: sinon.stub()
|
|
|
|
|
|
|
|
@SubscriptionGroupHandler =
|
|
|
|
isUserPartOfGroup:sinon.stub()
|
|
|
|
@createStub = sinon.stub().callsArgWith(0)
|
2018-06-01 06:28:06 -04:00
|
|
|
@NotificationsBuilder =
|
2016-02-18 05:06:21 -05:00
|
|
|
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
|
|
|
|
|
2018-06-01 06:28:06 -04:00
|
|
|
describe "notifyDomainLicence", ->
|
2016-02-18 05:06:21 -05:00
|
|
|
describe "no licence", ->
|
|
|
|
beforeEach (done)->
|
|
|
|
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
|
2018-06-01 06:28:06 -04:00
|
|
|
@UserHandler.notifyDomainLicence @user, done
|
2016-02-18 05:06:21 -05:00
|
|
|
|
|
|
|
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)
|
2018-06-01 06:28:06 -04:00
|
|
|
@UserHandler.notifyDomainLicence @user, done
|
2016-02-18 05:06:21 -05:00
|
|
|
|
|
|
|
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)
|
2018-06-01 06:28:06 -04:00
|
|
|
@UserHandler.notifyDomainLicence @user, done
|
2016-02-18 05:06:21 -05:00
|
|
|
|
|
|
|
it "should create notifcation", (done)->
|
|
|
|
@NotificationsBuilder.groupPlan.called.should.equal false
|
2017-06-08 07:12:08 -04:00
|
|
|
done()
|