forked from SmartDropLabs/smartdrop-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriceOracleCircuit.test.js
More file actions
48 lines (39 loc) · 1.46 KB
/
Copy pathpriceOracleCircuit.test.js
File metadata and controls
48 lines (39 loc) · 1.46 KB
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
'use strict';
jest.mock('../src/logger', () => ({
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
}));
jest.mock('../src/services/cache', () => ({
get: jest.fn(),
set: jest.fn(),
del: jest.fn(),
getClient: jest.fn(),
isConnected: jest.fn(),
}));
const mockCoingeckoCircuitState = { source: 'coingecko', open: true, openUntil: '2026-01-01T00:15:00.000Z' };
const mockCmcCircuitState = { source: 'coinmarketcap', open: false, openUntil: null };
jest.mock('../src/services/sources/stellarDex', () => ({
fetchPrice: jest.fn(),
// Deliberately no getCircuitState — stellar_dex has no auth-failure mode.
}));
jest.mock('../src/services/sources/coingecko', () => ({
fetchPrice: jest.fn(),
getCircuitState: jest.fn(() => mockCoingeckoCircuitState),
}));
jest.mock('../src/services/sources/coinmarketcap', () => ({
fetchPrice: jest.fn(),
getCircuitState: jest.fn(() => mockCmcCircuitState),
}));
const priceOracle = require('../src/services/priceOracle');
describe('priceOracle.getSourceCircuitStates', () => {
test('returns the circuit state for every source that has one', () => {
const states = priceOracle.getSourceCircuitStates();
expect(states).toEqual([mockCoingeckoCircuitState, mockCmcCircuitState]);
});
test('omits sources with no getCircuitState (e.g. stellar_dex)', () => {
const states = priceOracle.getSourceCircuitStates();
expect(states.find((s) => s.source === 'stellar_dex')).toBeUndefined();
});
});