From 01e1286a8b4a027e43451f7968221e932ca48677 Mon Sep 17 00:00:00 2001 From: Antoine Clausse Date: Wed, 29 May 2024 14:18:58 +0200 Subject: [PATCH] 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 --- .../collect_paypal_past_due_invoice.js | 5 ++-- .../src/CollectPayPalPastDueInvoiceTest.js | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js b/services/web/scripts/recurly/collect_paypal_past_due_invoice.js index 00007eb266..69a00d6bef 100644 --- a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js +++ b/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 { diff --git a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js b/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js index e0689b850c..1a6ce3c9a2 100644 --- a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js +++ b/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' + ) }) })