-
Notifications
You must be signed in to change notification settings - Fork 308
/
adapter.test.ts
142 lines (129 loc) · 3.82 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
137
138
139
140
141
142
import { AdapterRequest } from '@chainlink/ea-bootstrap'
import { server as startServer } from '../../src/index'
import {
mockCryptoEndpoint,
mockBalanceEndpoint,
mockMarketCapEndpoint,
mockVolumeEndpoint,
} from './fixtures'
import { setupExternalAdapterTest } from '@chainlink/ea-test-helpers'
import type { SuiteContext } from '@chainlink/ea-test-helpers'
import { SuperTest, Test } from 'supertest'
describe('amberdata', () => {
const context: SuiteContext = {
req: null,
server: startServer,
}
const envVariables = {
API_KEY: process.env.API_KEY || 'mock-api-key',
CACHE_ENABLED: 'false',
}
setupExternalAdapterTest(envVariables, context)
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 (context.req as SuperTest<Test>)
.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 crypto endpoint with an override from config/overrides.json', () => {
const cryptoRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'crypto',
base: 'LUNA',
quote: 'USD',
},
}
it('should reply with success', async () => {
mockCryptoEndpoint()
const response = await (context.req as SuperTest<Test>)
.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 (context.req as SuperTest<Test>)
.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 (context.req as SuperTest<Test>)
.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 (context.req as SuperTest<Test>)
.post('/')
.send(balanceRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
})