Skip to content

Commit b0d658f

Browse files
committed
Fixed get test to check for 404 that is thrown now by handleOpenPaymentsError
1 parent 0ee0908 commit b0d658f

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

packages/backend/src/open_payments/payment/incoming_remote/service.test.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,26 +321,32 @@ describe('Remote Incoming Payment Service', (): void => {
321321
})
322322

323323
test('returns NotFound error if 404 error getting public incoming payment', async () => {
324-
const clientGetPublicIncomingPaymentSpy = jest
325-
.spyOn(openPaymentsClient.incomingPayment, 'getPublic')
324+
const mockedGrant = {
325+
id: uuid(),
326+
accessToken: uuid()
327+
} as Grant
328+
const grantGetOrCreateSpy = jest
329+
.spyOn(grantService, 'getOrCreate')
330+
.mockResolvedValueOnce(mockedGrant)
331+
332+
const mockedIncomingPayment = mockIncomingPaymentWithPaymentMethods({
333+
walletAddress: walletAddress.id
334+
})
335+
336+
const clientGetIncomingPaymentSpy = jest
337+
.spyOn(openPaymentsClient.incomingPayment, 'get')
326338
.mockImplementationOnce(() => {
327-
throw new OpenPaymentsClientError(
328-
'Could not find public incoming payment',
329-
{
330-
status: 404,
331-
description: 'Could not find public incoming payment'
332-
}
333-
)
339+
throw new OpenPaymentsClientError('Not found', {
340+
status: 404,
341+
description: 'Not found'
342+
})
334343
})
335344

336-
const incomingPaymentUrl = `https://example.com/incoming-payment/${uuid()}`
337-
338345
await expect(
339-
remoteIncomingPaymentService.get(incomingPaymentUrl)
340-
).resolves.toEqual(RemoteIncomingPaymentError.NotFound)
341-
expect(clientGetPublicIncomingPaymentSpy).toHaveBeenCalledWith({
342-
url: incomingPaymentUrl
343-
})
346+
remoteIncomingPaymentService.get(mockedIncomingPayment.id)
347+
).resolves.toStrictEqual(RemoteIncomingPaymentError.NotFound)
348+
expect(clientGetIncomingPaymentSpy).toHaveBeenCalledTimes(1)
349+
expect(grantGetOrCreateSpy).toHaveBeenCalledTimes(1)
344350
})
345351

346352
test('returns InvalidRequest error if unhandled error getting public incoming payment', async () => {

0 commit comments

Comments
 (0)