Просмотр исходного кода

In PayPal collect invoices script: Update throw unsuccessful invoices collections (#18572)

* Remove throw on `INVOICES_COLLECTED_SUCCESS.length === 0`

Effectively reverts https://github.com/overleaf/internal/pull/18310/commits/038377b511c56fab24959ce99b6f2c7d6429c282

See: https://digital-science.slack.com/archives/C20TZCMMF/p1716973110408049

* Update tests so they don't expect rejections

* Reject when some invoice collection failed

GitOrigin-RevId: aa37f7fa37c96b8624e87d94be675d115e3250a9
Antoine Clausse 2 лет назад
Родитель
Сommit
01e1286a8b

+ 3 - 2
services/web/scripts/recurly/collect_paypal_past_due_invoice.js

@@ -91,8 +91,9 @@ const main = async () => {
   try {
     await attemptInvoicesCollection()
 
-    if (INVOICES_COLLECTED_SUCCESS.length === 0) {
-      throw new Error('No invoices collected')
+    const diff = INVOICES_COLLECTED.length - INVOICES_COLLECTED_SUCCESS.length
+    if (diff !== 0) {
+      throw new Error(`Invoices collection failed for ${diff} invoices`)
     }
 
     return {

+ 14 - 10
services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js

@@ -252,23 +252,27 @@ describe('CollectPayPalPastDueInvoice', function () {
     expect(apiRequestStub.callCount).to.eql(24)
   })
 
-  it('rejects with no invoices are processed because of errors', async function () {
+  it('rejects when some invoice processing failed', async function () {
     fakeApiRequests([404])
-    await expect(main()).to.be.rejectedWith('No invoices collected')
+    await expect(main()).to.be.rejectedWith(
+      'Invoices collection failed for 1 invoices'
+    )
   })
 
-  it('rejects when there are no invoices', async function () {
+  it('doesnt reject when there are no invoices', async function () {
     fakeApiRequests([])
-    await expect(main()).to.be.rejectedWith('No invoices collected')
+    const r = await main()
+    expect(r).to.eql({
+      INVOICES_COLLECTED: [],
+      INVOICES_COLLECTED_SUCCESS: [],
+      USERS_COLLECTED: [],
+    })
   })
 
   it('resolves when some invoices are partially successful', async function () {
     fakeApiRequests([200, 404])
-    const r = await main()
-    expect(r).to.eql({
-      INVOICES_COLLECTED: [200, 404],
-      INVOICES_COLLECTED_SUCCESS: [200],
-      USERS_COLLECTED: ['200', '404'],
-    })
+    await expect(main()).to.be.rejectedWith(
+      'Invoices collection failed for 1 invoices'
+    )
   })
 })