mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 10:20:59 +00:00
58 lines
No EOL
2.2 KiB
CoffeeScript
58 lines
No EOL
2.2 KiB
CoffeeScript
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"
|
|
expect = require("chai").expect
|
|
|
|
describe "SubscriptionDomainHandler", ->
|
|
|
|
beforeEach ->
|
|
|
|
@adminUser_id = 12345
|
|
@settings =
|
|
domainLicences: [
|
|
{domains:["highcools.site"], adminUser_id:"not this one"}
|
|
{domains:["uni.edu", "student.uni.edu"], adminUser_id:@adminUser_id}
|
|
]
|
|
@SubscriptionGroupHandler =
|
|
addUserToGroup: sinon.stub().callsArg(2)
|
|
@SubscriptionDomainHandler = SandboxedModule.require modulePath, requires:
|
|
"settings-sharelatex":@settings
|
|
"logger-sharelatex": log:->
|
|
"./SubscriptionGroupHandler": @SubscriptionGroupHandler
|
|
|
|
describe "_findDomainLicence", ->
|
|
|
|
it "should find the domain", (done)->
|
|
licence = @SubscriptionDomainHandler._findDomainLicence "bob@uni.edu"
|
|
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
|
|
done()
|
|
|
|
it "should return undefined if no licence matches", (done)->
|
|
licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu"
|
|
expect(licence).to.not.exist
|
|
done(licence)
|
|
|
|
describe "autoAllocate", ->
|
|
beforeEach ->
|
|
@email = "bob@somewhere.com"
|
|
@SubscriptionDomainHandler._findDomainLicence = sinon.stub()
|
|
|
|
it "should call the SubscriptionGroupHandler if there is licence", (done)->
|
|
@SubscriptionDomainHandler._findDomainLicence.returns(@settings.domainLicences[1])
|
|
@SubscriptionDomainHandler.autoAllocate {email:@email}, (err)=>
|
|
@SubscriptionGroupHandler.addUserToGroup.calledWith(@adminUser_id, @email).should.equal true
|
|
done()
|
|
|
|
it "should not call the SubscriptionGroupHandler if there is no licence", (done)->
|
|
@SubscriptionDomainHandler._findDomainLicence.returns()
|
|
@SubscriptionDomainHandler.autoAllocate {email:@email}, (err)=>
|
|
@SubscriptionGroupHandler.addUserToGroup.called.should.equal false
|
|
done() |