diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee index b57c3492f6..9e5d210d7e 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee @@ -45,7 +45,8 @@ module.exports = SubscriptionDomainHandler = _findDomainLicence: (email)-> licence = _.find settings.domainLicences, (licence)-> _.find licence.domains, (domain)-> - _s.endsWith email, domain + regex = "[@\.]#{domain}" + return email.match(regex) return licence diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee index 82c94d352c..acf99e2d3d 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee @@ -11,10 +11,14 @@ describe "SubscriptionDomainHandler", -> beforeEach -> @adminUser_id = 12345 + @otherAdminUser_id = 32131231234 + @ThirdOtherAdminUser_id = 33424324 @settings = domainLicences: [ - {domains:["highcools.site"], adminUser_id:"not this one"} {domains:["uni.edu", "student.uni.edu"], adminUser_id:@adminUser_id} + {domains:["student.myuni.com", "teacher.myuni.com"], adminUser_id:@otherAdminUser_id} + {domains:["highcools.site"], adminUser_id:@ThirdOtherAdminUser_id} + ] @SubscriptionGroupHandler = addUserToGroup: sinon.stub().callsArg(2) @@ -30,11 +34,21 @@ describe "SubscriptionDomainHandler", -> licence.adminUser_id.should.equal @adminUser_id done() - it "should find one of the other emails in the domain list", (done)-> - licence = @SubscriptionDomainHandler._findDomainLicence "sally@student.uni.edu" - licence.adminUser_id.should.equal @adminUser_id + it "should find the if email is subdomain", (done)-> + licence = @SubscriptionDomainHandler._findDomainLicence "bob@somewherelse.highcools.site" + licence.adminUser_id.should.equal @ThirdOtherAdminUser_id done() + it "should find one of the other emails in the domain list", (done)-> + licence = @SubscriptionDomainHandler._findDomainLicence "sally@teacher.myuni.com" + licence.adminUser_id.should.equal @otherAdminUser_id + done() + + it "should return undefined if no licence matches even if end of email is same", (done)-> + licence = @SubscriptionDomainHandler._findDomainLicence "bob@someotherhighcools.site" + expect(licence).to.not.exist + done(licence) + it "should return undefined if no licence matches", (done)-> licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu" expect(licence).to.not.exist @@ -46,7 +60,7 @@ describe "SubscriptionDomainHandler", -> @SubscriptionDomainHandler._findDomainLicence = sinon.stub() it "should call the SubscriptionGroupHandler if there is licence", (done)-> - @SubscriptionDomainHandler._findDomainLicence.returns(@settings.domainLicences[1]) + @SubscriptionDomainHandler._findDomainLicence.returns(@settings.domainLicences[0]) @SubscriptionDomainHandler.autoAllocate {email:@email}, (err)=> @SubscriptionGroupHandler.addUserToGroup.calledWith(@adminUser_id, @email).should.equal true done()