SubscriptionDomainHandlerTests.coffee 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. sinon = require('sinon')
  6. modulePath = path.join __dirname, "../../../../app/js/Features/Subscription/SubscriptionDomainHandler"
  7. expect = require("chai").expect
  8. describe "SubscriptionDomainHandler", ->
  9. beforeEach ->
  10. @adminUser_id = 12345
  11. @otherAdminUser_id = 32131231234
  12. @ThirdOtherAdminUser_id = 33424324
  13. @settings =
  14. domainLicences: [
  15. {domains:["uni.edu", "student.uni.edu"], adminUser_id:@adminUser_id}
  16. {domains:["student.myuni.com", "teacher.myuni.com"], adminUser_id:@otherAdminUser_id}
  17. {domains:["highcools.site"], adminUser_id:@ThirdOtherAdminUser_id}
  18. ]
  19. @SubscriptionGroupHandler =
  20. addUserToGroup: sinon.stub().callsArg(2)
  21. @SubscriptionDomainHandler = SandboxedModule.require modulePath, requires:
  22. "settings-sharelatex":@settings
  23. "logger-sharelatex": log:->
  24. "./SubscriptionGroupHandler": @SubscriptionGroupHandler
  25. describe "_findDomainLicence", ->
  26. it "should find the domain", (done)->
  27. licence = @SubscriptionDomainHandler._findDomainLicence "bob@uni.edu"
  28. licence.adminUser_id.should.equal @adminUser_id
  29. done()
  30. it "should find the if email is subdomain", (done)->
  31. licence = @SubscriptionDomainHandler._findDomainLicence "bob@somewherelse.highcools.site"
  32. licence.adminUser_id.should.equal @ThirdOtherAdminUser_id
  33. done()
  34. it "should find one of the other emails in the domain list", (done)->
  35. licence = @SubscriptionDomainHandler._findDomainLicence "sally@teacher.myuni.com"
  36. licence.adminUser_id.should.equal @otherAdminUser_id
  37. done()
  38. it "should return undefined if no licence matches even if end of email is same", (done)->
  39. licence = @SubscriptionDomainHandler._findDomainLicence "bob@someotherhighcools.site"
  40. expect(licence).to.not.exist
  41. done(licence)
  42. it "should return undefined if no licence matches", (done)->
  43. licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu"
  44. expect(licence).to.not.exist
  45. done(licence)