From ffd6ff757fa16804b5e41dfcac74405bad966291 Mon Sep 17 00:00:00 2001 From: Radu-Cristian Popa Date: Fri, 23 Aug 2024 05:57:43 +0300 Subject: [PATCH] Update quote tests --- .../open-payments/src/client/quote.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/open-payments/src/client/quote.test.ts b/packages/open-payments/src/client/quote.test.ts index 12391e4f..dd1786bd 100644 --- a/packages/open-payments/src/client/quote.test.ts +++ b/packages/open-payments/src/client/quote.test.ts @@ -36,6 +36,24 @@ describe('quote', (): void => { describe('getQuote', (): void => { test('returns the quote if it passes open api validation', async (): Promise => { + const scope = nock(baseUrl).get(`/quotes/${quote.id}`).reply(200, quote) + const result = await getQuote( + deps, + { + url: `${baseUrl}/quotes/${quote.id}`, + accessToken + }, + openApiValidators.successfulValidator + ) + expect(result).toEqual(quote) + expect(result.estimatedExchangeRate).toBeUndefined() + scope.done() + }) + + test('returns the quote with the estimated exchange rate if it passes open api validation', async (): Promise => { + const quote = mockQuote({ + estimatedExchangeRate: 120 + }) const scope = nock(baseUrl).get(`/quotes/${quote.id}`).reply(200, quote) const result = await getQuote( deps, @@ -79,6 +97,7 @@ describe('quote', (): void => { { receiver: quote.receiver, method: 'ilp', walletAddress } ) expect(result).toEqual(quote) + expect(result.estimatedExchangeRate).toBeUndefined() scope.done() }) @@ -97,6 +116,25 @@ describe('quote', (): void => { ).rejects.toThrowError() scope.done() }) + + test('returns estimated exchange rate if amount can not be sent over the path', async (): Promise => { + const quote = mockQuote({ + receiveAmount: { value: '0', assetCode: 'ZAR', assetScale: 2 }, + estimatedExchangeRate: 120 + }) + const scope = nock(baseUrl).post(`/quotes`).reply(200, quote) + const result = await createQuote( + deps, + { + url: baseUrl, + accessToken + }, + openApiValidators.successfulValidator, + { receiver: quote.receiver, method: 'ilp', walletAddress } + ) + expect(result).toEqual(quote) + scope.done() + }) }) describe('routes', (): void => {