mailisk 2.1.1 → 2.2.1
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/README.md +63 -11
- package/dist/index.d.ts +122 -9
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/private/dist/private/index.js +28 -0
- package/private/dist/private/index.js.map +1 -0
- package/private/dist/src/mailisk.interfaces.js +3 -0
- package/private/dist/src/mailisk.interfaces.js.map +1 -0
- package/private/dist/src/mailisk.js +168 -0
- package/private/dist/src/mailisk.js.map +1 -0
- package/private/index.ts +17 -0
- package/private/node_modules/.package-lock.json +44 -0
- package/private/node_modules/typescript/LICENSE.txt +55 -0
- package/private/node_modules/typescript/README.md +50 -0
- package/private/node_modules/typescript/SECURITY.md +41 -0
- package/private/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/private/node_modules/typescript/bin/tsc +2 -0
- package/private/node_modules/typescript/bin/tsserver +2 -0
- package/private/node_modules/typescript/lib/_tsc.js +133818 -0
- package/private/node_modules/typescript/lib/_tsserver.js +659 -0
- package/private/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/private/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/lib.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/private/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/private/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/private/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/private/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/private/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/private/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/private/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/private/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/private/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/private/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/private/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/private/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/private/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/private/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/private/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/private/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/private/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/private/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/private/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/private/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/private/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/private/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/private/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/private/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/private/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/private/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/private/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/private/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/private/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/private/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/private/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/private/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/private/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/private/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/private/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/private/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/private/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/private/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/private/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/private/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/private/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/private/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/private/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/private/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/private/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/private/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/private/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/private/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/private/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/private/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/private/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/private/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/private/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/private/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/private/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/private/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/private/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/private/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/tsc.js +8 -0
- package/private/node_modules/typescript/lib/tsserver.js +8 -0
- package/private/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/private/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/private/node_modules/typescript/lib/typesMap.json +497 -0
- package/private/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/private/node_modules/typescript/lib/typescript.js +200276 -0
- package/private/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/private/node_modules/typescript/lib/watchGuard.js +53 -0
- package/private/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/package.json +120 -0
- package/private/package-lock.json +53 -0
- package/private/package.json +17 -0
- package/private/tsconfig.json +103 -0
- package/src/mailisk.interfaces.ts +91 -6
- package/src/mailisk.ts +89 -7
- package/tests/mocks/axios-mocks.ts +85 -26
- package/tests/unit/mailisk.test.ts +138 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Mock namespace response data
|
|
2
2
|
export const mockNamespacesResponse = {
|
|
3
|
-
|
|
3
|
+
total_count: 1,
|
|
4
|
+
data: [
|
|
4
5
|
{
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
id: "0fde5afa-a8a8-41a4-9ca4-21d83efc37d8",
|
|
7
|
+
namespace: "test-namespace",
|
|
7
8
|
expires_at: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
|
|
8
9
|
},
|
|
9
10
|
],
|
|
@@ -11,39 +12,97 @@ export const mockNamespacesResponse = {
|
|
|
11
12
|
|
|
12
13
|
// Mock email response data
|
|
13
14
|
export const mockEmailsResponse = {
|
|
14
|
-
|
|
15
|
+
total_count: 1,
|
|
16
|
+
options: {
|
|
17
|
+
wait: true,
|
|
18
|
+
},
|
|
19
|
+
data: [
|
|
15
20
|
{
|
|
16
|
-
id: "
|
|
17
|
-
from: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
id: "1763808382384-m-m-dEmYI7ic5",
|
|
22
|
+
from: {
|
|
23
|
+
address: "sender@example.com",
|
|
24
|
+
name: "Sender",
|
|
25
|
+
},
|
|
26
|
+
to: [
|
|
27
|
+
{
|
|
28
|
+
address: "recipient@test-namespace.mailisk.net",
|
|
29
|
+
name: "Recipient",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
subject: "test",
|
|
33
|
+
html: "false",
|
|
34
|
+
text: "test",
|
|
35
|
+
received_date: "2025-11-22T10:46:22.000Z",
|
|
36
|
+
received_timestamp: 1763808382,
|
|
37
|
+
expires_timestamp: 1764672382,
|
|
38
|
+
spam_score: null,
|
|
25
39
|
},
|
|
26
40
|
],
|
|
27
|
-
count: 1,
|
|
28
41
|
};
|
|
29
42
|
|
|
30
43
|
// Mock attachment response data
|
|
31
44
|
export const mockAttachmentResponse = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
data: {
|
|
46
|
+
id: "b04730be-9c13-4f23-a2b7-a4a9a943cd31",
|
|
47
|
+
filename: "Sample.png",
|
|
48
|
+
content_type: "image/png",
|
|
49
|
+
size: 140551,
|
|
50
|
+
expires_at: "2025-09-09T10:03:33.000Z",
|
|
51
|
+
download_url: "url",
|
|
52
|
+
},
|
|
38
53
|
};
|
|
39
54
|
|
|
40
55
|
// Mock SMTP settings response
|
|
41
56
|
export const mockSmtpSettingsResponse = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
data: {
|
|
58
|
+
host: "smtp.mailisk.net",
|
|
59
|
+
port: 587,
|
|
60
|
+
username: "test-namespace",
|
|
61
|
+
password: "mock-password",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Mock SMS messages response data
|
|
66
|
+
export const mockSmsMessagesResponse = {
|
|
67
|
+
total_count: 1,
|
|
68
|
+
options: {
|
|
69
|
+
limit: 20,
|
|
70
|
+
offset: 0,
|
|
48
71
|
},
|
|
72
|
+
data: [
|
|
73
|
+
{
|
|
74
|
+
id: "37a2bc57-c2c7-4c08-a9dc-d143bc17643f",
|
|
75
|
+
sms_phone_number_id: "ba548be2-bff9-4e3f-a54b-e034c415e906",
|
|
76
|
+
body: "test newline \\n\\n test2",
|
|
77
|
+
from_number: "+18777804236",
|
|
78
|
+
to_number: "+19285639871",
|
|
79
|
+
provider_message_id: "SMf72eb72b6281a02e60a0114f38e34e36",
|
|
80
|
+
created_at: "2020-11-24T16:48:22.170Z",
|
|
81
|
+
direction: "inbound",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Mock SMS numbers response data
|
|
87
|
+
export const mockSmsNumbersResponse = {
|
|
88
|
+
total_count: 2,
|
|
89
|
+
data: [
|
|
90
|
+
{
|
|
91
|
+
id: "13c4551e-a5be-4959-9ea5-82931dcfc74d",
|
|
92
|
+
organisation_id: "c02bdb84-22df-4c18-85ba-2defdd04eccb",
|
|
93
|
+
status: "requested",
|
|
94
|
+
country: "US",
|
|
95
|
+
created_at: "2020-11-22T16:59:25.462Z",
|
|
96
|
+
updated_at: "2020-11-22T16:59:25.462Z",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "6bf073d6-d333-45c9-b009-c77f0cac7657",
|
|
100
|
+
organisation_id: "ddec2c7b-b087-45b6-a81d-b195f25d457f",
|
|
101
|
+
status: "active",
|
|
102
|
+
country: "US",
|
|
103
|
+
phone_number: "+19285639871",
|
|
104
|
+
created_at: "2020-11-22T16:41:40.329Z",
|
|
105
|
+
updated_at: "2020-11-22T16:41:40.329Z",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
49
108
|
};
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
mockEmailsResponse,
|
|
10
10
|
mockSmtpSettingsResponse,
|
|
11
11
|
mockAttachmentResponse,
|
|
12
|
+
mockSmsMessagesResponse,
|
|
13
|
+
mockSmsNumbersResponse,
|
|
12
14
|
} from "../mocks/axios-mocks";
|
|
13
15
|
|
|
14
16
|
const setupMockAxios = () => {
|
|
@@ -132,7 +134,7 @@ describe("MailiskClient", () => {
|
|
|
132
134
|
describe("downloadAttachment", () => {
|
|
133
135
|
it("should download and return attachment data", async () => {
|
|
134
136
|
const getAttachmentSpy = jest.spyOn(MailiskClient.prototype, "getAttachment");
|
|
135
|
-
getAttachmentSpy.mockResolvedValueOnce(
|
|
137
|
+
getAttachmentSpy.mockResolvedValueOnce(mockAttachmentResponse);
|
|
136
138
|
|
|
137
139
|
const mockBuffer = Buffer.from("test content");
|
|
138
140
|
(axios.get as jest.Mock).mockResolvedValueOnce({ data: mockBuffer });
|
|
@@ -140,11 +142,145 @@ describe("MailiskClient", () => {
|
|
|
140
142
|
const client = new MailiskClient({ apiKey: "test-key" });
|
|
141
143
|
const result = await client.downloadAttachment("attachment-123");
|
|
142
144
|
|
|
143
|
-
expect(axios.get).toHaveBeenCalledWith(mockAttachmentResponse.download_url, { responseType: "arraybuffer" });
|
|
145
|
+
expect(axios.get).toHaveBeenCalledWith(mockAttachmentResponse.data.download_url, { responseType: "arraybuffer" });
|
|
144
146
|
expect(result).toEqual(mockBuffer);
|
|
145
147
|
});
|
|
146
148
|
});
|
|
147
149
|
|
|
150
|
+
describe("searchSmsMessages", () => {
|
|
151
|
+
it("should fetch and return SMS messages with default parameters", async () => {
|
|
152
|
+
const { mockGet } = setupMockAxios();
|
|
153
|
+
mockGet.mockResolvedValueOnce({ data: mockSmsMessagesResponse });
|
|
154
|
+
|
|
155
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
156
|
+
const result = await client.searchSmsMessages("1234567890");
|
|
157
|
+
|
|
158
|
+
expect(mockGet).toHaveBeenCalledWith("api/sms/1234567890/messages", {
|
|
159
|
+
maxRedirects: 99999,
|
|
160
|
+
timeout: 1000 * 60 * 5,
|
|
161
|
+
params: {
|
|
162
|
+
from_date: expect.any(String),
|
|
163
|
+
wait: true,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
expect(result).toEqual(mockSmsMessagesResponse);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should use custom parameters if provided", async () => {
|
|
171
|
+
const { mockGet } = setupMockAxios();
|
|
172
|
+
mockGet.mockResolvedValueOnce({ data: mockSmsMessagesResponse });
|
|
173
|
+
|
|
174
|
+
const customParams = {
|
|
175
|
+
limit: 5,
|
|
176
|
+
offset: 2,
|
|
177
|
+
body: "verification",
|
|
178
|
+
from_number: "+18005550123",
|
|
179
|
+
from_date: "2023-01-01T00:00:00.000Z",
|
|
180
|
+
to_date: "2023-02-01T00:00:00.000Z",
|
|
181
|
+
wait: false,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
185
|
+
const result = await client.searchSmsMessages("+1234567890", customParams);
|
|
186
|
+
|
|
187
|
+
const expectedParams = { ...customParams };
|
|
188
|
+
|
|
189
|
+
expect(mockGet).toHaveBeenCalledWith("api/sms/+1234567890/messages", {
|
|
190
|
+
maxRedirects: 99999,
|
|
191
|
+
params: expectedParams,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(result).toEqual(mockSmsMessagesResponse);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("should use custom axios config if provided", async () => {
|
|
198
|
+
const { mockGet } = setupMockAxios();
|
|
199
|
+
mockGet.mockResolvedValueOnce({ data: mockSmsMessagesResponse });
|
|
200
|
+
|
|
201
|
+
const customConfig = {
|
|
202
|
+
timeout: 10000,
|
|
203
|
+
maxRedirects: 5,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
207
|
+
const result = await client.searchSmsMessages("+1234567890", undefined, customConfig);
|
|
208
|
+
|
|
209
|
+
expect(mockGet).toHaveBeenCalledWith("api/sms/+1234567890/messages", {
|
|
210
|
+
...customConfig,
|
|
211
|
+
params: {
|
|
212
|
+
from_date: expect.any(String),
|
|
213
|
+
wait: true,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(result).toEqual(mockSmsMessagesResponse);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("should handle errors correctly", async () => {
|
|
221
|
+
const { mockGet } = setupMockAxios();
|
|
222
|
+
const error = new Error("Search SMS Error");
|
|
223
|
+
mockGet.mockRejectedValueOnce(error);
|
|
224
|
+
|
|
225
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
226
|
+
|
|
227
|
+
await expect(client.searchSmsMessages("+1234567890")).rejects.toThrow("Search SMS Error");
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe("listSmsNumbers", () => {
|
|
232
|
+
it("should fetch and return SMS numbers", async () => {
|
|
233
|
+
const { mockGet } = setupMockAxios();
|
|
234
|
+
mockGet.mockResolvedValueOnce({ data: mockSmsNumbersResponse });
|
|
235
|
+
|
|
236
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
237
|
+
const result = await client.listSmsNumbers();
|
|
238
|
+
|
|
239
|
+
expect(mockGet).toHaveBeenCalledWith("api/sms/numbers");
|
|
240
|
+
expect(result).toEqual(mockSmsNumbersResponse);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("should handle errors correctly", async () => {
|
|
244
|
+
const { mockGet } = setupMockAxios();
|
|
245
|
+
const error = new Error("List SMS Numbers Error");
|
|
246
|
+
mockGet.mockRejectedValueOnce(error);
|
|
247
|
+
|
|
248
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
249
|
+
|
|
250
|
+
await expect(client.listSmsNumbers()).rejects.toThrow("List SMS Numbers Error");
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe("sendVirtualSms", () => {
|
|
255
|
+
it("should send an SMS through the API", async () => {
|
|
256
|
+
const { mockPost } = setupMockAxios();
|
|
257
|
+
mockPost.mockResolvedValueOnce({ data: {} });
|
|
258
|
+
|
|
259
|
+
const smsParams = {
|
|
260
|
+
from_number: "15551234567",
|
|
261
|
+
to_number: "15557654321",
|
|
262
|
+
body: "Test message",
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
266
|
+
await client.sendVirtualSms(smsParams);
|
|
267
|
+
|
|
268
|
+
expect(mockPost).toHaveBeenCalledWith("api/sms/virtual", smsParams);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("should handle errors when sending SMS", async () => {
|
|
272
|
+
const { mockPost } = setupMockAxios();
|
|
273
|
+
const error = new Error("Send SMS Error");
|
|
274
|
+
mockPost.mockRejectedValueOnce(error);
|
|
275
|
+
|
|
276
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
277
|
+
|
|
278
|
+
await expect(
|
|
279
|
+
client.sendVirtualSms({ from_number: "+15551234567", to_number: "+15557654321", body: "Test message" })
|
|
280
|
+
).rejects.toThrow("Send SMS Error");
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
148
284
|
describe("searchInbox", () => {
|
|
149
285
|
it("should fetch and return emails with default parameters", async () => {
|
|
150
286
|
const { mockGet } = setupMockAxios();
|