overleaf/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee

57 lines
2 KiB
CoffeeScript
Raw Normal View History

2015-01-27 13:09:56 -05:00
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/Subscription/SubscriptionDomainHandler"
2015-01-27 13:09:56 -05:00
expect = require("chai").expect
describe "SubscriptionDomainHandler", ->
2015-01-27 13:09:56 -05:00
beforeEach ->
@adminUser_id = 12345
2016-02-03 11:07:44 -05:00
@otherAdminUser_id = 32131231234
@ThirdOtherAdminUser_id = 33424324
2015-01-27 13:09:56 -05:00
@settings =
domainLicences: [
{domains:["uni.edu", "student.uni.edu"], adminUser_id:@adminUser_id}
2016-02-03 11:07:44 -05:00
{domains:["student.myuni.com", "teacher.myuni.com"], adminUser_id:@otherAdminUser_id}
{domains:["highcools.site"], adminUser_id:@ThirdOtherAdminUser_id}
2015-01-27 13:09:56 -05:00
]
@SubscriptionGroupHandler =
addUserToGroup: sinon.stub().callsArg(2)
@SubscriptionDomainHandler = SandboxedModule.require modulePath, requires:
2015-01-27 13:09:56 -05:00
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"./SubscriptionGroupHandler": @SubscriptionGroupHandler
describe "_findDomainLicence", ->
it "should find the domain", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@uni.edu"
2015-01-27 13:09:56 -05:00
licence.adminUser_id.should.equal @adminUser_id
done()
2016-02-03 11:07:44 -05:00
it "should find the if email is subdomain", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@somewherelse.highcools.site"
licence.adminUser_id.should.equal @ThirdOtherAdminUser_id
done()
2015-01-27 13:09:56 -05:00
it "should find one of the other emails in the domain list", (done)->
2016-02-03 11:07:44 -05:00
licence = @SubscriptionDomainHandler._findDomainLicence "sally@teacher.myuni.com"
licence.adminUser_id.should.equal @otherAdminUser_id
2015-01-27 13:09:56 -05:00
done()
2016-02-03 11:07:44 -05:00
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)
2015-01-27 13:09:56 -05:00
it "should return undefined if no licence matches", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu"
2015-01-27 13:09:56 -05:00
expect(licence).to.not.exist
done(licence)