forked from smartcontractkit/external-adapters-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.test.ts
136 lines (123 loc) · 3.49 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { AdapterRequest } from '@chainlink/types'
import { util } from '@chainlink/ea-bootstrap'
import nock from 'nock'
import request, { SuperTest, Test } from 'supertest'
import { server as startServer } from '../../src/index'
import {
mockCryptoEndpoint,
mockBalanceEndpoint,
mockMarketCapEndpoint,
mockVolumeEndpoint,
} from './fixtures'
import { AddressInfo } from 'net'
let oldEnv: NodeJS.ProcessEnv
describe('amberdata', () => {
let fastify: FastifyInstance
let req: SuperTest<Test>
beforeAll(async () => {
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env.CACHE_ENABLED = 'false'
process.env.API_KEY = process.env.API_KEY || 'mock-api-key'
if (util.parseBool(process.env.RECORD)) {
nock.recorder.rec()
}
fastify = await startServer()
req = request(`localhost:${(fastify.server.address() as AddressInfo).port}`)
})
afterAll((done) => {
process.env = oldEnv
if (util.parseBool(process.env.RECORD)) {
nock.recorder.play()
}
nock.restore()
nock.cleanAll()
nock.enableNetConnect()
fastify.close(done)
})
describe('when making a request to crypto endpoint', () => {
const cryptoRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'crypto',
base: 'ETH',
quote: 'BTC',
},
}
it('should reply with success', async () => {
mockCryptoEndpoint()
const response = await req
.post('/')
.send(cryptoRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
describe('when making a request to marketcap endpoint', () => {
const marketCapRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'marketcap',
base: 'ETH',
},
}
it('should reply with success', async () => {
mockMarketCapEndpoint()
const response = await req
.post('/')
.send(marketCapRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
describe('when making a request to volume endpoint', () => {
const volumeRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'volume',
base: 'LINK',
quote: 'USD',
},
}
it('should reply with success', async () => {
mockVolumeEndpoint()
const response = await req
.post('/')
.send(volumeRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
describe('when making a request to balance endpoint', () => {
const balanceRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'balance',
addresses: [
{ address: '3EyjZ6CtEZEKyc719NZMyWaJpJG5jsVJL1' },
{ address: '38bzm6nhQMFJe71jJw1U7CbgNrVNpkonZF' },
],
dataPath: 'addresses',
},
}
it('should reply with success', async () => {
mockBalanceEndpoint()
const response = await req
.post('/')
.send(balanceRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
})