-
Notifications
You must be signed in to change notification settings - Fork 308
/
fixtures.ts
78 lines (75 loc) · 1.96 KB
/
fixtures.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
import nock from 'nock'
import { MockWebsocketServer } from '@chainlink/external-adapter-framework/util/testing-utils'
export const mockPriceSuccess = (): nock.Scope =>
nock('https://api-v2.intrinio.com', {
encodedQueryParams: true,
})
.get('/securities/AAPL/prices/realtime')
.query({ api_key: 'fake-api-key' })
.reply(
200,
{
last_price: 24.25,
last_time: '2022-02-23T17:58:46.261+00:00',
last_size: 1,
bid_price: 24.23,
bid_size: 233,
ask_price: 24.24,
ask_size: 118,
open_price: 25.74,
close_price: null,
high_price: 25.74,
low_price: 24.1,
exchange_volume: null,
market_volume: 34311,
updated_on: null,
source: 'intrinio_mx',
security: {
id: 'sec_gkZOZA',
ticker: 'ETD',
exchange_ticker: 'ETD:UN',
figi: 'BBG000BBVHG3',
composite_figi: 'BBG000BBVDT8',
},
},
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()
export const mockAuthResponse = (): nock.Scope =>
nock('https://realtime.intrinio.com', {
encodedQueryParams: true,
})
.get('/auth')
.query({ api_key: 'fake-api-key' })
.reply(200, 'fake-api-token', ['Transfer-Encoding', 'chunked'])
.persist()
export const mockWebSocketServer = (url: string) => {
const mockWsServer = new MockWebsocketServer(url, { mock: false })
mockWsServer.on('connection', (socket) => {
socket.on('message', () => {
socket.send(
JSON.stringify({
topic: 'iex:securities:AAPL',
payload: {
type: 'last',
timestamp: 1646336888.345325,
ticker: 'AAPL',
size: 100,
price: 166.91,
},
event: 'quote',
}),
)
})
})
return mockWsServer
}