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' + ) }) })