[web] Convert RecurlyWrapper functions to async (#18384)
* Rename `RecurlyWrapper` to `promises`, as it will only contain the promises soon * Update `apiRequest` * Update `_parseXml` * Update `_parseXmlAndGetAttribute` * Update `_parse*Xml` * Update `updateAccountEmailAddress` * Update `checkAccountExists` * Update `createAccount` * Update `createBillingInfo` * Update `setAddressAndCompanyBillingInfo` * Update `createSubscription` * Update `_createPaypalSubscription` * Update `_handle422Response` * Update `_createCreditCardSubscription` * Update `createSubscription` * Update `getSubscriptions` * Update `getSubscription` * Update `getPaginatedEndpoint` * Update `getAccount` * Update `getAccountActiveCoupons` * Update `getCoupon` * Update `getBillingInfo` * Update `getAccountPastDueInvoices` * Update `attemptInvoiceCollection` * Update `updateSubscription` * Update `createFixedAmmountCoupon` * Update `lookupCoupon` * Update `redeemCoupon` * Update `extendTrial` * Update `listAccountActiveSubscriptions` * To find which functions to add as callbackified, I used this Regex: `RecurlyWrapper\.(?!promises)[^.\s]*` And after adding callbackified functions, we're left with no results with the Regex: `RecurlyWrapper\.(?!promises|apiUrl|_buildXml|_parseXml|attemptInvoiceCollection|createFixedAmmountCoupon|getAccountActiveCoupons|getBillingInfo|getPaginatedEndpoint|getSubscription|updateAccountEmailAddress)[^.\s]*` * Update unit tests * Test `getSubscription` both as "promise" and as "callback" I'm not sure if we want to generalize this. * Fix: add missing `await`s (!!) * Change `apiRequest` to reject errors instead of resolving it in an object * Fixup for CollectPayPalPastDueInvoice test * Fix: callbackify `getSubscriptions` (!!) * Replace `.then(...)` chain by multiple `await` * Fixup `attemptInvoicesCollection`: prevent reading length of undefined * Use `return await` when returning promises Per https://github.com/overleaf/internal/pull/18384#pullrequestreview-2065738771 GitOrigin-RevId: ceda755b24fd29f97a27e60ac5db9bc7e369f932
This commit is contained in:
@@ -155,44 +155,32 @@ const invoiceCollectXml = `
|
||||
</invoice>
|
||||
`
|
||||
|
||||
// from our logs
|
||||
const invoiceCollectErrXml2 = `
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<error>
|
||||
<symbol>not_found</symbol>
|
||||
<description lang="en-US">Couldn't find BillingInfo with account_code = abcdef87654321</description>
|
||||
</error>
|
||||
`
|
||||
|
||||
describe('CollectPayPalPastDueInvoice', function () {
|
||||
let apiRequestStub
|
||||
const fakeApiRequests = invoiceIdsAndReturnCode => {
|
||||
apiRequestStub = sinon.stub(RecurlyWrapper, 'apiRequest')
|
||||
apiRequestStub.callsFake((options, callback) => {
|
||||
apiRequestStub = sinon.stub(RecurlyWrapper.promises, 'apiRequest')
|
||||
apiRequestStub.callsFake(options => {
|
||||
switch (options.url) {
|
||||
case 'invoices':
|
||||
callback(
|
||||
null,
|
||||
{ statusCode: 200, headers: {} },
|
||||
invoicesXml(invoiceIdsAndReturnCode)
|
||||
)
|
||||
return
|
||||
return {
|
||||
response: { statusCode: 200, headers: {} },
|
||||
body: invoicesXml(invoiceIdsAndReturnCode),
|
||||
}
|
||||
case 'accounts/200/billing_info':
|
||||
case 'accounts/404/billing_info':
|
||||
callback(null, { statusCode: 200, headers: {} }, billingInfoXml)
|
||||
return
|
||||
return {
|
||||
response: { statusCode: 200, headers: {} },
|
||||
body: billingInfoXml,
|
||||
}
|
||||
case 'invoices/200/collect':
|
||||
callback(null, { statusCode: 200, headers: {} }, invoiceCollectXml)
|
||||
return
|
||||
return {
|
||||
response: { statusCode: 200, headers: {} },
|
||||
body: invoiceCollectXml,
|
||||
}
|
||||
case 'invoices/404/collect':
|
||||
callback(
|
||||
new OError(`Recurly API returned with status code: 404`, {
|
||||
statusCode: 404,
|
||||
}),
|
||||
{ statusCode: 404, headers: {} },
|
||||
invoiceCollectErrXml2
|
||||
)
|
||||
return
|
||||
throw new OError(`Recurly API returned with status code: 404`, {
|
||||
statusCode: 404,
|
||||
})
|
||||
default:
|
||||
throw new Error(`Unexpected URL: ${options.url}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user