forked from smartcontractkit/external-adapters-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.test.ts
96 lines (84 loc) · 2.46 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
import { AdapterRequest } from '@chainlink/ea-bootstrap'
import * as process from 'process'
import { server as startServer } from '../../src'
import { mockBalanceResponse, mockBcInfoResponse, mockCryptoResponse } from './fixtures'
import { setupExternalAdapterTest } from '@chainlink/ea-test-helpers'
import type { SuiteContext } from '@chainlink/ea-test-helpers'
import { SuperTest, Test } from 'supertest'
describe('execute', () => {
const context: SuiteContext = {
req: null,
server: startServer,
}
const envVariables = {
CACHE_ENABLED: 'false',
API_KEY: process.env.API_KEY || 'fake-api-key',
}
setupExternalAdapterTest(envVariables, context)
describe('balance endpoint', () => {
const balanceRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'balance',
addresses: [
{
address: 'n4VQ5YdHf7hLQ2gWQYYrcxoE5B7nWuDFNF',
chain: 'testnet',
},
],
dataPath: 'addresses',
},
}
it('should return success', async () => {
mockBalanceResponse()
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()
})
})
describe('bc_info endpoint', () => {
const bcInfoRequest: AdapterRequest = {
id: '1',
data: {
endpoint: 'difficulty',
blockchain: 'BTC',
},
}
it('should return success', async () => {
mockBcInfoResponse()
const response = await (context.req as SuperTest<Test>)
.post('/')
.send(bcInfoRequest)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
describe('crypto endpoint', () => {
const cryptoRequest: AdapterRequest = {
id: '1',
data: {
base: 'BTC',
quote: 'USD',
},
}
it('should return success', async () => {
mockCryptoResponse()
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()
})
})
})