|
|
@@ -7,21 +7,20 @@ SandboxedModule = require('sandboxed-module')
|
|
|
describe "UserHandler", ->
|
|
|
|
|
|
beforeEach ->
|
|
|
- @user =
|
|
|
+ @user =
|
|
|
_id:"12390i"
|
|
|
email: "bob@bob.com"
|
|
|
remove: sinon.stub().callsArgWith(0)
|
|
|
|
|
|
- @licence =
|
|
|
+ @licence =
|
|
|
subscription_id: 12323434
|
|
|
@SubscriptionDomainHandler =
|
|
|
getLicenceUserCanJoin: sinon.stub()
|
|
|
|
|
|
@SubscriptionGroupHandler =
|
|
|
isUserPartOfGroup:sinon.stub()
|
|
|
- convertEmailInvitesToMemberships: sinon.stub().callsArgWith(2)
|
|
|
@createStub = sinon.stub().callsArgWith(0)
|
|
|
- @NotificationsBuilder =
|
|
|
+ @NotificationsBuilder =
|
|
|
groupPlan:sinon.stub().returns({create:@createStub})
|
|
|
|
|
|
@UserHandler = SandboxedModule.require modulePath, requires:
|
|
|
@@ -30,16 +29,11 @@ describe "UserHandler", ->
|
|
|
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
|
|
|
"../Subscription/SubscriptionGroupHandler":@SubscriptionGroupHandler
|
|
|
|
|
|
- describe "populateGroupLicenceInvite", ->
|
|
|
+ describe "notifyDomainLicence", ->
|
|
|
describe "no licence", ->
|
|
|
beforeEach (done)->
|
|
|
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
|
|
|
- @UserHandler.populateGroupLicenceInvite @user, done
|
|
|
-
|
|
|
- it "should call convertEmailInvitesToMemberships", ->
|
|
|
- @SubscriptionGroupHandler.convertEmailInvitesToMemberships
|
|
|
- .calledWith(@user.email, @user._id)
|
|
|
- .should.equal true
|
|
|
+ @UserHandler.notifyDomainLicence @user, done
|
|
|
|
|
|
it "should not call NotificationsBuilder", (done)->
|
|
|
@NotificationsBuilder.groupPlan.called.should.equal false
|
|
|
@@ -53,28 +47,18 @@ describe "UserHandler", ->
|
|
|
beforeEach (done)->
|
|
|
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
|
|
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
|
|
|
- @UserHandler.populateGroupLicenceInvite @user, done
|
|
|
+ @UserHandler.notifyDomainLicence @user, done
|
|
|
|
|
|
it "should create notifcation", (done)->
|
|
|
@NotificationsBuilder.groupPlan.calledWith(@user, @licence).should.equal true
|
|
|
done()
|
|
|
-
|
|
|
- it "should call convertEmailInvitesToMemberships", ->
|
|
|
- @SubscriptionGroupHandler.convertEmailInvitesToMemberships
|
|
|
- .calledWith(@user.email, @user._id)
|
|
|
- .should.equal true
|
|
|
|
|
|
describe "with matching licence user is already in", ->
|
|
|
beforeEach (done)->
|
|
|
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
|
|
|
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
|
|
|
- @UserHandler.populateGroupLicenceInvite @user, done
|
|
|
+ @UserHandler.notifyDomainLicence @user, done
|
|
|
|
|
|
it "should create notifcation", (done)->
|
|
|
@NotificationsBuilder.groupPlan.called.should.equal false
|
|
|
done()
|
|
|
-
|
|
|
- it "should call convertEmailInvitesToMemberships", ->
|
|
|
- @SubscriptionGroupHandler.convertEmailInvitesToMemberships
|
|
|
- .calledWith(@user.email, @user._id)
|
|
|
- .should.equal true
|