소스 검색

Merge pull request #11019 from overleaf/tm-fix-subscription-creation-response-timeout

Fix createSubscription timing out if non-handled error occurs

GitOrigin-RevId: 4f40d7134d81e6c212b045b2b18da36eb0421a43
Thomas 3 년 전
부모
커밋
ae4b4c09b8

+ 1 - 0
services/web/app/src/Features/Subscription/SubscriptionController.js

@@ -473,6 +473,7 @@ async function createSubscription(req, res) {
         { err, user_id: user._id },
         'something went wrong creating subscription'
       )
+      throw err
     }
   }
 }

+ 10 - 29
services/web/test/unit/src/Subscription/SubscriptionControllerTests.js

@@ -523,8 +523,7 @@ describe('SubscriptionController', function () {
       })
     })
 
-    it('should handle 3DSecure errors', function (done) {
-      this.next = sinon.stub()
+    it('should handle 3DSecure errors/recurly transaction errors', function (done) {
       this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
       this.SubscriptionHandler.promises.createSubscription.rejects(
         new SubscriptionErrors.RecurlyTransactionError({})
@@ -541,7 +540,6 @@ describe('SubscriptionController', function () {
     })
 
     it('should handle validation errors', function (done) {
-      this.next = sinon.stub()
       this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
       this.SubscriptionHandler.promises.createSubscription.rejects(
         new Errors.InvalidError('invalid error test')
@@ -557,37 +555,20 @@ describe('SubscriptionController', function () {
       this.SubscriptionController.createSubscription(this.req, this.res)
     })
 
-    it('should handle recurly errors', function (done) {
+    it('should throw errors from createSubscription that are not handled', function (done) {
+      const genericError = new Error('generic error')
       this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
-      this.SubscriptionHandler.promises.createSubscription.rejects(
-        new SubscriptionErrors.RecurlyTransactionError({})
-      )
+      this.SubscriptionHandler.promises.createSubscription.rejects(genericError)
 
-      this.HttpErrorHandler.unprocessableEntity = sinon.spy(
-        (req, res, info) => {
-          expect(req).to.exist
-          expect(res).to.exist
-          expect(info).to.deep.equal('Unknown transaction error')
+      this.SubscriptionController.createSubscription(
+        this.req,
+        this.res,
+        error => {
+          expect(error).to.be.instanceof(Error)
+          expect(error.message).to.equal(genericError.message)
           done()
         }
       )
-
-      this.SubscriptionController.createSubscription(this.req, this.res)
-    })
-
-    it('should handle invalid error', function (done) {
-      this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
-      this.SubscriptionHandler.promises.createSubscription.rejects(
-        new Errors.InvalidError({})
-      )
-
-      this.HttpErrorHandler.unprocessableEntity = sinon.spy((req, res) => {
-        expect(req).to.exist
-        expect(res).to.exist
-        done()
-      })
-
-      this.SubscriptionController.createSubscription(this.req, this.res)
     })
   })