2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const should = require('chai').should()
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const { assert } = require('chai')
|
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Subscription/SubscriptionGroupController'
|
|
|
|
const MockResponse = require('../helpers/MockResponse')
|
|
|
|
|
|
|
|
describe('SubscriptionGroupController', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.user = { _id: '!@312431', email: 'user@email.com' }
|
|
|
|
this.adminUserId = '123jlkj'
|
|
|
|
this.subscriptionId = '123434325412'
|
|
|
|
this.user_email = 'bob@gmail.com'
|
|
|
|
this.req = {
|
|
|
|
session: {
|
|
|
|
user: {
|
|
|
|
_id: this.adminUserId,
|
|
|
|
email: this.user_email
|
|
|
|
}
|
|
|
|
},
|
|
|
|
params: {
|
|
|
|
subscriptionId: this.subscriptionId
|
|
|
|
},
|
|
|
|
query: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.subscription = {
|
|
|
|
_id: this.subscriptionId
|
|
|
|
}
|
|
|
|
|
|
|
|
this.GroupHandler = { removeUserFromGroup: sinon.stub().callsArgWith(2) }
|
|
|
|
|
|
|
|
this.SubscriptionLocator = {
|
2020-08-12 10:17:15 -04:00
|
|
|
getSubscription: sinon.stub().callsArgWith(1, null, this.subscription)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.AuthenticationController = {
|
|
|
|
getLoggedInUserId(req) {
|
|
|
|
return req.session.user._id
|
|
|
|
},
|
|
|
|
getSessionUser(req) {
|
|
|
|
return req.session.user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (this.Controller = SandboxedModule.require(modulePath, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'./SubscriptionGroupHandler': this.GroupHandler,
|
|
|
|
'logger-sharelatex': {
|
|
|
|
log() {}
|
|
|
|
},
|
|
|
|
'./SubscriptionLocator': this.SubscriptionLocator,
|
|
|
|
'../Authentication/AuthenticationController': this
|
|
|
|
.AuthenticationController
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
describe('removeUserFromGroup', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
it('should use the subscription id for the logged in user and take the user id from the params', function(done) {
|
|
|
|
const userIdToRemove = '31231'
|
|
|
|
this.req.params = { user_id: userIdToRemove }
|
|
|
|
this.req.entity = this.subscription
|
|
|
|
|
|
|
|
const res = {
|
2020-05-06 06:02:16 -04:00
|
|
|
sendStatus: () => {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.GroupHandler.removeUserFromGroup
|
|
|
|
.calledWith(this.subscriptionId, userIdToRemove)
|
|
|
|
.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.Controller.removeUserFromGroup(this.req, res)
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2020-08-12 10:17:15 -04:00
|
|
|
|
|
|
|
describe('removeSelfFromGroup', function() {
|
|
|
|
it('gets subscription and remove user', function(done) {
|
|
|
|
const userIdToRemove = '31231'
|
|
|
|
this.req.query = { subscriptionId: this.subscriptionId }
|
|
|
|
const memberUserIdToremove = 123456789
|
|
|
|
this.req.session.user._id = memberUserIdToremove
|
|
|
|
|
|
|
|
const res = {
|
|
|
|
sendStatus: () => {
|
|
|
|
sinon.assert.calledWith(
|
|
|
|
this.SubscriptionLocator.getSubscription,
|
|
|
|
this.subscriptionId
|
|
|
|
)
|
|
|
|
sinon.assert.calledWith(
|
|
|
|
this.GroupHandler.removeUserFromGroup,
|
|
|
|
this.subscriptionId,
|
|
|
|
memberUserIdToremove
|
|
|
|
)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.Controller.removeSelfFromGroup(this.req, res)
|
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|