From 57332242b6ece32c634e4c87690a58f4790b150a Mon Sep 17 00:00:00 2001 From: Max Kurapov Date: Wed, 1 Feb 2023 10:15:08 -0700 Subject: [PATCH] chore(backend): make toOpenPaymentType sync (#1056) * chore(backend): make toOpenPaymentType sync * chore(backend): make quote.toOpenPaymentsType sync * chore(backend): convert tests to sync * chore(backend): update tests --- .../open_payments/payment/incoming/model.ts | 41 +++++++++---------- .../payment/incoming/routes.test.ts | 6 +-- .../open_payments/payment/incoming/routes.ts | 30 +++++++++----- .../open_payments/payment/outgoing/model.ts | 15 +++---- .../payment/outgoing/routes.test.ts | 4 +- .../open_payments/payment/outgoing/routes.ts | 14 ++++--- .../payment/outgoing/service.test.ts | 15 +++---- .../payment_pointer/model.test.ts | 14 +++---- .../open_payments/payment_pointer/routes.ts | 6 +-- .../backend/src/open_payments/quote/model.ts | 15 ++----- .../src/open_payments/quote/routes.test.ts | 2 +- .../backend/src/open_payments/quote/routes.ts | 12 ++++-- .../src/open_payments/quote/service.test.ts | 23 +++++------ .../src/open_payments/receiver/model.test.ts | 10 ++--- .../open_payments/receiver/service.test.ts | 6 +-- .../src/open_payments/receiver/service.ts | 4 +- 16 files changed, 107 insertions(+), 110 deletions(-) diff --git a/packages/backend/src/open_payments/payment/incoming/model.ts b/packages/backend/src/open_payments/payment/incoming/model.ts index b8c0a6ac54..45d947de0b 100644 --- a/packages/backend/src/open_payments/payment/incoming/model.ts +++ b/packages/backend/src/open_payments/payment/incoming/model.ts @@ -130,17 +130,10 @@ export class IncomingPayment this.receivedAmountValue = amount.value } - public async getUrl(fetchedPaymentPointer?: PaymentPointer): Promise { - const paymentPointer = - fetchedPaymentPointer || (await this.getPaymentPointer()) - + public getUrl(paymentPointer: PaymentPointer): string { return `${paymentPointer.url}${IncomingPayment.urlPath}/${this.id}` } - public async getPaymentPointer(): Promise { - return this.paymentPointer ?? (await this.$relatedQuery('paymentPointer')) - } - public async onCredit({ totalReceived }: OnCreditOptions): Promise { @@ -249,29 +242,33 @@ export class IncomingPayment return payment } - public async toOpenPaymentsType(): Promise - public async toOpenPaymentsType( + public toOpenPaymentsType( + paymentPointer: PaymentPointer + ): OpenPaymentsIncomingPayment + public toOpenPaymentsType( + paymentPointer: PaymentPointer, ilpStreamConnection: Connection - ): Promise - public async toOpenPaymentsType( + ): OpenPaymentsIncomingPaymentWithConnection + public toOpenPaymentsType( + paymentPointer: PaymentPointer, ilpStreamConnection: string - ): Promise - public async toOpenPaymentsType( + ): OpenPaymentsIncomingPaymentWithConnectionUrl + public toOpenPaymentsType( + paymentPointer: PaymentPointer, ilpStreamConnection?: Connection | string - ): Promise< + ): | OpenPaymentsIncomingPaymentWithConnection | OpenPaymentsIncomingPaymentWithConnectionUrl - > - public async toOpenPaymentsType( + + public toOpenPaymentsType( + paymentPointer: PaymentPointer, ilpStreamConnection?: Connection | string - ): Promise< + ): | OpenPaymentsIncomingPayment | OpenPaymentsIncomingPaymentWithConnection - | OpenPaymentsIncomingPaymentWithConnectionUrl - > { - const paymentPointer = await this.getPaymentPointer() + | OpenPaymentsIncomingPaymentWithConnectionUrl { const baseIncomingPayment: OpenPaymentsIncomingPayment = { - id: await this.getUrl(paymentPointer), + id: this.getUrl(paymentPointer), paymentPointer: paymentPointer.url, incomingAmount: this.incomingAmount ? serializeAmount(this.incomingAmount) diff --git a/packages/backend/src/open_payments/payment/incoming/routes.test.ts b/packages/backend/src/open_payments/payment/incoming/routes.test.ts index 81544b4538..644b0726ac 100644 --- a/packages/backend/src/open_payments/payment/incoming/routes.test.ts +++ b/packages/backend/src/open_payments/payment/incoming/routes.test.ts @@ -82,9 +82,9 @@ describe('Incoming Payment Routes', (): void => { externalRef }), get: (ctx) => incomingPaymentRoutes.get(ctx), - getBody: async (incomingPayment, list) => { + getBody: (incomingPayment, list) => { return { - id: await incomingPayment.getUrl(), + id: incomingPayment.getUrl(paymentPointer), paymentPointer: paymentPointer.url, completed: false, incomingAmount: @@ -265,7 +265,7 @@ describe('Incoming Payment Routes', (): void => { await expect(incomingPaymentRoutes.complete(ctx)).resolves.toBeUndefined() expect(ctx.response).toSatisfyApiSpec() expect(ctx.body).toEqual({ - id: await incomingPayment.getUrl(), + id: incomingPayment.getUrl(paymentPointer), paymentPointer: paymentPointer.url, incomingAmount: { value: '123', diff --git a/packages/backend/src/open_payments/payment/incoming/routes.ts b/packages/backend/src/open_payments/payment/incoming/routes.ts index 0820e4858f..8175670f7b 100644 --- a/packages/backend/src/open_payments/payment/incoming/routes.ts +++ b/packages/backend/src/open_payments/payment/incoming/routes.ts @@ -24,6 +24,7 @@ import { IncomingPaymentWithConnection as OpenPaymentsIncomingPaymentWithConnection, IncomingPaymentWithConnectionUrl as OpenPaymentsIncomingPaymentWithConnectionUrl } from 'open-payments' +import { PaymentPointer } from '../../payment_pointer/model' // Don't allow creating an incoming payment too far out. Incoming payments with no payments before they expire are cleaned up, since incoming payments creation is unauthenticated. // TODO what is a good default value for this? @@ -75,7 +76,11 @@ async function getIncomingPayment( } if (!incomingPayment) return ctx.throw(404) const connection = deps.connectionService.get(incomingPayment) - ctx.body = await incomingPaymentToBody(incomingPayment, connection) + ctx.body = incomingPaymentToBody( + ctx.paymentPointer, + incomingPayment, + connection + ) } export type CreateBody = { @@ -116,7 +121,11 @@ async function createIncomingPayment( ctx.status = 201 const connection = deps.connectionService.get(incomingPaymentOrError) - ctx.body = await incomingPaymentToBody(incomingPaymentOrError, connection) + ctx.body = incomingPaymentToBody( + ctx.paymentPointer, + incomingPaymentOrError, + connection + ) } async function completeIncomingPayment( @@ -138,7 +147,7 @@ async function completeIncomingPayment( errorToMessage[incomingPaymentOrError] ) } - ctx.body = await incomingPaymentToBody(incomingPaymentOrError) + ctx.body = incomingPaymentToBody(ctx.paymentPointer, incomingPaymentOrError) } async function listIncomingPayments( @@ -149,8 +158,9 @@ async function listIncomingPayments( await listSubresource({ ctx, getPaymentPointerPage: deps.incomingPaymentService.getPaymentPointerPage, - toBody: async (payment) => - await incomingPaymentToBody( + toBody: (payment) => + incomingPaymentToBody( + ctx.paymentPointer, payment, deps.connectionService.getUrl(payment) ) @@ -159,13 +169,13 @@ async function listIncomingPayments( ctx.throw(500, 'Error trying to list incoming payments') } } -async function incomingPaymentToBody( +function incomingPaymentToBody( + paymentPointer: PaymentPointer, incomingPayment: IncomingPayment, ilpStreamConnection?: Connection | string -): Promise< +): | OpenPaymentsIncomingPayment | OpenPaymentsIncomingPaymentWithConnection - | OpenPaymentsIncomingPaymentWithConnectionUrl -> { - return incomingPayment.toOpenPaymentsType(ilpStreamConnection) + | OpenPaymentsIncomingPaymentWithConnectionUrl { + return incomingPayment.toOpenPaymentsType(paymentPointer, ilpStreamConnection) } diff --git a/packages/backend/src/open_payments/payment/outgoing/model.ts b/packages/backend/src/open_payments/payment/outgoing/model.ts index 77463c455d..736cca0950 100644 --- a/packages/backend/src/open_payments/payment/outgoing/model.ts +++ b/packages/backend/src/open_payments/payment/outgoing/model.ts @@ -72,10 +72,7 @@ export class OutgoingPayment return this.quote.assetId } - public async getUrl(fetchedPaymentPointer?: PaymentPointer): Promise { - const paymentPointer = - fetchedPaymentPointer || (await this.getPaymentPointer()) - + public getUrl(paymentPointer: PaymentPointer): string { return `${paymentPointer.url}${OutgoingPayment.urlPath}/${this.id}` } @@ -188,13 +185,13 @@ export class OutgoingPayment return this.paymentPointer ?? (await this.$relatedQuery('paymentPointer')) } - public async toOpenPaymentsType(): Promise { - const paymentPointer = await this.getPaymentPointer() - + public toOpenPaymentsType( + paymentPointer: PaymentPointer + ): OpenPaymentsOutgoingPayment { return { - id: await this.getUrl(paymentPointer), + id: this.getUrl(paymentPointer), paymentPointer: paymentPointer.url, - quoteId: (await this.quote?.getUrl()) ?? undefined, + quoteId: this.quote?.getUrl(paymentPointer) ?? undefined, receiveAmount: serializeAmount(this.receiveAmount), sendAmount: serializeAmount(this.sendAmount), sentAmount: serializeAmount(this.sentAmount), diff --git a/packages/backend/src/open_payments/payment/outgoing/routes.test.ts b/packages/backend/src/open_payments/payment/outgoing/routes.test.ts index 0d802f2590..2b949c5a16 100644 --- a/packages/backend/src/open_payments/payment/outgoing/routes.test.ts +++ b/packages/backend/src/open_payments/payment/outgoing/routes.test.ts @@ -100,12 +100,12 @@ describe('Outgoing Payment Routes', (): void => { return outgoingPayment }, get: (ctx) => outgoingPaymentRoutes.get(ctx), - getBody: async (outgoingPayment) => { + getBody: (outgoingPayment) => { return { id: `${paymentPointer.url}/outgoing-payments/${outgoingPayment.id}`, paymentPointer: paymentPointer.url, receiver: outgoingPayment.receiver, - quoteId: await outgoingPayment.quote.getUrl(), + quoteId: outgoingPayment.quote.getUrl(paymentPointer), sendAmount: serializeAmount(outgoingPayment.sendAmount), sentAmount: serializeAmount(outgoingPayment.sentAmount), receiveAmount: serializeAmount(outgoingPayment.receiveAmount), diff --git a/packages/backend/src/open_payments/payment/outgoing/routes.ts b/packages/backend/src/open_payments/payment/outgoing/routes.ts index 5c0d2d15e7..9884292cab 100644 --- a/packages/backend/src/open_payments/payment/outgoing/routes.ts +++ b/packages/backend/src/open_payments/payment/outgoing/routes.ts @@ -9,6 +9,7 @@ import { AccessAction, OutgoingPayment as OpenPaymentsOutgoingPayment } from 'open-payments' +import { PaymentPointer } from '../../payment_pointer/model' interface ServiceDependencies { config: IAppConfig @@ -52,7 +53,7 @@ async function getOutgoingPayment( ctx.throw(500, 'Error trying to get outgoing payment') } if (!outgoingPayment) return ctx.throw(404) - ctx.body = await outgoingPaymentToBody(outgoingPayment) + ctx.body = outgoingPaymentToBody(ctx.paymentPointer, outgoingPayment) } export type CreateBody = { @@ -86,7 +87,7 @@ async function createOutgoingPayment( return ctx.throw(errorToCode[paymentOrErr], errorToMessage[paymentOrErr]) } ctx.status = 201 - ctx.body = await outgoingPaymentToBody(paymentOrErr) + ctx.body = outgoingPaymentToBody(ctx.paymentPointer, paymentOrErr) } async function listOutgoingPayments( @@ -97,15 +98,16 @@ async function listOutgoingPayments( await listSubresource({ ctx, getPaymentPointerPage: deps.outgoingPaymentService.getPaymentPointerPage, - toBody: async (payment) => await outgoingPaymentToBody(payment) + toBody: (payment) => outgoingPaymentToBody(ctx.paymentPointer, payment) }) } catch (_) { ctx.throw(500, 'Error trying to list outgoing payments') } } -async function outgoingPaymentToBody( +function outgoingPaymentToBody( + paymentPointer: PaymentPointer, outgoingPayment: OutgoingPayment -): Promise { - return outgoingPayment.toOpenPaymentsType() +): OpenPaymentsOutgoingPayment { + return outgoingPayment.toOpenPaymentsType(paymentPointer) } diff --git a/packages/backend/src/open_payments/payment/outgoing/service.test.ts b/packages/backend/src/open_payments/payment/outgoing/service.test.ts index 93d02ab80f..b2827bdd11 100644 --- a/packages/backend/src/open_payments/payment/outgoing/service.test.ts +++ b/packages/backend/src/open_payments/payment/outgoing/service.test.ts @@ -245,11 +245,10 @@ describe('OutgoingPaymentService', (): void => { beforeEach(async (): Promise => { const { id: sendAssetId } = await createAsset(deps, asset) - paymentPointerId = ( - await createPaymentPointer(deps, { - assetId: sendAssetId - }) - ).id + const paymentPointer = await createPaymentPointer(deps, { + assetId: sendAssetId + }) + paymentPointerId = paymentPointer.id const { id: destinationAssetId } = await createAsset(deps, destinationAsset) receiverPaymentPointer = await createPaymentPointer(deps, { assetId: destinationAssetId, @@ -266,7 +265,7 @@ describe('OutgoingPaymentService', (): void => { incomingPayment = await createIncomingPayment(deps, { paymentPointerId: receiverPaymentPointer.id }) - receiver = await incomingPayment.getUrl() + receiver = incomingPayment.getUrl(receiverPaymentPointer) amtDelivered = BigInt(0) }) @@ -855,12 +854,14 @@ describe('OutgoingPaymentService', (): void => { assetScale: receiverPaymentPointer.asset.scale } }) + const fetchedReceiver = connectionService.getUrl(incomingPayment) assert.ok(fetchedReceiver) + assert.ok(incomingPayment.paymentPointer) const paymentId = await setup({ receiver: toConnection ? fetchedReceiver - : await incomingPayment.getUrl(), + : incomingPayment.getUrl(incomingPayment.paymentPointer), receiveAmount }) diff --git a/packages/backend/src/open_payments/payment_pointer/model.test.ts b/packages/backend/src/open_payments/payment_pointer/model.test.ts index c3a87565a4..5ae2ae0bd1 100644 --- a/packages/backend/src/open_payments/payment_pointer/model.test.ts +++ b/packages/backend/src/open_payments/payment_pointer/model.test.ts @@ -194,7 +194,7 @@ type RouteTestsOptions = Omit< > & { getPaymentPointer: () => Promise get: (ctx: ReadContext) => Promise - getBody: (model: M, list?: boolean) => Promise> + getBody: (model: M, list?: boolean) => Record list?: (ctx: ListContext) => Promise urlPath: string } @@ -230,7 +230,7 @@ export const getRouteTests = ({ expect(ctx.response).toSatisfyApiSpec() } expect(ctx.body).toEqual({ - result: expectedMatch ? [await getBody(expectedMatch, true)] : [], + result: expectedMatch ? [getBody(expectedMatch, true)] : [], pagination: { hasPreviousPage: false, hasNextPage: false, @@ -261,7 +261,7 @@ export const getRouteTests = ({ if (expectedMatch) { await expect(get(ctx)).resolves.toBeUndefined() expect(ctx.response).toSatisfyApiSpec() - expect(ctx.body).toEqual(await getBody(expectedMatch)) + expect(ctx.body).toEqual(getBody(expectedMatch)) } else { await expect(get(ctx)).rejects.toMatchObject({ status: 404, @@ -319,11 +319,9 @@ export const getRouteTests = ({ expect(ctx.response).toSatisfyApiSpec() expect(ctx.body).toEqual({ pagination, - result: await Promise.all( - models - .slice(startIndex, endIndex + 1) - .map(async (model) => await getBody(model, true)) - ) + result: models + .slice(startIndex, endIndex + 1) + .map((model) => getBody(model, true)) }) } ) diff --git a/packages/backend/src/open_payments/payment_pointer/routes.ts b/packages/backend/src/open_payments/payment_pointer/routes.ts index 92a0ba606d..2059a63d47 100644 --- a/packages/backend/src/open_payments/payment_pointer/routes.ts +++ b/packages/backend/src/open_payments/payment_pointer/routes.ts @@ -40,9 +40,7 @@ export async function getPaymentPointer( interface ListSubresourceOptions { ctx: ListContext getPaymentPointerPage: PaymentPointerSubresourceService['getPaymentPointerPage'] - toBody: - | ((model: M) => Record) - | ((model: M) => Promise>) + toBody: (model: M) => Record } export const listSubresource = async ({ @@ -68,7 +66,7 @@ export const listSubresource = async ({ ) const result = { pagination: pageInfo, - result: await Promise.all(page.map(async (item: M) => await toBody(item))) + result: page.map((item: M) => toBody(item)) } ctx.body = result } diff --git a/packages/backend/src/open_payments/quote/model.ts b/packages/backend/src/open_payments/quote/model.ts index 7684dacd09..1b70de7b10 100644 --- a/packages/backend/src/open_payments/quote/model.ts +++ b/packages/backend/src/open_payments/quote/model.ts @@ -47,14 +47,7 @@ export class Quote extends PaymentPointerSubresource { private sendAmountValue!: bigint - public async getPaymentPointer(): Promise { - return this.paymentPointer ?? (await this.$relatedQuery('paymentPointer')) - } - - public async getUrl(fetchedPaymentPointer?: PaymentPointer): Promise { - const paymentPointer = - fetchedPaymentPointer || (await this.getPaymentPointer()) - + public getUrl(paymentPointer: PaymentPointer): string { return `${paymentPointer.url}${Quote.urlPath}/${this.id}` } @@ -164,11 +157,9 @@ export class Quote extends PaymentPointerSubresource { } } - public async toOpenPaymentsType(): Promise { - const paymentPointer = await this.getPaymentPointer() - + public toOpenPaymentsType(paymentPointer: PaymentPointer): OpenPaymentsQuote { return { - id: await this.getUrl(paymentPointer), + id: this.getUrl(paymentPointer), paymentPointer: paymentPointer.url, receiveAmount: serializeAmount(this.receiveAmount), sendAmount: serializeAmount(this.sendAmount), diff --git a/packages/backend/src/open_payments/quote/routes.test.ts b/packages/backend/src/open_payments/quote/routes.test.ts index 269581aafa..9c78b95f28 100644 --- a/packages/backend/src/open_payments/quote/routes.test.ts +++ b/packages/backend/src/open_payments/quote/routes.test.ts @@ -96,7 +96,7 @@ describe('Quote Routes', (): void => { client }), get: (ctx) => quoteRoutes.get(ctx), - getBody: async (quote) => { + getBody: (quote) => { return { id: `${paymentPointer.url}/quotes/${quote.id}`, paymentPointer: paymentPointer.url, diff --git a/packages/backend/src/open_payments/quote/routes.ts b/packages/backend/src/open_payments/quote/routes.ts index efa12167e8..d327497a99 100644 --- a/packages/backend/src/open_payments/quote/routes.ts +++ b/packages/backend/src/open_payments/quote/routes.ts @@ -7,6 +7,7 @@ import { isQuoteError, errorToCode, errorToMessage } from './errors' import { Quote } from './model' import { AmountJSON, parseAmount } from '../amount' import { Quote as OpenPaymentsQuote } from 'open-payments' +import { PaymentPointer } from '../payment_pointer/model' interface ServiceDependencies { config: IAppConfig @@ -40,7 +41,7 @@ async function getQuote( paymentPointerId: ctx.paymentPointer.id }) if (!quote) return ctx.throw(404) - ctx.body = await quoteToBody(quote) + ctx.body = quoteToBody(ctx.paymentPointer, quote) } interface CreateBodyBase { @@ -80,7 +81,7 @@ async function createQuote( } ctx.status = 201 - ctx.body = await quoteToBody(quoteOrErr) + ctx.body = quoteToBody(ctx.paymentPointer, quoteOrErr) } catch (err) { if (isQuoteError(err)) { return ctx.throw(errorToCode[err], errorToMessage[err]) @@ -90,6 +91,9 @@ async function createQuote( } } -async function quoteToBody(quote: Quote): Promise { - return quote.toOpenPaymentsType() +function quoteToBody( + paymentPointer: PaymentPointer, + quote: Quote +): OpenPaymentsQuote { + return quote.toOpenPaymentsType(paymentPointer) } diff --git a/packages/backend/src/open_payments/quote/service.test.ts b/packages/backend/src/open_payments/quote/service.test.ts index e3376b0a91..8de6155c3c 100644 --- a/packages/backend/src/open_payments/quote/service.test.ts +++ b/packages/backend/src/open_payments/quote/service.test.ts @@ -247,7 +247,7 @@ describe('QuoteService', (): void => { paymentPointerId, receiver: toConnection ? connectionService.getUrl(incomingPayment) - : await incomingPayment.getUrl() + : incomingPayment.getUrl(receivingPaymentPointer) } if (sendAmount) options.sendAmount = sendAmount if (receiveAmount) options.receiveAmount = receiveAmount @@ -575,7 +575,7 @@ describe('QuoteService', (): void => { }) const options: CreateQuoteOptions = { paymentPointerId, - receiver: await incomingPayment.getUrl(), + receiver: incomingPayment.getUrl(receivingPaymentPointer), receiveAmount } const expected: ExpectedQuote = { @@ -651,13 +651,12 @@ describe('QuoteService', (): void => { `( 'fails to create $description', async ({ sendAmount, receiveAmount }): Promise => { + const incomingPayment = await createIncomingPayment(deps, { + paymentPointerId: receivingPaymentPointer.id + }) const options: CreateQuoteOptions = { paymentPointerId, - receiver: await ( - await createIncomingPayment(deps, { - paymentPointerId: receivingPaymentPointer.id - }) - ).getUrl() + receiver: incomingPayment.getUrl(receivingPaymentPointer) } if (sendAmount) options.sendAmount = sendAmount if (receiveAmount) options.receiveAmount = receiveAmount @@ -672,14 +671,14 @@ describe('QuoteService', (): void => { jest .spyOn(ratesService, 'prices') .mockImplementation(() => Promise.reject(new Error('fail'))) + const incomingPayment = await createIncomingPayment(deps, { + paymentPointerId: receivingPaymentPointer.id + }) + await expect( quoteService.create({ paymentPointerId, - receiver: await ( - await createIncomingPayment(deps, { - paymentPointerId: receivingPaymentPointer.id - }) - ).getUrl(), + receiver: incomingPayment.getUrl(receivingPaymentPointer), sendAmount }) ).rejects.toThrow('missing prices') diff --git a/packages/backend/src/open_payments/receiver/model.test.ts b/packages/backend/src/open_payments/receiver/model.test.ts index e8a74a3a1e..bfa9af0ca0 100644 --- a/packages/backend/src/open_payments/receiver/model.test.ts +++ b/packages/backend/src/open_payments/receiver/model.test.ts @@ -44,7 +44,7 @@ describe('Receiver Model', (): void => { assert(connection instanceof Connection) const receiver = Receiver.fromIncomingPayment( - await incomingPayment.toOpenPaymentsType(connection) + await incomingPayment.toOpenPaymentsType(paymentPointer, connection) ) expect(receiver).toEqual({ @@ -53,7 +53,7 @@ describe('Receiver Model', (): void => { ilpAddress: expect.any(String), sharedSecret: expect.any(Buffer), incomingPayment: { - id: await incomingPayment.getUrl(), + id: incomingPayment.getUrl(paymentPointer), paymentPointer: paymentPointer.url, updatedAt: incomingPayment.updatedAt, createdAt: incomingPayment.createdAt, @@ -76,7 +76,7 @@ describe('Receiver Model', (): void => { assert(connection instanceof Connection) const openPaymentsIncomingPayment = - await incomingPayment.toOpenPaymentsType(connection) + await incomingPayment.toOpenPaymentsType(paymentPointer, connection) expect(() => Receiver.fromIncomingPayment(openPaymentsIncomingPayment) @@ -94,7 +94,7 @@ describe('Receiver Model', (): void => { assert(connection instanceof Connection) const openPaymentsIncomingPayment = - await incomingPayment.toOpenPaymentsType(connection) + await incomingPayment.toOpenPaymentsType(paymentPointer, connection) expect(() => Receiver.fromIncomingPayment(openPaymentsIncomingPayment) @@ -112,7 +112,7 @@ describe('Receiver Model', (): void => { ;(connection.ilpAddress as string) = 'not base 64 encoded' const openPaymentsIncomingPayment = - await incomingPayment.toOpenPaymentsType(connection) + await incomingPayment.toOpenPaymentsType(paymentPointer, connection) expect(() => Receiver.fromIncomingPayment(openPaymentsIncomingPayment) diff --git a/packages/backend/src/open_payments/receiver/service.test.ts b/packages/backend/src/open_payments/receiver/service.test.ts index d03cbb089f..0bca137283 100644 --- a/packages/backend/src/open_payments/receiver/service.test.ts +++ b/packages/backend/src/open_payments/receiver/service.test.ts @@ -194,15 +194,15 @@ describe('Receiver Service', (): void => { ) await expect( - receiverService.get(await incomingPayment.getUrl()) + receiverService.get(incomingPayment.getUrl(paymentPointer)) ).resolves.toEqual({ assetCode: incomingPayment.receivedAmount.assetCode, assetScale: incomingPayment.receivedAmount.assetScale, ilpAddress: expect.any(String), sharedSecret: expect.any(Buffer), incomingPayment: { - id: await incomingPayment.getUrl(), - paymentPointer: (await incomingPayment.getPaymentPointer()).url, + id: incomingPayment.getUrl(paymentPointer), + paymentPointer: paymentPointer.url, completed: incomingPayment.completed, receivedAmount: incomingPayment.receivedAmount, incomingAmount: incomingPayment.incomingAmount, diff --git a/packages/backend/src/open_payments/receiver/service.ts b/packages/backend/src/open_payments/receiver/service.ts index b413b10bd0..70b5aa3a76 100644 --- a/packages/backend/src/open_payments/receiver/service.ts +++ b/packages/backend/src/open_payments/receiver/service.ts @@ -131,7 +131,7 @@ async function createLocalIncomingPayment( throw new Error(errorMessage) } - return incomingPaymentOrError.toOpenPaymentsType(connection) + return incomingPaymentOrError.toOpenPaymentsType(paymentPointer, connection) } async function getReceiver( @@ -274,7 +274,7 @@ async function getLocalIncomingPayment({ return undefined } - return incomingPayment.toOpenPaymentsType(connection) + return incomingPayment.toOpenPaymentsType(paymentPointer, connection) } async function getIncomingPaymentGrant(