laplace-api 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +37 -0
- package/.github/workflows/test.yml +25 -0
- package/README.md +461 -2
- package/package.json +1 -1
- package/src/client/broker.ts +9 -7
- package/src/client/capital_increase.ts +7 -12
- package/src/client/collections.ts +57 -28
- package/src/client/financial_fundamentals.ts +2 -5
- package/src/client/financial_ratios.ts +114 -95
- package/src/client/live-price-web-socket.ts +24 -9
- package/src/client/live-price.ts +228 -46
- package/src/client/politician.ts +75 -0
- package/src/client/stocks.ts +73 -0
- package/src/test/broker.test.ts +583 -148
- package/src/test/capital_increase.test.ts +186 -39
- package/src/test/collections.test.ts +445 -60
- package/src/test/custom_theme.test.ts +242 -60
- package/src/test/financial_fundamentals.test.ts +297 -56
- package/src/test/financial_ratios.test.ts +363 -92
- package/src/test/funds.test.ts +275 -68
- package/src/test/key-insight.test.ts +81 -19
- package/src/test/live-price.test.ts +425 -64
- package/src/test/politician.test.ts +253 -0
- package/src/test/readme.test.ts +481 -0
- package/src/test/search.test.ts +301 -65
- package/src/test/stocks.test.ts +764 -152
- package/src/utilities/configuration.ts +23 -10
- package/src/utilities/test.env +2 -2
|
@@ -9,7 +9,66 @@ import {
|
|
|
9
9
|
import { Stock, StockClient } from "../client/stocks";
|
|
10
10
|
import "./client_test_suite";
|
|
11
11
|
import { validateCollection } from "./helpers";
|
|
12
|
-
import { Locale, Region, SortBy } from "../client/collections";
|
|
12
|
+
import { Locale, Region, SortBy, Collection, CollectionDetail } from "../client/collections";
|
|
13
|
+
import { AssetType } from "../client/stocks";
|
|
14
|
+
|
|
15
|
+
const mockStocks: Stock[] = [
|
|
16
|
+
{
|
|
17
|
+
id: "stock1",
|
|
18
|
+
name: "Tüpraş",
|
|
19
|
+
symbol: "TUPRS",
|
|
20
|
+
assetType: AssetType.Stock,
|
|
21
|
+
sectorId: "sector1",
|
|
22
|
+
industryId: "industry1",
|
|
23
|
+
updatedDate: "2024-03-14T10:00:00Z",
|
|
24
|
+
active: true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "stock2",
|
|
28
|
+
name: "Garanti Bankası",
|
|
29
|
+
symbol: "GARAN",
|
|
30
|
+
assetType: AssetType.Stock,
|
|
31
|
+
sectorId: "sector2",
|
|
32
|
+
industryId: "industry2",
|
|
33
|
+
updatedDate: "2024-03-14T10:00:00Z",
|
|
34
|
+
active: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "stock3",
|
|
38
|
+
name: "Türk Hava Yolları",
|
|
39
|
+
symbol: "THYAO",
|
|
40
|
+
assetType: AssetType.Stock,
|
|
41
|
+
sectorId: "sector3",
|
|
42
|
+
industryId: "industry3",
|
|
43
|
+
updatedDate: "2024-03-14T10:00:00Z",
|
|
44
|
+
active: true
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const mockCustomThemes: Collection[] = [
|
|
49
|
+
{
|
|
50
|
+
id: "theme1",
|
|
51
|
+
title: "Enerji Şirketleri",
|
|
52
|
+
description: "Türkiye'nin önde gelen enerji şirketleri",
|
|
53
|
+
region: [Region.Tr],
|
|
54
|
+
imageUrl: "https://example.com/energy.jpg",
|
|
55
|
+
avatarUrl: "https://example.com/energy-avatar.jpg",
|
|
56
|
+
numStocks: 5,
|
|
57
|
+
status: CollectionStatus.Active
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const mockCustomThemeDetail: CollectionDetail = {
|
|
62
|
+
id: "theme1",
|
|
63
|
+
title: "Enerji Şirketleri",
|
|
64
|
+
description: "Türkiye'nin önde gelen enerji şirketleri",
|
|
65
|
+
region: [Region.Tr],
|
|
66
|
+
imageUrl: "https://example.com/energy.jpg",
|
|
67
|
+
avatarUrl: "https://example.com/energy-avatar.jpg",
|
|
68
|
+
numStocks: 2,
|
|
69
|
+
status: CollectionStatus.Active,
|
|
70
|
+
stocks: [mockStocks[0], mockStocks[1]]
|
|
71
|
+
};
|
|
13
72
|
|
|
14
73
|
describe("CustomTheme", () => {
|
|
15
74
|
let client: CustomThemeClient;
|
|
@@ -28,68 +87,191 @@ describe("CustomTheme", () => {
|
|
|
28
87
|
stocksClient = new StockClient(config, logger);
|
|
29
88
|
});
|
|
30
89
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
90
|
+
describe("Integration Tests", () => {
|
|
91
|
+
test("GetAllCustomThemes", async () => {
|
|
92
|
+
const resp = await client.getAllCustomThemes(Locale.Tr);
|
|
93
|
+
expect(resp).not.toBeEmpty();
|
|
94
|
+
|
|
95
|
+
const firstTheme = resp[0];
|
|
96
|
+
validateCollection(firstTheme);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('CreateUpdateDeleteCustomTheme', async () => {
|
|
100
|
+
const stocks = await stocksClient.getAllStocks(Region.Tr);
|
|
101
|
+
expect(stocks).not.toBeEmpty();
|
|
102
|
+
|
|
103
|
+
const createParams: CreateCustomThemeParams = {
|
|
104
|
+
title: {
|
|
105
|
+
[Locale.Tr]: 'Test Custom Theme',
|
|
106
|
+
},
|
|
107
|
+
description: {
|
|
108
|
+
[Locale.Tr]: 'Test Custom Theme Description',
|
|
109
|
+
},
|
|
110
|
+
region: [Region.Tr],
|
|
111
|
+
image_url: 'Test Custom Theme Image URL',
|
|
112
|
+
image: 'Test Custom Theme Image',
|
|
113
|
+
avatar_url: 'Test Custom Theme Avatar Image',
|
|
114
|
+
stocks: [stocks[0].id, stocks[1].id],
|
|
115
|
+
status: CollectionStatus.Active,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const id = await testCreateCustomTheme(client, createParams);
|
|
119
|
+
await testGetDetails(id, Locale.Tr, client, createParams);
|
|
120
|
+
|
|
121
|
+
let updateParams: UpdateCustomThemeParams = {
|
|
122
|
+
stockIds: [stocks[0].id, stocks[2].id],
|
|
123
|
+
};
|
|
124
|
+
await testUpdateCustomTheme(id, client, updateParams);
|
|
125
|
+
applyUpdateParams(updateParams, createParams);
|
|
126
|
+
await testGetDetails(id, Locale.Tr, client, createParams);
|
|
127
|
+
|
|
128
|
+
updateParams = {
|
|
129
|
+
title: {
|
|
130
|
+
[Locale.Tr]: 'Test Custom Theme Title Updated',
|
|
131
|
+
[Locale.En]: 'Test Custom Theme Title Updated',
|
|
132
|
+
},
|
|
133
|
+
description: {
|
|
134
|
+
[Locale.Tr]: 'Test Custom Theme Description Updated',
|
|
135
|
+
[Locale.En]: 'Test Custom Theme Description Updated',
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
await testUpdateCustomTheme(id, client, updateParams);
|
|
139
|
+
applyUpdateParams(updateParams, createParams);
|
|
140
|
+
await testGetDetails(id, Locale.Tr, client, createParams);
|
|
141
|
+
await testGetDetails(id, Locale.En, client, createParams);
|
|
34
142
|
|
|
35
|
-
|
|
36
|
-
|
|
143
|
+
updateParams = {
|
|
144
|
+
status: CollectionStatus.Inactive,
|
|
145
|
+
};
|
|
146
|
+
await testUpdateCustomTheme(id, client, updateParams);
|
|
147
|
+
applyUpdateParams(updateParams, createParams);
|
|
148
|
+
await testGetDetails(id, Locale.Tr, client, createParams);
|
|
149
|
+
|
|
150
|
+
await testDeleteCustomTheme(id, client);
|
|
151
|
+
await expect(client.getCustomThemeDetail(id, Locale.Tr, SortBy.PriceChange)).rejects.toThrow();
|
|
152
|
+
}, 15000);
|
|
37
153
|
});
|
|
38
154
|
|
|
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
|
-
|
|
155
|
+
describe("Mock Tests", () => {
|
|
156
|
+
beforeEach(() => {
|
|
157
|
+
jest.clearAllMocks();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("getAllCustomThemes", () => {
|
|
161
|
+
test("should return custom themes list with mock data", async () => {
|
|
162
|
+
jest.spyOn(client, 'getAllCustomThemes').mockResolvedValue(mockCustomThemes);
|
|
163
|
+
|
|
164
|
+
const resp = await client.getAllCustomThemes(Locale.Tr);
|
|
165
|
+
|
|
166
|
+
expect(resp).toHaveLength(1);
|
|
167
|
+
|
|
168
|
+
const theme = resp[0];
|
|
169
|
+
expect(theme.id).toBe("theme1");
|
|
170
|
+
expect(theme.title).toBe("Enerji Şirketleri");
|
|
171
|
+
expect(theme.description).toBe("Türkiye'nin önde gelen enerji şirketleri");
|
|
172
|
+
expect(theme.region).toEqual([Region.Tr]);
|
|
173
|
+
expect(theme.imageUrl).toBe("https://example.com/energy.jpg");
|
|
174
|
+
expect(theme.avatarUrl).toBe("https://example.com/energy-avatar.jpg");
|
|
175
|
+
expect(theme.numStocks).toBe(5);
|
|
176
|
+
expect(theme.status).toBe(CollectionStatus.Active);
|
|
177
|
+
|
|
178
|
+
expect(client.getAllCustomThemes).toHaveBeenCalledWith(Locale.Tr);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("getCustomThemeDetail", () => {
|
|
183
|
+
test("should return custom theme detail with mock data", async () => {
|
|
184
|
+
jest.spyOn(client, 'getCustomThemeDetail').mockResolvedValue(mockCustomThemeDetail);
|
|
185
|
+
|
|
186
|
+
const resp = await client.getCustomThemeDetail("theme1", Locale.Tr, null);
|
|
187
|
+
|
|
188
|
+
expect(resp.id).toBe("theme1");
|
|
189
|
+
expect(resp.title).toBe("Enerji Şirketleri");
|
|
190
|
+
expect(resp.description).toBe("Türkiye'nin önde gelen enerji şirketleri");
|
|
191
|
+
expect(resp.region).toEqual([Region.Tr]);
|
|
192
|
+
expect(resp.imageUrl).toBe("https://example.com/energy.jpg");
|
|
193
|
+
expect(resp.avatarUrl).toBe("https://example.com/energy-avatar.jpg");
|
|
194
|
+
expect(resp.numStocks).toBe(2);
|
|
195
|
+
expect(resp.status).toBe(CollectionStatus.Active);
|
|
196
|
+
expect(resp.stocks).toHaveLength(2);
|
|
197
|
+
expect(resp.stocks[0].symbol).toBe("TUPRS");
|
|
198
|
+
expect(resp.stocks[1].symbol).toBe("GARAN");
|
|
199
|
+
|
|
200
|
+
expect(client.getCustomThemeDetail).toHaveBeenCalledWith("theme1", Locale.Tr, null);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("should handle sort by price change", async () => {
|
|
204
|
+
jest.spyOn(client, 'getCustomThemeDetail').mockResolvedValue(mockCustomThemeDetail);
|
|
205
|
+
|
|
206
|
+
await client.getCustomThemeDetail("theme1", Locale.Tr, SortBy.PriceChange);
|
|
207
|
+
|
|
208
|
+
expect(client.getCustomThemeDetail).toHaveBeenCalledWith("theme1", Locale.Tr, SortBy.PriceChange);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe("createCustomTheme", () => {
|
|
213
|
+
test("should create custom theme with mock data", async () => {
|
|
214
|
+
const createParams: CreateCustomThemeParams = {
|
|
215
|
+
title: {
|
|
216
|
+
[Locale.Tr]: "Yeni Tema",
|
|
217
|
+
[Locale.En]: "New Theme"
|
|
218
|
+
},
|
|
219
|
+
description: {
|
|
220
|
+
[Locale.Tr]: "Tema açıklaması",
|
|
221
|
+
[Locale.En]: "Theme description"
|
|
222
|
+
},
|
|
223
|
+
region: [Region.Tr],
|
|
224
|
+
image_url: "https://example.com/new-theme.jpg",
|
|
225
|
+
avatar_url: "https://example.com/new-theme-avatar.jpg",
|
|
226
|
+
stocks: [mockStocks[0].id, mockStocks[1].id],
|
|
227
|
+
status: CollectionStatus.Active
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
jest.spyOn(client, 'createCustomTheme').mockResolvedValue("new-theme-id");
|
|
231
|
+
|
|
232
|
+
const resp = await client.createCustomTheme(createParams);
|
|
233
|
+
|
|
234
|
+
expect(resp).toBe("new-theme-id");
|
|
235
|
+
|
|
236
|
+
expect(client.createCustomTheme).toHaveBeenCalledWith(createParams);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("updateCustomTheme", () => {
|
|
241
|
+
test("should update custom theme with mock data", async () => {
|
|
242
|
+
const updateParams: UpdateCustomThemeParams = {
|
|
243
|
+
title: {
|
|
244
|
+
[Locale.Tr]: "Güncellenmiş Tema",
|
|
245
|
+
[Locale.En]: "Updated Theme"
|
|
246
|
+
},
|
|
247
|
+
stockIds: [mockStocks[0].id, mockStocks[2].id]
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
jest.spyOn(client, 'updateCustomTheme').mockResolvedValue(undefined);
|
|
251
|
+
|
|
252
|
+
await client.updateCustomTheme("theme1", updateParams);
|
|
253
|
+
|
|
254
|
+
expect(client.updateCustomTheme).toHaveBeenCalledWith("theme1", updateParams);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("deleteCustomTheme", () => {
|
|
259
|
+
test("should delete custom theme", async () => {
|
|
260
|
+
jest.spyOn(client, 'deleteCustomTheme').mockResolvedValue(undefined);
|
|
261
|
+
|
|
262
|
+
await client.deleteCustomTheme("theme1");
|
|
263
|
+
|
|
264
|
+
expect(client.deleteCustomTheme).toHaveBeenCalledWith("theme1");
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("should handle delete error", async () => {
|
|
268
|
+
jest.spyOn(client, 'deleteCustomTheme').mockRejectedValue(new Error("Theme not found"));
|
|
269
|
+
|
|
270
|
+
await expect(client.deleteCustomTheme("invalid-theme"))
|
|
271
|
+
.rejects.toThrow("Theme not found");
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|
|
93
275
|
});
|
|
94
276
|
|
|
95
277
|
async function testCreateCustomTheme(client: CustomThemeClient, createParams: CreateCustomThemeParams): Promise<string> {
|