mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-16 16:21:20 +00:00
In PayPal collect invoices script: Update throw unsuccessful invoices collections (#18572)
* Remove throw on `INVOICES_COLLECTED_SUCCESS.length === 0`
Effectively reverts 038377b511
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
This commit is contained in:
parent
69871fccbe
commit
01e1286a8b
2 changed files with 17 additions and 12 deletions
|
@ -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 {
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue