2014-02-12 05:23:40 -05: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 16:22:49 -04:00
|
|
|
MockResponse = require "../helpers/MockResponse"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-01 07:43:42 -04:00
|
|
|
describe "SubscriptionGroupController", ->
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
beforeEach ->
|
2015-05-28 16:22:49 -04:00
|
|
|
@user = {_id:"!@312431",email:"user@email.com"}
|
2016-09-07 11:40:49 -04:00
|
|
|
@adminUserId = "123jlkj"
|
2018-07-11 04:31:57 -04:00
|
|
|
@subscriptionId = "123434325412"
|
2016-09-07 11:40:49 -04:00
|
|
|
@user_email = "bob@gmail.com"
|
|
|
|
@req =
|
|
|
|
session:
|
|
|
|
user:
|
|
|
|
_id: @adminUserId
|
|
|
|
email:@user_email
|
|
|
|
params:
|
2018-07-11 04:31:57 -04:00
|
|
|
subscriptionId:@subscriptionId
|
2016-09-07 11:40:49 -04:00
|
|
|
query:{}
|
2018-10-25 11:10:02 -04:00
|
|
|
|
2018-07-11 04:31:57 -04:00
|
|
|
@subscription = {
|
|
|
|
_id: @subscriptionId
|
|
|
|
}
|
2018-10-25 11:10:02 -04:00
|
|
|
|
2016-09-07 11:40:49 -04:00
|
|
|
@GroupHandler =
|
2014-02-12 05:23:40 -05:00
|
|
|
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
2018-10-25 11:10:02 -04:00
|
|
|
|
2018-07-11 04:31:57 -04:00
|
|
|
@SubscriptionLocator =
|
2018-07-13 06:47:26 -04:00
|
|
|
findManagedSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
2018-07-11 04:31:57 -04:00
|
|
|
|
2016-09-07 11:40:49 -04:00
|
|
|
@AuthenticationController =
|
|
|
|
getLoggedInUserId: (req) -> req.session.user._id
|
|
|
|
getSessionUser: (req) -> req.session.user
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@Controller = SandboxedModule.require modulePath, requires:
|
|
|
|
"./SubscriptionGroupHandler":@GroupHandler
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
"./SubscriptionLocator": @SubscriptionLocator
|
2016-09-07 11:40:49 -04:00
|
|
|
'../Authentication/AuthenticationController': @AuthenticationController
|
2015-05-27 15:50:16 -04:00
|
|
|
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe "removeUserFromGroup", ->
|
2018-07-11 04:31:57 -04:00
|
|
|
it "should use the subscription id for the logged in user and take the user id from the params", (done)->
|
2014-02-12 05:23:40 -05:00
|
|
|
userIdToRemove = "31231"
|
|
|
|
@req.params = user_id: userIdToRemove
|
2018-10-25 11:10:02 -04:00
|
|
|
@req.entity = @subscription
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
res =
|
|
|
|
send : =>
|
2018-07-11 04:31:57 -04:00
|
|
|
@GroupHandler.removeUserFromGroup.calledWith(@subscriptionId, userIdToRemove).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
@Controller.removeUserFromGroup @req, res
|