laplace-api 4.8.0 → 5.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.
@@ -8,7 +8,7 @@ import {
8
8
  import "./client_test_suite";
9
9
  import { Region } from "../client/collections";
10
10
 
11
- const mockCapitalIncrease: CapitalIncrease = {
11
+ const mockCapitalIncrease = {
12
12
  id: 12345,
13
13
  boardDecisionDate: "2024-03-01",
14
14
  registeredCapitalCeiling: "1000000000",
@@ -38,16 +38,9 @@ const mockCapitalIncrease: CapitalIncrease = {
38
38
  externalCapitalIncreaseRate: "0.3"
39
39
  };
40
40
 
41
- const mockCapitalIncrease2: CapitalIncrease = {
42
- ...mockCapitalIncrease,
43
- id: 12346,
44
- symbol: "GARAN",
45
- boardDecisionDate: "2024-03-10",
46
- };
47
-
48
41
  const mockPaginatedResponse: PaginatedResponse<CapitalIncrease> = {
49
42
  recordCount: 2,
50
- items: [mockCapitalIncrease, mockCapitalIncrease2]
43
+ items: [mockCapitalIncrease]
51
44
  };
52
45
 
53
46
  const mockActiveRights: CapitalIncrease[] = [mockCapitalIncrease];
@@ -69,7 +62,7 @@ describe("Capital Increase", () => {
69
62
 
70
63
  describe("Integration Tests", () => {
71
64
  test("GetAllCapitalIncreases", async () => {
72
- const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
65
+ const resp = await client.getAllCapitalIncreases(10, Region.Tr, 1);
73
66
 
74
67
  expect(resp).toBeDefined();
75
68
  expect(typeof resp.recordCount).toBe("number");
@@ -84,9 +77,9 @@ describe("Capital Increase", () => {
84
77
  test("GetCapitalIncreasesForInstrument", async () => {
85
78
  const resp = await client.getCapitalIncreasesForInstrument(
86
79
  "TUPRS",
87
- 1,
88
80
  10,
89
- Region.Tr
81
+ Region.Tr,
82
+ 1
90
83
  );
91
84
 
92
85
  expect(resp).toBeDefined();
@@ -104,7 +97,6 @@ describe("Capital Increase", () => {
104
97
  const resp = await client.getActiveRightsForInstrument(
105
98
  "TUPRS",
106
99
  "2024-01-01",
107
- Region.Tr
108
100
  );
109
101
 
110
102
  expect(Array.isArray(resp)).toBe(true);
@@ -118,104 +110,123 @@ describe("Capital Increase", () => {
118
110
  });
119
111
 
120
112
  describe("Mock Tests", () => {
113
+ const region = Region.Tr;
114
+ const page = 1;
115
+ const size = 10;
116
+ const symbol = "TUPRS";
117
+ const date = "2024-03-14";
118
+
119
+ let client: CapitalIncreaseClient;
120
+ let cli: { request: jest.Mock };
121
+
121
122
  beforeEach(() => {
122
- jest.clearAllMocks();
123
+ cli = { request: jest.fn() };
124
+
125
+ const config = (global as any).testSuite.config as LaplaceConfiguration;
126
+ const logger: Logger = {
127
+ info: jest.fn(),
128
+ error: jest.fn(),
129
+ warn: jest.fn(),
130
+ debug: jest.fn(),
131
+ } as unknown as Logger;
132
+
133
+ client = new CapitalIncreaseClient(config, logger, cli as any);
123
134
  });
124
-
135
+
125
136
  describe("getAllCapitalIncreases", () => {
126
- test("should return paginated capital increases", async () => {
127
- jest.spyOn(client, 'getAllCapitalIncreases').mockResolvedValue(mockPaginatedResponse);
137
+ test("should call correct endpoint/params and map all fields", async () => {
138
+ cli.request.mockResolvedValueOnce({ data: mockPaginatedResponse });
139
+
140
+ const resp = await client.getAllCapitalIncreases(size, region, page);
128
141
 
129
- const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
142
+ expect(cli.request).toHaveBeenCalledTimes(1);
143
+ const call = cli.request.mock.calls[0][0];
130
144
 
145
+ expect(call.method).toBe("GET");
146
+ expect(call.url).toBe("/api/v1/capital-increase/all");
147
+ expect(call.params).toEqual({ page, size, region });
148
+
131
149
  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);
150
+ expect(resp.items).toHaveLength(1);
151
+
152
+ expectCapitalIncreaseEqual(resp.items[0], mockCapitalIncrease);
141
153
  });
142
-
154
+
143
155
  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);
156
+ cli.request.mockResolvedValueOnce({ data: { recordCount: 0, items: [] } });
157
+
158
+ const resp = await client.getAllCapitalIncreases(size, region, page);
151
159
 
152
160
  expect(resp.recordCount).toBe(0);
153
- expect(resp.items).toHaveLength(0);
161
+ expect(resp.items).toEqual([]);
154
162
  });
155
163
  });
156
-
164
+
157
165
  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);
166
+ test("should call correct endpoint/params and map all fields", async () => {
167
+ cli.request.mockResolvedValueOnce({ data: { recordCount: 1, items: [mockCapitalIncrease] } });
168
+
169
+ const resp = await client.getCapitalIncreasesForInstrument(symbol, size, region, page);
164
170
 
165
- const resp = await client.getCapitalIncreasesForInstrument("TUPRS", 1, 10, Region.Tr);
171
+ expect(cli.request).toHaveBeenCalledTimes(1);
172
+ const call = cli.request.mock.calls[0][0];
166
173
 
174
+ expect(call.method).toBe("GET");
175
+ expect(call.url).toBe(`/api/v1/capital-increase/${symbol}`);
176
+ expect(call.params).toEqual({ page, size, region });
177
+
167
178
  expect(resp.recordCount).toBe(1);
168
179
  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);
180
+ expectCapitalIncreaseEqual(resp.items[0], mockCapitalIncrease);
181
+ expect(resp.items[0].symbol).toBe(symbol);
173
182
  });
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);
183
+
184
+ test("should bubble up request error", async () => {
185
+ cli.request.mockRejectedValueOnce(new Error("Invalid symbol"));
186
+
187
+ await expect(
188
+ client.getCapitalIncreasesForInstrument("INVALID", size, region, page)
189
+ ).rejects.toThrow("Invalid symbol");
186
190
  });
187
191
  });
188
-
192
+
189
193
  describe("getActiveRightsForInstrument", () => {
190
- test("should return active rights for specific instrument", async () => {
191
- jest.spyOn(client, 'getActiveRightsForInstrument').mockResolvedValue(mockActiveRights);
194
+ test("should call correct endpoint/params and map all fields", async () => {
195
+ cli.request.mockResolvedValueOnce({ data: mockActiveRights });
196
+
197
+ const resp = await client.getActiveRightsForInstrument(symbol, date);
192
198
 
193
- const resp = await client.getActiveRightsForInstrument("TUPRS", "2024-03-14", Region.Tr);
199
+ expect(cli.request).toHaveBeenCalledTimes(1);
200
+ const call = cli.request.mock.calls[0][0];
194
201
 
202
+ expect(call.method).toBe("GET");
203
+ expect(call.url).toBe(`/api/v1/rights/active/${symbol}`);
204
+ expect(call.params).toEqual({ date });
205
+
206
+ expect(Array.isArray(resp)).toBe(true);
195
207
  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);
208
+ expectCapitalIncreaseEqual(resp[0], mockCapitalIncrease);
209
+ expect(resp[0].symbol).toBe(symbol);
201
210
  });
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);
211
+
212
+ test("should handle empty array", async () => {
213
+ cli.request.mockResolvedValueOnce({ data: [] });
214
+
215
+ const resp = await client.getActiveRightsForInstrument("INVALID", date);
216
+
217
+ expect(resp).toEqual([]);
209
218
  });
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");
219
+
220
+ test("should bubble up request error", async () => {
221
+ cli.request.mockRejectedValueOnce(new Error("Invalid date format"));
222
+
223
+ await expect(
224
+ client.getActiveRightsForInstrument(symbol, "invalid-date")
225
+ ).rejects.toThrow("Invalid date format");
216
226
  });
217
227
  });
218
228
  });
229
+
219
230
  });
220
231
 
221
232
  function validateCapitalIncrease(item: CapitalIncrease) {
@@ -285,3 +296,41 @@ function validateCapitalIncrease(item: CapitalIncrease) {
285
296
  expect(typeof id).toBe("number");
286
297
  });
287
298
  }
299
+
300
+ function expectCapitalIncreaseEqual(actual: CapitalIncrease, expected: CapitalIncrease) {
301
+ expect(actual.id).toBe(expected.id);
302
+ expect(actual.boardDecisionDate).toBe(expected.boardDecisionDate);
303
+ expect(actual.registeredCapitalCeiling).toBe(expected.registeredCapitalCeiling);
304
+ expect(actual.currentCapital).toBe(expected.currentCapital);
305
+ expect(actual.targetCapital).toBe(expected.targetCapital);
306
+ expect(actual.types).toEqual(expected.types);
307
+
308
+ expect(actual.spkApplicationResult).toBe(expected.spkApplicationResult);
309
+ expect(actual.spkApplicationDate).toBe(expected.spkApplicationDate);
310
+ expect(actual.spkApprovalDate).toBe(expected.spkApprovalDate);
311
+ expect(actual.paymentDate).toBe(expected.paymentDate);
312
+ expect(actual.registrationDate).toBe(expected.registrationDate);
313
+
314
+ expect(actual.specifiedCurrency).toBe(expected.specifiedCurrency);
315
+ expect(actual.symbol).toBe(expected.symbol);
316
+ expect(actual.relatedDisclosureIds).toEqual(expected.relatedDisclosureIds);
317
+
318
+ expect(actual.rightsRate).toBe(expected.rightsRate);
319
+ expect(actual.rightsPrice).toBe(expected.rightsPrice);
320
+ expect(actual.rightsTotalAmount).toBe(expected.rightsTotalAmount);
321
+ expect(actual.rightsStartDate).toBe(expected.rightsStartDate);
322
+ expect(actual.rightsEndDate).toBe(expected.rightsEndDate);
323
+ expect(actual.rightsLastSellDate).toBe(expected.rightsLastSellDate);
324
+
325
+ expect(actual.bonusRate).toBe(expected.bonusRate);
326
+ expect(actual.bonusTotalAmount).toBe(expected.bonusTotalAmount);
327
+ expect(actual.bonusStartDate).toBe(expected.bonusStartDate);
328
+ expect(actual.bonusDividendRate).toBe(expected.bonusDividendRate);
329
+ expect(actual.bonusDividendTotalAmount).toBe(expected.bonusDividendTotalAmount);
330
+
331
+ expect(actual.externalCapitalIncreaseAmount).toBe(expected.externalCapitalIncreaseAmount);
332
+ expect(actual.externalCapitalIncreaseRate).toBe(expected.externalCapitalIncreaseRate);
333
+
334
+ expect(Object.keys(actual).sort()).toEqual(Object.keys(expected).sort());
335
+ }
336
+