Explorar o código

fix tests, and placeholder while loading

GitOrigin-RevId: c3e4f31179423ed259cc2aab5b053e5c952350ff
Ersun Warncke %!s(int64=6) %!d(string=hai) anos
pai
achega
59c26be6f2

+ 2 - 3
services/web/app/src/Features/ThirdPartyDataStore/TpdsController.js

@@ -133,13 +133,12 @@ module.exports = {
     })
     })
   },
   },
 
 
-  async getQueues(req, res) {
+  async getQueues(req, res, next) {
     const userId = AuthenticationController.getLoggedInUserId(req)
     const userId = AuthenticationController.getLoggedInUserId(req)
     try {
     try {
       res.json(await TdpsQueueManager.getQueues(userId))
       res.json(await TdpsQueueManager.getQueues(userId))
     } catch (err) {
     } catch (err) {
-      logger.error({ err, userId }, 'error getting queues')
-      res.json({ error: 'error getting queues' })
+      next(err)
     }
     }
   },
   },
 
 

+ 53 - 0
services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js

@@ -21,6 +21,14 @@ const modulePath = require('path').join(
 describe('TpdsController', function() {
 describe('TpdsController', function() {
   beforeEach(function() {
   beforeEach(function() {
     this.TpdsUpdateHandler = {}
     this.TpdsUpdateHandler = {}
+    this.AuthenticationController = {
+      getLoggedInUserId: sinon.stub().returns('user-id')
+    }
+    this.TpdsQueueManager = {
+      promises: {
+        getQueues: sinon.stub().returns('queues')
+      }
+    }
     this.TpdsController = SandboxedModule.require(modulePath, {
     this.TpdsController = SandboxedModule.require(modulePath, {
       globals: {
       globals: {
         console: console
         console: console
@@ -31,6 +39,9 @@ describe('TpdsController', function() {
         '../Notifications/NotificationsBuilder': (this.NotificationsBuilder = {
         '../Notifications/NotificationsBuilder': (this.NotificationsBuilder = {
           tpdsFileLimit: sinon.stub().returns({ create: sinon.stub() })
           tpdsFileLimit: sinon.stub().returns({ create: sinon.stub() })
         }),
         }),
+        '../Authentication/AuthenticationController': this
+          .AuthenticationController,
+        './TpdsQueueManager': this.TpdsQueueManager,
         'logger-sharelatex': {
         'logger-sharelatex': {
           log() {},
           log() {},
           warn() {},
           warn() {},
@@ -266,4 +277,46 @@ describe('TpdsController', function() {
       this.res.sendStatus.calledWith(200).should.equal(true)
       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)
+      })
+    })
+  })
 })
 })