|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+const request = require('supertest');
|
|
|
2
|
+const app = require('../src/app');
|
|
|
3
|
+const { LivePrice, Symbol, sequelize } = require('../src/models');
|
|
|
4
|
+
|
|
|
5
|
+describe('LivePrice Controller Integration Tests', () => {
|
|
|
6
|
+ beforeAll(async () => {
|
|
|
7
|
+ // Verify database connection
|
|
|
8
|
+ await sequelize.authenticate();
|
|
|
9
|
+
|
|
|
10
|
+ // Sync models
|
|
|
11
|
+ await sequelize.sync({ force: true });
|
|
|
12
|
+
|
|
|
13
|
+ // Create test symbols
|
|
|
14
|
+ await Symbol.bulkCreate([
|
|
|
15
|
+ { symbol: 'TEST1', exchange: 'TEST', instrumentType: 'forex' },
|
|
|
16
|
+ { symbol: 'TEST2', exchange: 'TEST', instrumentType: 'stock' }
|
|
|
17
|
+ ]);
|
|
|
18
|
+
|
|
|
19
|
+ // Get created symbols
|
|
|
20
|
+ const symbols = await Symbol.findAll();
|
|
|
21
|
+
|
|
|
22
|
+ // Create test live prices using actual symbol IDs
|
|
|
23
|
+ await LivePrice.bulkCreate([
|
|
|
24
|
+ {
|
|
|
25
|
+ symbolId: symbols[0].id,
|
|
|
26
|
+ price: 1.12348, // Added required price field
|
|
|
27
|
+ bid: 1.12345,
|
|
|
28
|
+ ask: 1.12350,
|
|
|
29
|
+ lastUpdated: new Date()
|
|
|
30
|
+ },
|
|
|
31
|
+ {
|
|
|
32
|
+ symbolId: symbols[1].id,
|
|
|
33
|
+ price: 100.55, // Added required price field
|
|
|
34
|
+ bid: 100.50,
|
|
|
35
|
+ ask: 100.60,
|
|
|
36
|
+ lastUpdated: new Date()
|
|
|
37
|
+ }
|
|
|
38
|
+ ]);
|
|
|
39
|
+ });
|
|
|
40
|
+
|
|
|
41
|
+ afterAll(async () => {
|
|
|
42
|
+ await LivePrice.destroy({ where: {} });
|
|
|
43
|
+ await Symbol.destroy({ where: {} });
|
|
|
44
|
+ await sequelize.close();
|
|
|
45
|
+ });
|
|
|
46
|
+
|
|
|
47
|
+ describe('GET /api/live-prices', () => {
|
|
|
48
|
+ it('should return all live prices with symbol associations', async () => {
|
|
|
49
|
+ const response = await request(app)
|
|
|
50
|
+ .get('/api/live-prices')
|
|
|
51
|
+ .expect(200);
|
|
|
52
|
+
|
|
|
53
|
+ expect(response.body.success).toBe(true);
|
|
|
54
|
+ expect(response.body.data.length).toBe(2);
|
|
|
55
|
+
|
|
|
56
|
+ // Verify association alias change
|
|
|
57
|
+ expect(response.body.data[0].livePriceSymbol).toBeDefined();
|
|
|
58
|
+ expect(response.body.data[0].livePriceSymbol.symbol).toBe('TEST1');
|
|
|
59
|
+ expect(response.body.data[1].livePriceSymbol.symbol).toBe('TEST2');
|
|
|
60
|
+ });
|
|
|
61
|
+ });
|
|
|
62
|
+
|
|
|
63
|
+ describe('GET /api/live-prices/:symbolId', () => {
|
|
|
64
|
+ it('should return live price for specific symbol', async () => {
|
|
|
65
|
+ const response = await request(app)
|
|
|
66
|
+ .get('/api/live-prices/1')
|
|
|
67
|
+ .expect(200);
|
|
|
68
|
+
|
|
|
69
|
+ expect(response.body.success).toBe(true);
|
|
|
70
|
+ expect(response.body.data.livePriceSymbol.symbol).toBe('TEST1');
|
|
|
71
|
+ });
|
|
|
72
|
+
|
|
|
73
|
+ it('should return 404 for invalid symbol ID', async () => {
|
|
|
74
|
+ await request(app)
|
|
|
75
|
+ .get('/api/live-prices/999')
|
|
|
76
|
+ .expect(404);
|
|
|
77
|
+ });
|
|
|
78
|
+ });
|
|
|
79
|
+
|
|
|
80
|
+ describe('GET /api/live-prices/exchange/:exchange', () => {
|
|
|
81
|
+ it('should return live prices filtered by exchange', async () => {
|
|
|
82
|
+ const response = await request(app)
|
|
|
83
|
+ .get('/api/live-prices/exchange/TEST')
|
|
|
84
|
+ .expect(200);
|
|
|
85
|
+
|
|
|
86
|
+ expect(response.body.success).toBe(true);
|
|
|
87
|
+ expect(response.body.data.length).toBe(2);
|
|
|
88
|
+ response.body.data.forEach(price => {
|
|
|
89
|
+ expect(price.livePriceSymbol.exchange).toBe('TEST');
|
|
|
90
|
+ });
|
|
|
91
|
+ });
|
|
|
92
|
+ });
|
|
|
93
|
+
|
|
|
94
|
+ describe('GET /api/live-prices/type/:type', () => {
|
|
|
95
|
+ it('should return live prices filtered by instrument type', async () => {
|
|
|
96
|
+ const response = await request(app)
|
|
|
97
|
+ .get('/api/live-prices/type/forex')
|
|
|
98
|
+ .expect(200);
|
|
|
99
|
+
|
|
|
100
|
+ expect(response.body.success).toBe(true);
|
|
|
101
|
+ expect(response.body.data.length).toBe(1);
|
|
|
102
|
+ expect(response.body.data[0].livePriceSymbol.instrumentType).toBe('forex');
|
|
|
103
|
+ });
|
|
|
104
|
+ });
|
|
|
105
|
+});
|