Skip to content

Commit

Permalink
Update quote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Aug 23, 2024
1 parent 8276810 commit ffd6ff7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/open-payments/src/client/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ describe('quote', (): void => {

describe('getQuote', (): void => {
test('returns the quote if it passes open api validation', async (): Promise<void> => {
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<void> => {
const quote = mockQuote({
estimatedExchangeRate: 120
})
const scope = nock(baseUrl).get(`/quotes/${quote.id}`).reply(200, quote)
const result = await getQuote(
deps,
Expand Down Expand Up @@ -79,6 +97,7 @@ describe('quote', (): void => {
{ receiver: quote.receiver, method: 'ilp', walletAddress }
)
expect(result).toEqual(quote)
expect(result.estimatedExchangeRate).toBeUndefined()
scope.done()
})

Expand All @@ -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<void> => {
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 => {
Expand Down

0 comments on commit ffd6ff7

Please sign in to comment.