Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sdk-router): error console cleanup #3379

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/sdk-router/src/rfq/api.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { getAllQuotes } from './api'

global.fetch = require('node-fetch')

// Retry the flaky tests up to 3 times
jest.retryTimes(3)

describe('getAllQuotes', () => {
it('Integration test', async () => {
const result = await getAllQuotes()
Expand Down
13 changes: 13 additions & 0 deletions packages/sdk-router/src/rfq/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,28 @@ describe('getAllQuotes', () => {
})

describe('Returns an empty array', () => {
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {
// Do nothing
})
})

afterEach(() => {
jest.restoreAllMocks()
})

it('when the response is not ok', async () => {
fetchMock.mockResponseOnce(JSON.stringify(quotesAPI), { status: 500 })
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})

it('when fetch throws an error', async () => {
fetchMock.mockRejectOnce(new Error('Error fetching quotes'))
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})

it('when the response takes too long to return', async () => {
Expand All @@ -94,6 +106,7 @@ describe('getAllQuotes', () => {
)
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})
})
})
6 changes: 5 additions & 1 deletion packages/sdk-router/src/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ import * as operations from './operations'
// Override fetch to exclude RFQ from tests
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({}),
ok: true,
json: () => Promise.resolve([]),
})
) as any

// Retry the flaky tests up to 3 times
jest.retryTimes(3)

const EXPECTED_GAS_DROP: { [chainId: number]: BigNumber } = {
[SupportedChainId.ETH]: BigNumber.from(0),
// TODO: reenable once both ARB airdrops are adjusted
Expand Down
Loading