Skip to content

Commit

Permalink
fix(backend): getLocalIncomingPayment doesn't throw when no streamCre…
Browse files Browse the repository at this point in the history
…dentials
  • Loading branch information
cozminu committed Mar 6, 2025
1 parent 3445660 commit a52756f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
34 changes: 23 additions & 11 deletions packages/backend/src/open_payments/receiver/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Receiver } from './model'
import { IncomingPayment } from '../payment/incoming/model'
import { StreamCredentialsService } from '../../payment-method/ilp/stream-credentials/service'
import { WalletAddress } from '../wallet_address/model'
import { Asset } from '../../asset/model'

describe('Receiver Service', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -164,13 +165,23 @@ describe('Receiver Service', (): void => {
)
})

test('throws error if stream credentials could not be generated', async () => {
jest.spyOn(incomingPaymentService, 'get').mockResolvedValueOnce({
id: uuid(),
walletAddress: {
id: 'https://example.com/wallet-address'
} as WalletAddress
} as IncomingPayment)
test('returns object without methods if stream credentials could not be generated', async () => {
const incomingPayment = new IncomingPayment()
incomingPayment.id = uuid()
incomingPayment.createdAt = new Date()
incomingPayment.updatedAt = new Date()
incomingPayment.expiresAt = new Date(Date.now() + 30_000)
incomingPayment.walletAddress = new WalletAddress()
incomingPayment.walletAddress.url =
'https://example.com/wallet-address'
incomingPayment.asset = {
code: 'USD',
scale: 2
} as Asset

jest
.spyOn(incomingPaymentService, 'get')
.mockResolvedValueOnce(incomingPayment)

jest
.spyOn(streamCredentialsService, 'get')
Expand All @@ -179,11 +190,12 @@ describe('Receiver Service', (): void => {
await expect(
getLocalIncomingPayment(
serviceDeps,
`https://example.com/incoming-payments/${uuid()}`
`https://example.com/incoming-payments/${incomingPayment.id}`
)
).rejects.toThrow(
'Could not get stream credentials for local incoming payment'
)
).resolves.toMatchObject({
id: `https://example.com/incoming-payments/${incomingPayment.id}`,
walletAddress: incomingPayment.walletAddress.url
})
})
})
})
Expand Down
8 changes: 0 additions & 8 deletions packages/backend/src/open_payments/receiver/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,6 @@ export async function getLocalIncomingPayment(

const streamCredentials = deps.streamCredentialsService.get(incomingPayment)

if (!streamCredentials) {
const errorMessage =
'Could not get stream credentials for local incoming payment'
deps.logger.error({ incomingPaymentId: incomingPayment.id }, errorMessage)

throw new Error(errorMessage)
}

return incomingPayment.toOpenPaymentsTypeWithMethods(
incomingPayment.walletAddress,
streamCredentials
Expand Down

0 comments on commit a52756f

Please sign in to comment.