mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 06:53:55 +00:00
fix tests, and placeholder while loading
GitOrigin-RevId: c3e4f31179423ed259cc2aab5b053e5c952350ff
This commit is contained in:
parent
09667a3f6a
commit
59c26be6f2
2 changed files with 55 additions and 3 deletions
|
@ -133,13 +133,12 @@ module.exports = {
|
|||
})
|
||||
},
|
||||
|
||||
async getQueues(req, res) {
|
||||
async getQueues(req, res, next) {
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
try {
|
||||
res.json(await TdpsQueueManager.getQueues(userId))
|
||||
} catch (err) {
|
||||
logger.error({ err, userId }, 'error getting queues')
|
||||
res.json({ error: 'error getting queues' })
|
||||
next(err)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -21,6 +21,14 @@ const modulePath = require('path').join(
|
|||
describe('TpdsController', function() {
|
||||
beforeEach(function() {
|
||||
this.TpdsUpdateHandler = {}
|
||||
this.AuthenticationController = {
|
||||
getLoggedInUserId: sinon.stub().returns('user-id')
|
||||
}
|
||||
this.TpdsQueueManager = {
|
||||
promises: {
|
||||
getQueues: sinon.stub().returns('queues')
|
||||
}
|
||||
}
|
||||
this.TpdsController = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
|
@ -31,6 +39,9 @@ describe('TpdsController', function() {
|
|||
'../Notifications/NotificationsBuilder': (this.NotificationsBuilder = {
|
||||
tpdsFileLimit: sinon.stub().returns({ create: sinon.stub() })
|
||||
}),
|
||||
'../Authentication/AuthenticationController': this
|
||||
.AuthenticationController,
|
||||
'./TpdsQueueManager': this.TpdsQueueManager,
|
||||
'logger-sharelatex': {
|
||||
log() {},
|
||||
warn() {},
|
||||
|
@ -266,4 +277,46 @@ describe('TpdsController', function() {
|
|||
this.res.sendStatus.calledWith(200).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getQueues', function() {
|
||||
beforeEach(function() {
|
||||
this.req = {}
|
||||
this.res = { json: sinon.stub() }
|
||||
this.next = sinon.stub()
|
||||
})
|
||||
|
||||
describe('success', function() {
|
||||
beforeEach(async function() {
|
||||
await this.TpdsController.getQueues(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should use userId from session', function() {
|
||||
this.AuthenticationController.getLoggedInUserId.should.have.been
|
||||
.calledOnce
|
||||
this.TpdsQueueManager.promises.getQueues.should.have.been.calledWith(
|
||||
'user-id'
|
||||
)
|
||||
})
|
||||
|
||||
it('should call json with response', function() {
|
||||
this.res.json.should.have.been.calledWith('queues')
|
||||
this.next.should.not.have.been.called
|
||||
})
|
||||
})
|
||||
|
||||
describe('error', function() {
|
||||
beforeEach(async function() {
|
||||
this.err = new Error()
|
||||
this.TpdsQueueManager.promises.getQueues = sinon
|
||||
.stub()
|
||||
.rejects(this.err)
|
||||
await this.TpdsController.getQueues(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should call next with error', function() {
|
||||
this.res.json.should.not.have.been.called
|
||||
this.next.should.have.been.calledWith(this.err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue