-
Notifications
You must be signed in to change notification settings - Fork 308
/
allocation.test.ts
73 lines (65 loc) · 1.86 KB
/
allocation.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
import nock from 'nock'
import { getTotalAllocations } from '../../src'
import { mockSourceEAResponse } from './fixtures'
describe('execute', () => {
const allocations = [
{
symbol: 'wBTC',
balance: 100000000,
decimals: 8,
},
{
symbol: 'DAI',
balance: '1000000000000000000',
},
]
const SOURCE_EA_URL = 'http://localhost:8081'
afterAll(() => {
nock.restore()
nock.cleanAll()
nock.enableNetConnect()
})
describe('price method', () => {
mockSourceEAResponse(SOURCE_EA_URL)
it(`should return the correct data for price method`, async () => {
const resp = await getTotalAllocations({
allocations,
sourceUrl: SOURCE_EA_URL,
})
expect(resp.result).toBe(260.54)
expect(resp).toMatchSnapshot()
})
it(`should return the correct data for price method with explicit quote and method`, async () => {
const resp = await getTotalAllocations({
allocations,
sourceUrl: SOURCE_EA_URL,
method: 'price',
quote: 'EUR',
})
expect(resp.result).toBe(260.54)
expect(resp).toMatchSnapshot()
})
})
describe('marketcap method', () => {
mockSourceEAResponse(SOURCE_EA_URL, 'marketcap')
it(`should return the correct data for marketcap method`, async () => {
const resp = await getTotalAllocations({
allocations,
sourceUrl: SOURCE_EA_URL,
method: 'marketcap',
})
expect(resp.result).toBe(260.54)
expect(resp).toMatchSnapshot()
})
it(`should return the correct data for marketcap method with explicit quote`, async () => {
const resp = await getTotalAllocations({
allocations,
sourceUrl: SOURCE_EA_URL,
method: 'marketcap',
quote: 'EUR',
})
expect(resp.result).toBe(260.54)
expect(resp).toMatchSnapshot()
})
})
})