-
Notifications
You must be signed in to change notification settings - Fork 308
/
adapter.test.ts
63 lines (54 loc) · 1.68 KB
/
adapter.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
import { AdapterData, AdapterRequest, AdapterRequestData, Execute } from '@chainlink/ea-bootstrap'
import nock from 'nock'
import * as apyFinanceAdapter from '../../src/index'
import { mockEthereumCalls, mockTiingoResponse } from './fixtures'
let oldEnv: NodeJS.ProcessEnv
describe('execute', () => {
let execute: Execute
const id = '1'
beforeAll(async () => {
execute = await apyFinanceAdapter.makeExecute()
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env.CACHE_ENABLED = 'false'
process.env.TIINGO_DATA_PROVIDER_URL =
process.env.TIINGO_DATA_PROVIDER_URL || 'http://localhost:3000'
process.env.ETHEREUM_RPC_URL =
process.env.ETHEREUM_RPC_URL || 'https://geth-main.eth.devnet.tools'
if (process.env.RECORD) nock.recorder.rec()
})
afterAll(() => {
process.env = oldEnv
if (process.env.RECORD) nock.recorder.play()
nock.restore()
nock.cleanAll()
nock.enableNetConnect()
})
describe('with request properly formatted', () => {
mockTiingoResponse()
mockEthereumCalls()
const data: AdapterRequestData = {
id,
data: {
source: 'tiingo',
},
}
it('should return success', async () => {
const resp = await execute(data as AdapterRequest<AdapterData>, {})
expect(resp).toMatchSnapshot()
})
})
describe('with varying stable prices', () => {
mockTiingoResponse()
mockEthereumCalls()
const data: AdapterRequestData = {
id,
data: {
source: 'tiingo',
},
}
it('should return correct result', async () => {
const resp = await execute(data as AdapterRequest<AdapterData>, {})
expect(resp).toMatchSnapshot()
})
})
})