2014-02-12 10:23:40 +00:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
should = require('chai').should()
|
|
|
|
sinon = require 'sinon'
|
|
|
|
assert = require("chai").assert
|
|
|
|
modulePath = "../../../../app/js/Features/Subscription/SubscriptionGroupController"
|
2015-05-28 20:22:49 +00:00
|
|
|
MockResponse = require "../helpers/MockResponse"
|
2014-02-12 10:23:40 +00:00
|
|
|
|
2015-06-01 11:43:42 +00:00
|
|
|
describe "SubscriptionGroupController", ->
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
beforeEach ->
|
2015-05-28 20:22:49 +00:00
|
|
|
@user = {_id:"!@312431",email:"user@email.com"}
|
2016-09-07 15:40:49 +00:00
|
|
|
@adminUserId = "123jlkj"
|
2018-07-11 08:31:57 +00:00
|
|
|
@subscriptionId = "123434325412"
|
2016-09-07 15:40:49 +00:00
|
|
|
@user_email = "bob@gmail.com"
|
|
|
|
@req =
|
|
|
|
session:
|
|
|
|
user:
|
|
|
|
_id: @adminUserId
|
|
|
|
email:@user_email
|
|
|
|
params:
|
2018-07-11 08:31:57 +00:00
|
|
|
subscriptionId:@subscriptionId
|
2016-09-07 15:40:49 +00:00
|
|
|
query:{}
|
2018-07-11 08:31:57 +00:00
|
|
|
@subscription = {
|
|
|
|
_id: @subscriptionId
|
|
|
|
}
|
2016-09-07 15:40:49 +00:00
|
|
|
@GroupHandler =
|
2014-02-12 10:23:40 +00:00
|
|
|
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
|
|
|
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
2015-05-27 19:50:16 +00:00
|
|
|
isUserPartOfGroup: sinon.stub()
|
2015-05-28 20:22:49 +00:00
|
|
|
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
|
2018-07-11 08:31:57 +00:00
|
|
|
@SubscriptionLocator =
|
2018-07-13 10:47:26 +00:00
|
|
|
findManagedSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
2018-07-11 08:31:57 +00:00
|
|
|
|
2016-09-07 15:40:49 +00:00
|
|
|
@AuthenticationController =
|
|
|
|
getLoggedInUserId: (req) -> req.session.user._id
|
|
|
|
getSessionUser: (req) -> req.session.user
|
2014-02-12 10:23:40 +00:00
|
|
|
|
2016-09-07 15:40:49 +00:00
|
|
|
@SubscriptionDomainHandler =
|
2015-05-27 19:50:16 +00:00
|
|
|
findDomainLicenceBySubscriptionId:sinon.stub()
|
|
|
|
|
|
|
|
@OneTimeTokenHandler =
|
|
|
|
getValueFromTokenAndExpire:sinon.stub()
|
|
|
|
|
|
|
|
|
2016-09-07 15:40:49 +00:00
|
|
|
@ErrorsController =
|
2015-05-27 19:50:16 +00:00
|
|
|
notFound:sinon.stub()
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
@Controller = SandboxedModule.require modulePath, requires:
|
|
|
|
"./SubscriptionGroupHandler":@GroupHandler
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
"./SubscriptionLocator": @SubscriptionLocator
|
2015-05-27 19:57:54 +00:00
|
|
|
"./SubscriptionDomainHandler":@SubscriptionDomainHandler
|
2015-05-27 19:50:16 +00:00
|
|
|
"../Errors/ErrorController":@ErrorsController
|
2016-09-07 15:40:49 +00:00
|
|
|
'../Authentication/AuthenticationController': @AuthenticationController
|
2015-05-27 19:50:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@token = "super-secret-token"
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe "addUserToGroup", ->
|
|
|
|
|
2018-07-11 08:31:57 +00:00
|
|
|
it "should use the subscription id for the logged in user and take the email address from the body", (done)->
|
2016-02-25 14:15:56 +00:00
|
|
|
newEmail = " boB@gmaiL.com "
|
2014-02-12 10:23:40 +00:00
|
|
|
@req.body = email: newEmail
|
|
|
|
res =
|
|
|
|
json : (data)=>
|
2018-07-11 08:31:57 +00:00
|
|
|
@GroupHandler.addUserToGroup.calledWith(@subscriptionId, "bob@gmail.com").should.equal true
|
2014-02-12 10:23:40 +00:00
|
|
|
data.user.should.deep.equal @user
|
|
|
|
done()
|
|
|
|
@Controller.addUserToGroup @req, res
|
|
|
|
|
|
|
|
|
|
|
|
describe "removeUserFromGroup", ->
|
2018-07-11 08:31:57 +00:00
|
|
|
it "should use the subscription id for the logged in user and take the user id from the params", (done)->
|
2014-02-12 10:23:40 +00:00
|
|
|
userIdToRemove = "31231"
|
|
|
|
@req.params = user_id: userIdToRemove
|
|
|
|
|
|
|
|
res =
|
|
|
|
send : =>
|
2018-07-11 08:31:57 +00:00
|
|
|
@GroupHandler.removeUserFromGroup.calledWith(@subscriptionId, userIdToRemove).should.equal true
|
2014-02-12 10:23:40 +00:00
|
|
|
done()
|
|
|
|
@Controller.removeUserFromGroup @req, res
|
|
|
|
|
2016-09-07 15:40:49 +00:00
|
|
|
describe "renderSubscriptionGroupAdminPage", ->
|
2014-02-12 10:23:40 +00:00
|
|
|
it "should redirect you if you don't have a group account", (done)->
|
2015-05-28 20:22:49 +00:00
|
|
|
@subscription.groupPlan = false
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
res =
|
|
|
|
redirect : (path)=>
|
2017-06-22 13:07:07 +00:00
|
|
|
path.should.equal("/user/subscription")
|
|
|
|
done()
|
|
|
|
@Controller.renderSubscriptionGroupAdminPage @req, res
|
|
|
|
|
|
|
|
it "should redirect you don't have a subscription", (done)->
|
|
|
|
@SubscriptionLocator.getUsersSubscription = sinon.stub().callsArgWith(1)
|
|
|
|
|
|
|
|
res =
|
|
|
|
redirect : (path)=>
|
|
|
|
path.should.equal("/user/subscription")
|
2014-02-12 10:23:40 +00:00
|
|
|
done()
|
|
|
|
@Controller.renderSubscriptionGroupAdminPage @req, res
|
2015-05-27 19:50:16 +00:00
|
|
|
|
2016-09-07 15:40:49 +00:00
|
|
|
describe "exportGroupCsv", ->
|
2015-05-28 20:22:49 +00:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@subscription.groupPlan = true
|
|
|
|
@res = new MockResponse()
|
|
|
|
@res.contentType = sinon.stub()
|
|
|
|
@res.header = sinon.stub()
|
|
|
|
@res.send = sinon.stub()
|
|
|
|
@Controller.exportGroupCsv @req, @res
|
|
|
|
|
|
|
|
it "should set the correct content type on the request", ->
|
|
|
|
@res.contentType
|
|
|
|
.calledWith("text/csv")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should name the exported csv file", ->
|
|
|
|
@res.header
|
|
|
|
.calledWith(
|
|
|
|
"Content-Disposition",
|
|
|
|
"attachment; filename=Group.csv")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should export the correct csv", ->
|
|
|
|
@res.send
|
|
|
|
.calledWith("user@email.com\n")
|
|
|
|
.should.equal true
|