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.
@@ -3,10 +3,55 @@ import { LaplaceConfiguration } from "../utilities/configuration";
3
3
  import {
4
4
  CapitalIncrease,
5
5
  CapitalIncreaseClient,
6
+ PaginatedResponse,
6
7
  } from "../client/capital_increase";
7
8
  import "./client_test_suite";
8
9
  import { Region } from "../client/collections";
9
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
+ };
40
+
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
+
10
55
  describe("Capital Increase", () => {
11
56
  let client: CapitalIncreaseClient;
12
57
 
@@ -22,52 +67,154 @@ describe("Capital Increase", () => {
22
67
  client = new CapitalIncreaseClient(config, logger);
23
68
  });
24
69
 
25
- test("GetAllCapitalIncreases", async () => {
26
- const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
70
+ describe("Integration Tests", () => {
71
+ test("GetAllCapitalIncreases", async () => {
72
+ const resp = await client.getAllCapitalIncreases(1, 10, Region.Tr);
27
73
 
28
- expect(resp).toBeDefined();
29
- expect(typeof resp.recordCount).toBe("number");
30
- expect(Array.isArray(resp.items)).toBe(true);
74
+ expect(resp).toBeDefined();
75
+ expect(typeof resp.recordCount).toBe("number");
76
+ expect(Array.isArray(resp.items)).toBe(true);
31
77
 
32
- if (resp.items.length > 0) {
33
- const firstItem = resp.items[0];
34
- validateCapitalIncrease(firstItem);
35
- }
36
- });
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
+ });
37
102
 
38
- test("GetCapitalIncreasesForInstrument", async () => {
39
- const resp = await client.getCapitalIncreasesForInstrument(
40
- "TUPRS",
41
- 1,
42
- 10,
43
- Region.Tr
44
- );
45
-
46
- expect(resp).toBeDefined();
47
- expect(typeof resp.recordCount).toBe("number");
48
- expect(Array.isArray(resp.items)).toBe(true);
49
-
50
- if (resp.items.length > 0) {
51
- const firstItem = resp.items[0];
52
- validateCapitalIncrease(firstItem);
53
- expect(firstItem.symbol).toBe("TUPRS");
54
- }
103
+ test("GetActiveRightsForInstrument", async () => {
104
+ const resp = await client.getActiveRightsForInstrument(
105
+ "TUPRS",
106
+ "2024-01-01",
107
+ Region.Tr
108
+ );
109
+
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
+ });
55
118
  });
56
119
 
57
- test("GetActiveRightsForInstrument", async () => {
58
- const resp = await client.getActiveRightsForInstrument(
59
- "TUPRS",
60
- "2024-01-01",
61
- Region.Tr
62
- );
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
+ });
63
210
 
64
- expect(Array.isArray(resp)).toBe(true);
211
+ test("should handle invalid date format", async () => {
212
+ jest.spyOn(client, 'getActiveRightsForInstrument').mockRejectedValue(new Error("Invalid date format"));
65
213
 
66
- if (resp.length > 0) {
67
- const firstItem = resp[0];
68
- validateCapitalIncrease(firstItem);
69
- expect(firstItem.symbol).toBe("TUPRS");
70
- }
214
+ await expect(client.getActiveRightsForInstrument("TUPRS", "invalid-date", Region.Tr))
215
+ .rejects.toThrow("Invalid date format");
216
+ });
217
+ });
71
218
  });
72
219
  });
73
220