laplace-api 3.1.0 → 4.1.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.
@@ -1,15 +1,61 @@
1
- import { Logger } from 'winston';
2
- import { LaplaceConfiguration } from '../utilities/configuration';
3
- import { CapitalIncreaseClient } from '../client/capital_increase';
4
- import { Region } from '../client/collections';
5
- import './client_test_suite';
1
+ import { Logger } from "winston";
2
+ import { LaplaceConfiguration } from "../utilities/configuration";
3
+ import {
4
+ CapitalIncrease,
5
+ CapitalIncreaseClient,
6
+ PaginatedResponse,
7
+ } from "../client/capital_increase";
8
+ import "./client_test_suite";
9
+ import { Region } from "../client/collections";
6
10
 
11
+ const mockCapitalIncrease: CapitalIncrease = {
12
+ id: 12345,
13
+ boardDecisionDate: "2024-03-01",
14
+ registeredCapitalCeiling: "1000000000",
15
+ currentCapital: "500000000",
16
+ targetCapital: "750000000",
17
+ types: ["RIGHTS", "BONUS"],
18
+ spkApplicationResult: "APPROVED",
19
+ spkApplicationDate: "2024-03-05",
20
+ spkApprovalDate: "2024-03-15",
21
+ paymentDate: "2024-04-01",
22
+ registrationDate: "2024-03-20",
23
+ specifiedCurrency: "TRY",
24
+ symbol: "TUPRS",
25
+ relatedDisclosureIds: [1001, 1002],
26
+ rightsRate: "0.5",
27
+ rightsPrice: "100",
28
+ rightsTotalAmount: "250000000",
29
+ rightsStartDate: "2024-04-01",
30
+ rightsEndDate: "2024-04-15",
31
+ rightsLastSellDate: "2024-04-14",
32
+ bonusRate: "0.2",
33
+ bonusTotalAmount: "100000000",
34
+ bonusStartDate: "2024-04-01",
35
+ bonusDividendRate: "0.1",
36
+ bonusDividendTotalAmount: "50000000",
37
+ externalCapitalIncreaseAmount: "150000000",
38
+ externalCapitalIncreaseRate: "0.3"
39
+ };
7
40
 
8
- describe('Capital Increase', () => {
41
+ const mockCapitalIncrease2: CapitalIncrease = {
42
+ ...mockCapitalIncrease,
43
+ id: 12346,
44
+ symbol: "GARAN",
45
+ boardDecisionDate: "2024-03-10",
46
+ };
47
+
48
+ const mockPaginatedResponse: PaginatedResponse<CapitalIncrease> = {
49
+ recordCount: 2,
50
+ items: [mockCapitalIncrease, mockCapitalIncrease2]
51
+ };
52
+
53
+ const mockActiveRights: CapitalIncrease[] = [mockCapitalIncrease];
54
+
55
+ describe("Capital Increase", () => {
9
56
  let client: CapitalIncreaseClient;
10
57
 
11
58
  beforeAll(() => {
12
- // Assuming global.testSuite is set up as in the previous example
13
59
  const config = (global as any).testSuite.config as LaplaceConfiguration;
14
60
  const logger: Logger = {
15
61
  info: jest.fn(),
@@ -21,16 +67,221 @@ describe('Capital Increase', () => {
21
67
  client = new CapitalIncreaseClient(config, logger);
22
68
  });
23
69
 
24
- test('GetAllCapitalIncreases', async () => {
25
- await client.getAllCapitalIncreases(1, 10, Region.Tr, );
26
- });
70
+ describe("Integration Tests", () => {
71
+ test("GetAllCapitalIncreases", async () => {
72
+ const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
27
73
 
28
- test('GetCapitalIncreasesForInstrument', async () => {
29
- await client.getCapitalIncreasesForInstrument("TUPRS", 1, 10, Region.Tr);
30
- });
74
+ expect(resp).toBeDefined();
75
+ expect(typeof resp.recordCount).toBe("number");
76
+ expect(Array.isArray(resp.items)).toBe(true);
77
+
78
+ if (resp.items.length > 0) {
79
+ const firstItem = resp.items[0];
80
+ validateCapitalIncrease(firstItem);
81
+ }
82
+ });
83
+
84
+ test("GetCapitalIncreasesForInstrument", async () => {
85
+ const resp = await client.getCapitalIncreasesForInstrument(
86
+ "TUPRS",
87
+ 1,
88
+ 10,
89
+ Region.Tr
90
+ );
91
+
92
+ expect(resp).toBeDefined();
93
+ expect(typeof resp.recordCount).toBe("number");
94
+ expect(Array.isArray(resp.items)).toBe(true);
95
+
96
+ if (resp.items.length > 0) {
97
+ const firstItem = resp.items[0];
98
+ validateCapitalIncrease(firstItem);
99
+ expect(firstItem.symbol).toBe("TUPRS");
100
+ }
101
+ });
102
+
103
+ test("GetActiveRightsForInstrument", async () => {
104
+ const resp = await client.getActiveRightsForInstrument(
105
+ "TUPRS",
106
+ "2024-01-01",
107
+ Region.Tr
108
+ );
31
109
 
32
- test('GetActiveRightsForInstrument', async () => {
33
- await client.getActiveRightsForInstrument("TUPRS", "2024-01-01", Region.Tr);
110
+ expect(Array.isArray(resp)).toBe(true);
111
+
112
+ if (resp.length > 0) {
113
+ const firstItem = resp[0];
114
+ validateCapitalIncrease(firstItem);
115
+ expect(firstItem.symbol).toBe("TUPRS");
116
+ }
117
+ });
34
118
  });
35
119
 
120
+ describe("Mock Tests", () => {
121
+ beforeEach(() => {
122
+ jest.clearAllMocks();
123
+ });
124
+
125
+ describe("getAllCapitalIncreases", () => {
126
+ test("should return paginated capital increases", async () => {
127
+ jest.spyOn(client, 'getAllCapitalIncreases').mockResolvedValue(mockPaginatedResponse);
128
+
129
+ const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
130
+
131
+ expect(resp.recordCount).toBe(2);
132
+ expect(resp.items).toHaveLength(2);
133
+
134
+ const firstItem = resp.items[0];
135
+ expect(firstItem.symbol).toBe("TUPRS");
136
+ expect(firstItem.types).toEqual(["RIGHTS", "BONUS"]);
137
+ expect(firstItem.currentCapital).toBe("500000000");
138
+ expect(firstItem.targetCapital).toBe("750000000");
139
+
140
+ expect(client.getAllCapitalIncreases).toHaveBeenCalledWith(1, 10, Region.Tr);
141
+ });
142
+
143
+ test("should handle empty response", async () => {
144
+ const emptyResponse: PaginatedResponse<CapitalIncrease> = {
145
+ recordCount: 0,
146
+ items: []
147
+ };
148
+ jest.spyOn(client, 'getAllCapitalIncreases').mockResolvedValue(emptyResponse);
149
+
150
+ const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
151
+
152
+ expect(resp.recordCount).toBe(0);
153
+ expect(resp.items).toHaveLength(0);
154
+ });
155
+ });
156
+
157
+ describe("getCapitalIncreasesForInstrument", () => {
158
+ test("should return capital increases for specific instrument", async () => {
159
+ const singleInstrumentResponse: PaginatedResponse<CapitalIncrease> = {
160
+ recordCount: 1,
161
+ items: [mockCapitalIncrease]
162
+ };
163
+ jest.spyOn(client, 'getCapitalIncreasesForInstrument').mockResolvedValue(singleInstrumentResponse);
164
+
165
+ const resp = await client.getCapitalIncreasesForInstrument("TUPRS", 1, 10, Region.Tr);
166
+
167
+ expect(resp.recordCount).toBe(1);
168
+ expect(resp.items).toHaveLength(1);
169
+ expect(resp.items[0].symbol).toBe("TUPRS");
170
+ expect(resp.items[0].boardDecisionDate).toBe("2024-03-01");
171
+
172
+ expect(client.getCapitalIncreasesForInstrument).toHaveBeenCalledWith("TUPRS", 1, 10, Region.Tr);
173
+ });
174
+
175
+ test("should handle instrument with no capital increases", async () => {
176
+ const emptyResponse: PaginatedResponse<CapitalIncrease> = {
177
+ recordCount: 0,
178
+ items: []
179
+ };
180
+ jest.spyOn(client, 'getCapitalIncreasesForInstrument').mockResolvedValue(emptyResponse);
181
+
182
+ const resp = await client.getCapitalIncreasesForInstrument("INVALID", 1, 10, Region.Tr);
183
+
184
+ expect(resp.recordCount).toBe(0);
185
+ expect(resp.items).toHaveLength(0);
186
+ });
187
+ });
188
+
189
+ describe("getActiveRightsForInstrument", () => {
190
+ test("should return active rights for specific instrument", async () => {
191
+ jest.spyOn(client, 'getActiveRightsForInstrument').mockResolvedValue(mockActiveRights);
192
+
193
+ const resp = await client.getActiveRightsForInstrument("TUPRS", "2024-03-14", Region.Tr);
194
+
195
+ expect(resp).toHaveLength(1);
196
+ expect(resp[0].symbol).toBe("TUPRS");
197
+ expect(resp[0].rightsStartDate).toBe("2024-04-01");
198
+ expect(resp[0].rightsEndDate).toBe("2024-04-15");
199
+
200
+ expect(client.getActiveRightsForInstrument).toHaveBeenCalledWith("TUPRS", "2024-03-14", Region.Tr);
201
+ });
202
+
203
+ test("should handle instrument with no active rights", async () => {
204
+ jest.spyOn(client, 'getActiveRightsForInstrument').mockResolvedValue([]);
205
+
206
+ const resp = await client.getActiveRightsForInstrument("INVALID", "2024-03-14", Region.Tr);
207
+
208
+ expect(resp).toHaveLength(0);
209
+ });
210
+
211
+ test("should handle invalid date format", async () => {
212
+ jest.spyOn(client, 'getActiveRightsForInstrument').mockRejectedValue(new Error("Invalid date format"));
213
+
214
+ await expect(client.getActiveRightsForInstrument("TUPRS", "invalid-date", Region.Tr))
215
+ .rejects.toThrow("Invalid date format");
216
+ });
217
+ });
218
+ });
36
219
  });
220
+
221
+ function validateCapitalIncrease(item: CapitalIncrease) {
222
+ expect(typeof item.id).toBe("number");
223
+ expect(typeof item.boardDecisionDate).toBe("string");
224
+ expect(typeof item.registeredCapitalCeiling).toBe("string");
225
+ expect(typeof item.currentCapital).toBe("string");
226
+ expect(typeof item.targetCapital).toBe("string");
227
+ expect(Array.isArray(item.types)).toBe(true);
228
+
229
+ if (item.spkApplicationResult !== null) {
230
+ expect(typeof item.spkApplicationResult).toBe("string");
231
+ }
232
+
233
+ if (item.spkApplicationDate !== null) {
234
+ expect(typeof item.spkApplicationDate).toBe("string");
235
+ }
236
+
237
+ if (item.spkApprovalDate !== null) {
238
+ expect(typeof item.spkApprovalDate).toBe("string");
239
+ }
240
+
241
+ if (item.paymentDate !== null) {
242
+ expect(typeof item.paymentDate).toBe("string");
243
+ }
244
+
245
+ if (item.registrationDate !== null) {
246
+ expect(typeof item.registrationDate).toBe("string");
247
+ }
248
+
249
+ expect(typeof item.specifiedCurrency).toBe("string");
250
+ expect(typeof item.symbol).toBe("string");
251
+ expect(Array.isArray(item.relatedDisclosureIds)).toBe(true);
252
+ expect(typeof item.rightsRate).toBe("string");
253
+ expect(typeof item.rightsPrice).toBe("string");
254
+ expect(typeof item.rightsTotalAmount).toBe("string");
255
+
256
+ if (item.rightsStartDate !== null) {
257
+ expect(typeof item.rightsStartDate).toBe("string");
258
+ }
259
+
260
+ if (item.rightsEndDate !== null) {
261
+ expect(typeof item.rightsEndDate).toBe("string");
262
+ }
263
+
264
+ if (item.rightsLastSellDate !== null) {
265
+ expect(typeof item.rightsLastSellDate).toBe("string");
266
+ }
267
+
268
+ expect(typeof item.bonusRate).toBe("string");
269
+ expect(typeof item.bonusTotalAmount).toBe("string");
270
+
271
+ if (item.bonusStartDate !== null) {
272
+ expect(typeof item.bonusStartDate).toBe("string");
273
+ }
274
+
275
+ expect(typeof item.bonusDividendRate).toBe("string");
276
+ expect(typeof item.bonusDividendTotalAmount).toBe("string");
277
+ expect(typeof item.externalCapitalIncreaseAmount).toBe("string");
278
+ expect(typeof item.externalCapitalIncreaseRate).toBe("string");
279
+
280
+ item.types.forEach(type => {
281
+ expect(typeof type).toBe("string");
282
+ });
283
+
284
+ item.relatedDisclosureIds.forEach(id => {
285
+ expect(typeof id).toBe("number");
286
+ });
287
+ }