-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathreserves.test.ts
74 lines (57 loc) · 2.14 KB
/
reserves.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import nock from 'nock'
import * as process from 'process'
import { config } from '../../src/config'
import { hope } from '../../src/endpoint'
import { mockResponseErrorStatus, mockResponseErrorValue, mockResponseSuccess } from './fixtures'
import { Adapter } from '@chainlink/external-adapter-framework/adapter'
import { TestAdapter } from '@chainlink/external-adapter-framework/util/testing-utils'
describe('hope endpoint', () => {
let spy: jest.SpyInstance
let testAdapter: TestAdapter
const API_ENDPOINT = 'http://mock-api.com'
beforeAll(async () => {
process.env['API_ENDPOINT'] = API_ENDPOINT
process.env['API_KEY'] = 'mock-api-key'
process.env['API_SECRET'] = 'mock-api-secret'
const mockDate = new Date('2022-05-10T16:09:27.193Z')
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime())
})
beforeEach(async () => {
const adapter = new Adapter({
name: 'ELVEN',
endpoints: [hope],
defaultEndpoint: hope.name,
config,
})
// Reset TestAdapter before each test
await testAdapter?.api.close()
testAdapter = await TestAdapter.startWithMockedCache(adapter, {
testAdapter: {} as TestAdapter<never>,
})
})
afterAll(async () => {
await testAdapter.api.close()
spy.mockRestore()
nock.restore()
nock.cleanAll()
nock.enableNetConnect()
})
it('should return success', async () => {
mockResponseSuccess(API_ENDPOINT)
const res = await testAdapter.request({ endpoint: 'hope' })
expect(res.statusCode).toBe(200)
expect(res.json()).toMatchSnapshot()
})
it('should return error if provider returns an error status', async () => {
mockResponseErrorStatus(API_ENDPOINT)
const res = await testAdapter.request({ endpoint: 'hope' })
expect(res.statusCode).toBe(502)
expect(res.json()).toMatchSnapshot()
})
it('should return error if provider returns a total value which is inconsistent with aggregated reserve values', async () => {
mockResponseErrorValue(API_ENDPOINT)
const res = await testAdapter.request({ endpoint: 'hope' })
expect(res.statusCode).toBe(502)
expect(res.json()).toMatchSnapshot()
})
})