2020-05-07 08:03:30 +02:00
|
|
|
import axios, { AxiosResponse } from 'axios'
|
|
|
|
import rateAsset, { RatingResponse } from '../../../src/utils/rateAsset'
|
|
|
|
import web3 from '../__mocks__/web3'
|
|
|
|
|
|
|
|
jest.mock('axios')
|
|
|
|
|
|
|
|
describe('rateAsset()', () => {
|
|
|
|
it('success', async () => {
|
2020-06-30 14:19:27 +02:00
|
|
|
;(axios.post as any).mockResolvedValueOnce({
|
2020-05-07 08:03:30 +02:00
|
|
|
data: ['4.0', 1]
|
|
|
|
} as AxiosResponse)
|
|
|
|
|
|
|
|
const response: RatingResponse | string = await rateAsset('0x00', web3, 5)
|
|
|
|
expect(response && response[0]).toBe('4.0')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('string return', async () => {
|
2020-06-30 14:19:27 +02:00
|
|
|
;(axios.post as any).mockResolvedValueOnce({
|
2020-05-07 08:03:30 +02:00
|
|
|
data: 'Missing signature'
|
|
|
|
} as AxiosResponse)
|
|
|
|
|
|
|
|
const response: RatingResponse | string = await rateAsset('0x00', web3, 5)
|
|
|
|
expect(response && response).toBe('Missing signature')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('error catch', async () => {
|
2020-06-30 14:19:27 +02:00
|
|
|
;(axios.post as any).mockResolvedValueOnce({
|
2020-05-07 08:03:30 +02:00
|
|
|
data: {}
|
|
|
|
} as AxiosResponse)
|
|
|
|
|
|
|
|
const response: RatingResponse | string = await rateAsset(
|
|
|
|
'0x00',
|
|
|
|
{} as any,
|
|
|
|
5
|
|
|
|
)
|
|
|
|
expect(response && response).toContain('Error: ')
|
|
|
|
})
|
|
|
|
})
|