mailisk 2.4.0 → 2.5.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.
@@ -11,6 +11,8 @@ import {
11
11
  mockAttachmentResponse,
12
12
  mockSmsMessagesResponse,
13
13
  mockSmsNumbersResponse,
14
+ mockOutboundEmailDetailResponse,
15
+ mockOutboundEmailResponse,
14
16
  mockTotpDevice,
15
17
  mockTotpDevicesResponse,
16
18
  mockTotpOtpResponse,
@@ -284,6 +286,97 @@ describe("MailiskClient", () => {
284
286
  });
285
287
  });
286
288
 
289
+ describe("outbound email", () => {
290
+ it("should send an outbound email through the API", async () => {
291
+ const { mockPost } = setupMockAxios();
292
+ mockPost.mockResolvedValueOnce({ data: mockOutboundEmailResponse });
293
+
294
+ const emailParams = {
295
+ from: {
296
+ email: "support@test-namespace.mailisk.net",
297
+ name: "Support",
298
+ },
299
+ reply_to: {
300
+ email: "team@test-namespace.mailisk.net",
301
+ name: "Team",
302
+ },
303
+ to: ["verified@example.com"],
304
+ subject: "Hello",
305
+ text: "Hello from Mailisk",
306
+ html: "<p>Hello from Mailisk</p>",
307
+ attachments: [
308
+ {
309
+ filename: "hello.txt",
310
+ content_type: "text/plain",
311
+ content_base64: Buffer.from("hello").toString("base64"),
312
+ disposition: "attachment" as const,
313
+ },
314
+ ],
315
+ };
316
+
317
+ const client = new MailiskClient({ apiKey: "test-key" });
318
+ const result = await client.sendEmail("test-namespace", emailParams);
319
+
320
+ expect(mockPost).toHaveBeenCalledWith("api/emails/send", emailParams, {
321
+ params: {
322
+ namespace: "test-namespace",
323
+ },
324
+ });
325
+ expect(result).toEqual(mockOutboundEmailResponse);
326
+ });
327
+
328
+ it("should get outbound email delivery details", async () => {
329
+ const { mockGet } = setupMockAxios();
330
+ mockGet.mockResolvedValueOnce({ data: mockOutboundEmailDetailResponse });
331
+
332
+ const client = new MailiskClient({ apiKey: "test-key" });
333
+ const result = await client.getOutboundEmail("outbound-email-id");
334
+
335
+ expect(mockGet).toHaveBeenCalledWith("api/emails/outbound/outbound-email-id");
336
+ expect(result).toEqual(mockOutboundEmailDetailResponse);
337
+ });
338
+
339
+ it("should reply to an inbound email through the API", async () => {
340
+ const { mockPost } = setupMockAxios();
341
+ mockPost.mockResolvedValueOnce({ data: mockOutboundEmailResponse });
342
+
343
+ const replyParams = {
344
+ from: {
345
+ email: "support@test-namespace.mailisk.net",
346
+ },
347
+ cc: ["manager@example.com"],
348
+ subject: "Re: Hello",
349
+ text: "Thanks for the message.",
350
+ };
351
+
352
+ const client = new MailiskClient({ apiKey: "test-key" });
353
+ const result = await client.replyToEmail("inbound-email-id", replyParams);
354
+
355
+ expect(mockPost).toHaveBeenCalledWith("api/emails/inbound-email-id/reply", replyParams);
356
+ expect(result).toEqual(mockOutboundEmailResponse);
357
+ });
358
+
359
+ it("should forward an inbound email through the API", async () => {
360
+ const { mockPost } = setupMockAxios();
361
+ mockPost.mockResolvedValueOnce({ data: mockOutboundEmailResponse });
362
+
363
+ const forwardParams = {
364
+ from: {
365
+ email: "support@test-namespace.mailisk.net",
366
+ },
367
+ to: ["verified@example.com"],
368
+ subject: "Fwd: Hello",
369
+ text: "Forwarding this along.",
370
+ };
371
+
372
+ const client = new MailiskClient({ apiKey: "test-key" });
373
+ const result = await client.forwardEmail("inbound-email-id", forwardParams);
374
+
375
+ expect(mockPost).toHaveBeenCalledWith("api/emails/inbound-email-id/forward", forwardParams);
376
+ expect(result).toEqual(mockOutboundEmailResponse);
377
+ });
378
+ });
379
+
287
380
  describe("listTotpDevices", () => {
288
381
  it("should fetch and return saved TOTP devices", async () => {
289
382
  const { mockGet } = setupMockAxios();