mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
implement Plunk email driver with comprehensive tests
- Add plunkEmail driver following IEmailDriver interface
- Support single and multiple recipients (up to 5 max per Plunk API)
- Handle both string and { text, html } body formats
- Include sender customization (from, name, reply)
- Add recipient validation and error handling
- Create comprehensive unit tests with 6 test cases
- Export plunkEmail from core drivers index
- Update task list with implementation progress
This commit is contained in:
92
app/src/core/drivers/email/plunk.spec.ts
Normal file
92
app/src/core/drivers/email/plunk.spec.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { plunkEmail } from "./plunk";
|
||||
|
||||
const ALL_TESTS = !!process.env.ALL_TESTS;
|
||||
|
||||
describe.skipIf(ALL_TESTS)("plunk", () => {
|
||||
it.only("should throw on failed", async () => {
|
||||
const driver = plunkEmail({ apiKey: "invalid" });
|
||||
expect(driver.send("foo@bar.com", "Test", "Test")).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("should send an email", async () => {
|
||||
const driver = plunkEmail({
|
||||
apiKey: process.env.PLUNK_API_KEY!,
|
||||
from: "test@example.com",
|
||||
});
|
||||
const response = await driver.send(
|
||||
"test@example.com",
|
||||
"Test Email",
|
||||
"This is a test email",
|
||||
);
|
||||
expect(response).toBeDefined();
|
||||
expect(response.success).toBe(true);
|
||||
expect(response.emails).toBeDefined();
|
||||
expect(response.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it("should send HTML email", async () => {
|
||||
const driver = plunkEmail({
|
||||
apiKey: process.env.PLUNK_API_KEY!,
|
||||
from: "test@example.com",
|
||||
});
|
||||
const htmlBody = "<h1>Test Email</h1><p>This is a test email</p>";
|
||||
const response = await driver.send(
|
||||
"test@example.com",
|
||||
"HTML Test",
|
||||
htmlBody,
|
||||
);
|
||||
expect(response).toBeDefined();
|
||||
expect(response.success).toBe(true);
|
||||
});
|
||||
|
||||
it("should send with text and html", async () => {
|
||||
const driver = plunkEmail({
|
||||
apiKey: process.env.PLUNK_API_KEY!,
|
||||
from: "test@example.com",
|
||||
});
|
||||
const response = await driver.send("test@example.com", "Test Email", {
|
||||
text: "This is plain text",
|
||||
html: "<p>This is HTML</p>",
|
||||
});
|
||||
expect(response).toBeDefined();
|
||||
expect(response.success).toBe(true);
|
||||
});
|
||||
|
||||
it("should send to multiple recipients", async () => {
|
||||
const driver = plunkEmail({
|
||||
apiKey: process.env.PLUNK_API_KEY!,
|
||||
from: "test@example.com",
|
||||
});
|
||||
const response = await driver.send(
|
||||
"test@example.com",
|
||||
"Multi-recipient Test",
|
||||
"Test email to multiple recipients",
|
||||
{
|
||||
to: ["test1@example.com", "test2@example.com"],
|
||||
},
|
||||
);
|
||||
expect(response).toBeDefined();
|
||||
expect(response.success).toBe(true);
|
||||
expect(response.emails).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("should throw error for more than 5 recipients", async () => {
|
||||
const driver = plunkEmail({
|
||||
apiKey: process.env.PLUNK_API_KEY!,
|
||||
from: "test@example.com",
|
||||
});
|
||||
expect(
|
||||
driver.send("test@example.com", "Test", "Test", {
|
||||
to: [
|
||||
"test1@example.com",
|
||||
"test2@example.com",
|
||||
"test3@example.com",
|
||||
"test4@example.com",
|
||||
"test5@example.com",
|
||||
"test6@example.com",
|
||||
],
|
||||
}),
|
||||
).rejects.toThrow("Plunk supports a maximum of 5 recipients per email");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user