@octarq/plugin-mail 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/api.ts +223 -0
- package/i18n.ts +699 -0
- package/index.ts +17 -0
- package/package.json +26 -3
- package/pages/AuthBadges.tsx +33 -0
- package/pages/Compose.tsx +291 -0
- package/pages/EmailListItem.tsx +85 -0
- package/pages/EmailListPane.tsx +152 -0
- package/pages/EmailView.tsx +283 -0
- package/pages/FolderNav.tsx +30 -0
- package/pages/MailGuide.tsx +36 -0
- package/pages/MailSettings.tsx +174 -0
- package/pages/MailTabs.tsx +26 -0
- package/pages/MailboxBar.tsx +59 -0
- package/pages/MailboxEditor.tsx +116 -0
- package/pages/SMTPSenders.tsx +323 -0
- package/pages/SuppressionList.tsx +148 -0
- package/pages/emptyState.test.tsx +58 -0
- package/pages/forms.test.tsx +694 -0
- package/pages/index.tsx +213 -0
- package/pages/mailEnhancements.test.tsx +254 -0
- package/pages/types.ts +10 -0
- package/tsconfig.json +15 -0
- package/widgets/MailSetupStepWidget.tsx +55 -0
- package/widgets/MailStatCardWidget.tsx +22 -0
- package/widgets/RecentMailPanelWidget.tsx +37 -0
- package/README.md +0 -3
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { cleanup, render, screen, waitFor, fireEvent } from "@testing-library/react";
|
|
4
|
+
import { MemoryRouter } from "react-router-dom";
|
|
5
|
+
import { ConfirmProvider, RoleProvider, I18nProvider, registerUIPlugin, resetRegistry } from "@octarq/plugin-sdk";
|
|
6
|
+
import mailPlugin from "../index";
|
|
7
|
+
import { Compose } from "./Compose";
|
|
8
|
+
import { MailboxEditor } from "./MailboxEditor";
|
|
9
|
+
import { SMTPSenders } from "./SMTPSenders";
|
|
10
|
+
import { SuppressionList } from "./SuppressionList";
|
|
11
|
+
import { SMTPSender, Mailbox, MailSuppression } from "../api";
|
|
12
|
+
|
|
13
|
+
function jsonResponse(body: unknown, status = 200) {
|
|
14
|
+
return {
|
|
15
|
+
ok: status >= 200 && status < 300,
|
|
16
|
+
status,
|
|
17
|
+
json: async () => body,
|
|
18
|
+
headers: { get: (name: string) => (name === "content-type" ? "application/json" : null) },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const mockSenders: SMTPSender[] = [
|
|
23
|
+
{
|
|
24
|
+
id: 1,
|
|
25
|
+
name: "Corporate Mailgun",
|
|
26
|
+
host: "smtp.mailgun.org",
|
|
27
|
+
port: 587,
|
|
28
|
+
user: "postmaster@acme.com",
|
|
29
|
+
fromEmail: "noreply@acme.com",
|
|
30
|
+
passSet: true,
|
|
31
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const mockIntegrations = [
|
|
36
|
+
{
|
|
37
|
+
id: 1,
|
|
38
|
+
name: "Corporate Mailgun",
|
|
39
|
+
provider: "smtp",
|
|
40
|
+
providerType: "communication",
|
|
41
|
+
configured: true,
|
|
42
|
+
isDefault: true,
|
|
43
|
+
metadata: {
|
|
44
|
+
fromEmail: "noreply@acme.com",
|
|
45
|
+
fromName: "Acme Mail",
|
|
46
|
+
smtpHost: "smtp.mailgun.org",
|
|
47
|
+
smtpPort: 587,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 2,
|
|
52
|
+
name: "Transactional Resend",
|
|
53
|
+
provider: "resend",
|
|
54
|
+
providerType: "communication",
|
|
55
|
+
configured: true,
|
|
56
|
+
metadata: {
|
|
57
|
+
fromEmail: "alerts@acme.com",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 3,
|
|
62
|
+
name: "Bare SMTP",
|
|
63
|
+
provider: "smtp",
|
|
64
|
+
providerType: "communication",
|
|
65
|
+
configured: false,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const mockMailbox: Mailbox = {
|
|
70
|
+
id: 10,
|
|
71
|
+
address: "support@acme.com",
|
|
72
|
+
note: "Customer support queue",
|
|
73
|
+
enabled: true,
|
|
74
|
+
unread: 3,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const mockSuppressions: MailSuppression[] = [
|
|
78
|
+
{
|
|
79
|
+
id: 1,
|
|
80
|
+
address: "hardbounce@invalid.com",
|
|
81
|
+
reason: "hard_bounce",
|
|
82
|
+
source: "smtp",
|
|
83
|
+
count: 2,
|
|
84
|
+
createdAt: "2026-05-01T00:00:00Z",
|
|
85
|
+
updatedAt: "2026-05-01T00:00:00Z",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 2,
|
|
89
|
+
address: "complaint@spam.com",
|
|
90
|
+
reason: "complaint",
|
|
91
|
+
source: "fbl",
|
|
92
|
+
count: 1,
|
|
93
|
+
createdAt: "2026-05-02T00:00:00Z",
|
|
94
|
+
updatedAt: "2026-05-02T00:00:00Z",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 3,
|
|
98
|
+
address: "manual@blocked.com",
|
|
99
|
+
reason: "manual",
|
|
100
|
+
source: "admin",
|
|
101
|
+
count: 1,
|
|
102
|
+
createdAt: "2026-05-03T00:00:00Z",
|
|
103
|
+
updatedAt: "2026-05-03T00:00:00Z",
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const testResources = {
|
|
108
|
+
en: {
|
|
109
|
+
uiCommon: {
|
|
110
|
+
confirm: "Confirm",
|
|
111
|
+
cancel: "Cancel",
|
|
112
|
+
},
|
|
113
|
+
settings: {
|
|
114
|
+
noSmtpConfigured: "No SMTP outgoing senders configured.",
|
|
115
|
+
noSmtpSenders: "No SMTP outgoing senders configured.",
|
|
116
|
+
smtpPasswordSet: "password set",
|
|
117
|
+
smtpNoPassword: "no password",
|
|
118
|
+
integrationsHubBanner: "Manage third-party credentials and cloud provider integrations centrally.",
|
|
119
|
+
openIntegrationsHub: "Integrations Hub",
|
|
120
|
+
addSmtpSender: "Add SMTP Sender",
|
|
121
|
+
addSmtp: "Add SMTP",
|
|
122
|
+
test: "Test",
|
|
123
|
+
editSmtp: "Edit SMTP",
|
|
124
|
+
remove: "Remove",
|
|
125
|
+
cancel: "Cancel",
|
|
126
|
+
save: "Save",
|
|
127
|
+
confirmRemoveSmtp: "Remove this SMTP sender?",
|
|
128
|
+
modifySmtpRelay: "Edit SMTP Sender",
|
|
129
|
+
configureSmtpRelay: "Add SMTP Sender",
|
|
130
|
+
senderConnectionName: "Connection Name",
|
|
131
|
+
senderConnectionPlaceholder: "e.g. Corporate SMTP",
|
|
132
|
+
smtpHostLabel: "SMTP Host",
|
|
133
|
+
smtpPortLabel: "Port",
|
|
134
|
+
smtpUsernameLabel: "Username",
|
|
135
|
+
smtpUsernamePlaceholder: "e.g. postmaster@domain.com",
|
|
136
|
+
smtpPasswordLabel: "Password",
|
|
137
|
+
smtpFromEmailLabel: "From Email",
|
|
138
|
+
senderLeavePasswordBlank: "Leave blank to keep existing password",
|
|
139
|
+
saveRelay: "Save",
|
|
140
|
+
saving: "Saving...",
|
|
141
|
+
saveSettings: "Save Settings",
|
|
142
|
+
saved: "Saved.",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function renderWithProviders(ui: React.ReactElement) {
|
|
148
|
+
return render(
|
|
149
|
+
<MemoryRouter>
|
|
150
|
+
<I18nProvider resources={testResources}>
|
|
151
|
+
<RoleProvider value={{ role: "admin", isInstanceAdmin: true }}>
|
|
152
|
+
<ConfirmProvider>{ui}</ConfirmProvider>
|
|
153
|
+
</RoleProvider>
|
|
154
|
+
</I18nProvider>
|
|
155
|
+
</MemoryRouter>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
describe("Mail Forms", () => {
|
|
160
|
+
let fetchMock: ReturnType<typeof vi.fn>;
|
|
161
|
+
|
|
162
|
+
beforeEach(() => {
|
|
163
|
+
cleanup();
|
|
164
|
+
resetRegistry();
|
|
165
|
+
registerUIPlugin(mailPlugin);
|
|
166
|
+
|
|
167
|
+
fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
168
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
169
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
170
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
171
|
+
const path = urlObj.pathname;
|
|
172
|
+
|
|
173
|
+
if (method === "GET" && path === "/api/vault/items") {
|
|
174
|
+
return jsonResponse(mockIntegrations);
|
|
175
|
+
}
|
|
176
|
+
if (method === "POST" && path.startsWith("/api/vault/items/") && path.endsWith("/test")) {
|
|
177
|
+
return jsonResponse({ ok: true, message: "Sent test email via Corporate Mailgun." });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (method === "GET" && path === "/api/smtp-senders") {
|
|
181
|
+
return jsonResponse(mockSenders);
|
|
182
|
+
}
|
|
183
|
+
if (method === "POST" && path === "/api/smtp-senders") {
|
|
184
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
185
|
+
return jsonResponse({ id: 2, ...body, passSet: !!body.pass, createdAt: new Date().toISOString() });
|
|
186
|
+
}
|
|
187
|
+
if (method === "PUT" && path.startsWith("/api/smtp-senders/")) {
|
|
188
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
189
|
+
return jsonResponse({ id: 1, ...body, passSet: true });
|
|
190
|
+
}
|
|
191
|
+
if (method === "DELETE" && path.startsWith("/api/smtp-senders/")) {
|
|
192
|
+
return jsonResponse({ ok: true });
|
|
193
|
+
}
|
|
194
|
+
if (method === "POST" && path.endsWith("/test") && path.startsWith("/api/smtp-senders/")) {
|
|
195
|
+
return jsonResponse({ ok: true });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (method === "GET" && path === "/api/settings") {
|
|
199
|
+
return jsonResponse({ autoWrapLinks: true });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (method === "POST" && path === "/api/emails/send") {
|
|
203
|
+
return jsonResponse({ ok: true });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (method === "GET" && path === "/api/mailboxes") {
|
|
207
|
+
return jsonResponse([mockMailbox]);
|
|
208
|
+
}
|
|
209
|
+
if (method === "POST" && path === "/api/mailboxes") {
|
|
210
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
211
|
+
return jsonResponse({ id: 11, ...body, unread: 0 });
|
|
212
|
+
}
|
|
213
|
+
if (method === "PUT" && path === "/api/mailboxes/10") {
|
|
214
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
215
|
+
return jsonResponse({ ...mockMailbox, ...body });
|
|
216
|
+
}
|
|
217
|
+
if (method === "DELETE" && path === "/api/mailboxes/10") {
|
|
218
|
+
return jsonResponse({ ok: true });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (method === "GET" && path === "/api/mail/suppressions") {
|
|
222
|
+
return jsonResponse(mockSuppressions);
|
|
223
|
+
}
|
|
224
|
+
if (method === "POST" && path === "/api/mail/suppressions") {
|
|
225
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
226
|
+
return jsonResponse({
|
|
227
|
+
id: 4,
|
|
228
|
+
address: body.address,
|
|
229
|
+
reason: "manual",
|
|
230
|
+
source: "admin",
|
|
231
|
+
count: 1,
|
|
232
|
+
createdAt: new Date().toISOString(),
|
|
233
|
+
updatedAt: new Date().toISOString(),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (method === "DELETE" && path.startsWith("/api/mail/suppressions/")) {
|
|
237
|
+
return jsonResponse({ ok: true });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
throw new Error(`Unhandled fetch in Mail test: ${method} ${rawUrl}`);
|
|
241
|
+
});
|
|
242
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
afterEach(() => {
|
|
246
|
+
cleanup();
|
|
247
|
+
vi.restoreAllMocks();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("Compose", () => {
|
|
251
|
+
it("renders compose modal, validates required fields, and sends email successfully", async () => {
|
|
252
|
+
const onClose = vi.fn();
|
|
253
|
+
|
|
254
|
+
renderWithProviders(<Compose onClose={onClose} />);
|
|
255
|
+
|
|
256
|
+
// Verify fields
|
|
257
|
+
expect(screen.getByText("Compose mail")).toBeDefined();
|
|
258
|
+
expect((screen.getByRole("button", { name: "Send mail" }) as HTMLButtonElement).disabled).toBe(true);
|
|
259
|
+
|
|
260
|
+
// Wait for settings & senders to load and checkbox to appear
|
|
261
|
+
await waitFor(() => {
|
|
262
|
+
expect(screen.getByRole("checkbox")).toBeDefined();
|
|
263
|
+
expect(screen.getAllByText("Corporate Mailgun (noreply@acme.com)").length).toBeGreaterThan(0);
|
|
264
|
+
});
|
|
265
|
+
expect(document.body.textContent).not.toContain("undefined");
|
|
266
|
+
|
|
267
|
+
// Fill in recipients, subject, body
|
|
268
|
+
const toInput = screen.getByPlaceholderText("hello@world.com");
|
|
269
|
+
fireEvent.change(toInput, {
|
|
270
|
+
target: { value: "alice@example.com, bob@example.com" },
|
|
271
|
+
});
|
|
272
|
+
const subjectInput = screen.getByPlaceholderText("Subject line");
|
|
273
|
+
fireEvent.change(subjectInput, {
|
|
274
|
+
target: { value: "Important System Update" },
|
|
275
|
+
});
|
|
276
|
+
fireEvent.change(screen.getByPlaceholderText("Type email content here…"), {
|
|
277
|
+
target: { value: "Hello team,\nPlease read https://example.com/update" },
|
|
278
|
+
});
|
|
279
|
+
fireEvent.change(screen.getByPlaceholderText("e.g. custom@domain.com"), {
|
|
280
|
+
target: { value: "team@acme.com" },
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// Submit email
|
|
284
|
+
const sendBtn = screen.getByRole("button", { name: "Send mail" });
|
|
285
|
+
expect((sendBtn as HTMLButtonElement).disabled).toBe(false);
|
|
286
|
+
fireEvent.click(sendBtn);
|
|
287
|
+
|
|
288
|
+
await waitFor(() => {
|
|
289
|
+
expect(screen.getByText("Message sent.")).toBeDefined();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Verify the POST payload sent to /api/emails/send
|
|
293
|
+
const sendCall = fetchMock.mock.calls.find(c => {
|
|
294
|
+
const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
|
|
295
|
+
return url.includes("/api/emails/send");
|
|
296
|
+
});
|
|
297
|
+
expect(sendCall).toBeDefined();
|
|
298
|
+
const payload = JSON.parse(sendCall![1]?.body as string);
|
|
299
|
+
expect(payload).toMatchObject({
|
|
300
|
+
to: ["alice@example.com", "bob@example.com"],
|
|
301
|
+
from: "team@acme.com",
|
|
302
|
+
subject: "Important System Update",
|
|
303
|
+
text: "Hello team,\nPlease read https://example.com/update",
|
|
304
|
+
smtpSenderId: 1,
|
|
305
|
+
smtpSenderSource: "integration",
|
|
306
|
+
trackLinks: true,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Click Done
|
|
310
|
+
fireEvent.click(screen.getByRole("button", { name: "Done" }));
|
|
311
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("cancels compose when cancel button is clicked", async () => {
|
|
315
|
+
const onClose = vi.fn();
|
|
316
|
+
renderWithProviders(<Compose onClose={onClose} />);
|
|
317
|
+
|
|
318
|
+
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
|
319
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("pre-fills draft reply data", async () => {
|
|
323
|
+
renderWithProviders(
|
|
324
|
+
<Compose
|
|
325
|
+
draft={{ to: "customer@example.com", subject: "Re: Order #1234" }}
|
|
326
|
+
onClose={vi.fn()}
|
|
327
|
+
/>
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const toInput = screen.getByPlaceholderText("hello@world.com") as HTMLInputElement;
|
|
331
|
+
expect(toInput.value).toBe("customer@example.com");
|
|
332
|
+
|
|
333
|
+
const subjectInput = screen.getByPlaceholderText("Subject line") as HTMLInputElement;
|
|
334
|
+
expect(subjectInput.value).toBe("Re: Order #1234");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("displays FormError when sending email fails", async () => {
|
|
338
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
339
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
340
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
341
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
342
|
+
const path = urlObj.pathname;
|
|
343
|
+
|
|
344
|
+
if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse(mockIntegrations);
|
|
345
|
+
if (method === "GET" && path === "/api/settings") return jsonResponse({});
|
|
346
|
+
if (method === "POST" && path === "/api/emails/send") {
|
|
347
|
+
return jsonResponse({ message: "SMTP relay authentication failed" }, 400);
|
|
348
|
+
}
|
|
349
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
renderWithProviders(<Compose onClose={vi.fn()} />);
|
|
353
|
+
|
|
354
|
+
expect(screen.getByText("Compose mail")).toBeDefined();
|
|
355
|
+
|
|
356
|
+
fireEvent.change(screen.getByPlaceholderText("hello@world.com"), { target: { value: "test@example.com" } });
|
|
357
|
+
fireEvent.change(screen.getByPlaceholderText("Subject line"), { target: { value: "Test" } });
|
|
358
|
+
|
|
359
|
+
const sendBtn = screen.getByRole("button", { name: "Send mail" });
|
|
360
|
+
await waitFor(() => {
|
|
361
|
+
expect((sendBtn as HTMLButtonElement).disabled).toBe(false);
|
|
362
|
+
});
|
|
363
|
+
fireEvent.click(sendBtn);
|
|
364
|
+
|
|
365
|
+
await waitFor(() => {
|
|
366
|
+
expect(screen.getByText("SMTP relay authentication failed")).toBeDefined();
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("renders fail-closed callout and disables Send when no senders configured", async () => {
|
|
371
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
372
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
373
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
374
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
375
|
+
const path = urlObj.pathname;
|
|
376
|
+
if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse([]);
|
|
377
|
+
if (method === "GET" && path === "/api/settings") return jsonResponse({});
|
|
378
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
renderWithProviders(<Compose onClose={vi.fn()} />);
|
|
382
|
+
|
|
383
|
+
await waitFor(() => {
|
|
384
|
+
expect(screen.getByText("No SMTP outgoing senders configured.")).toBeDefined();
|
|
385
|
+
expect((screen.getByRole("button", { name: "Send mail" }) as HTMLButtonElement).disabled).toBe(true);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// Standalone instances without Core Vault still serve the local sender registry.
|
|
390
|
+
it("falls back to local SMTP senders when Core Vault is absent", async () => {
|
|
391
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
392
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
393
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
394
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
395
|
+
const path = urlObj.pathname;
|
|
396
|
+
|
|
397
|
+
if (method === "GET" && path === "/api/vault/items") return jsonResponse({ detail: "Not Found" }, 404);
|
|
398
|
+
if (method === "GET" && path === "/api/smtp-senders") return jsonResponse(mockSenders);
|
|
399
|
+
if (method === "GET" && path === "/api/settings") return jsonResponse({});
|
|
400
|
+
if (method === "POST" && path === "/api/emails/send") return jsonResponse({ ok: true });
|
|
401
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
renderWithProviders(<Compose onClose={vi.fn()} />);
|
|
405
|
+
|
|
406
|
+
fireEvent.change(screen.getByPlaceholderText("hello@world.com"), { target: { value: "alice@example.com" } });
|
|
407
|
+
fireEvent.change(screen.getByPlaceholderText("Subject line"), { target: { value: "Local relay" } });
|
|
408
|
+
|
|
409
|
+
const sendBtn = screen.getByRole("button", { name: "Send mail" });
|
|
410
|
+
await waitFor(() => {
|
|
411
|
+
expect((sendBtn as HTMLButtonElement).disabled).toBe(false);
|
|
412
|
+
});
|
|
413
|
+
fireEvent.click(sendBtn);
|
|
414
|
+
|
|
415
|
+
await waitFor(() => {
|
|
416
|
+
const sendCall = fetchMock.mock.calls.find((c) => {
|
|
417
|
+
const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
|
|
418
|
+
return url.includes("/api/emails/send");
|
|
419
|
+
});
|
|
420
|
+
expect(sendCall).toBeDefined();
|
|
421
|
+
const payload = JSON.parse(sendCall![1]?.body as string);
|
|
422
|
+
expect(payload).toMatchObject({
|
|
423
|
+
smtpSenderId: 1,
|
|
424
|
+
smtpSenderSource: "local",
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
describe("MailboxEditor", () => {
|
|
431
|
+
it("renders new mailbox form, validates prefix & domain, and creates mailbox", async () => {
|
|
432
|
+
const onSaved = vi.fn();
|
|
433
|
+
const onClose = vi.fn();
|
|
434
|
+
|
|
435
|
+
renderWithProviders(
|
|
436
|
+
<MailboxEditor
|
|
437
|
+
box={null}
|
|
438
|
+
hosts={["acme.com", "mail.acme.com"]}
|
|
439
|
+
onClose={onClose}
|
|
440
|
+
onSaved={onSaved}
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
expect(screen.getByText("Create mailbox")).toBeDefined();
|
|
445
|
+
const prefixInput = screen.getByPlaceholderText("e.g. sales");
|
|
446
|
+
const noteInput = screen.getByPlaceholderText("e.g. support operations");
|
|
447
|
+
|
|
448
|
+
fireEvent.change(prefixInput, { target: { value: "hello" } });
|
|
449
|
+
fireEvent.change(noteInput, { target: { value: "General contact inbox" } });
|
|
450
|
+
|
|
451
|
+
const saveBtn = screen.getByRole("button", { name: "Save configuration" });
|
|
452
|
+
fireEvent.click(saveBtn);
|
|
453
|
+
|
|
454
|
+
await waitFor(() => {
|
|
455
|
+
expect(onSaved).toHaveBeenCalledTimes(1);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("renders warning when no mail hosts are configured", async () => {
|
|
460
|
+
renderWithProviders(
|
|
461
|
+
<MailboxEditor
|
|
462
|
+
box={null}
|
|
463
|
+
hosts={[]}
|
|
464
|
+
onClose={vi.fn()}
|
|
465
|
+
onSaved={vi.fn()}
|
|
466
|
+
/>
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
expect(screen.getByText("No mail-enabled hosts. Configure your custom domain first.")).toBeDefined();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("renders edit mailbox mode, updates note/enabled, and deletes mailbox with confirmation", async () => {
|
|
473
|
+
const onSaved = vi.fn();
|
|
474
|
+
|
|
475
|
+
renderWithProviders(
|
|
476
|
+
<MailboxEditor
|
|
477
|
+
box={mockMailbox}
|
|
478
|
+
hosts={["acme.com"]}
|
|
479
|
+
onClose={vi.fn()}
|
|
480
|
+
onSaved={onSaved}
|
|
481
|
+
/>
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
expect(screen.getByText("Edit mailbox")).toBeDefined();
|
|
485
|
+
const addressInput = screen.getByDisplayValue("support@acme.com") as HTMLInputElement;
|
|
486
|
+
expect(addressInput.disabled).toBe(true);
|
|
487
|
+
|
|
488
|
+
const noteInput = screen.getByPlaceholderText("e.g. support operations") as HTMLTextAreaElement;
|
|
489
|
+
expect(noteInput.value).toBe("Customer support queue");
|
|
490
|
+
|
|
491
|
+
fireEvent.change(noteInput, { target: { value: "Updated support queue note" } });
|
|
492
|
+
|
|
493
|
+
const saveBtn = screen.getByRole("button", { name: "Save configuration" });
|
|
494
|
+
fireEvent.click(saveBtn);
|
|
495
|
+
|
|
496
|
+
await waitFor(() => {
|
|
497
|
+
expect(onSaved).toHaveBeenCalledTimes(1);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// Delete mailbox with confirmation
|
|
501
|
+
const delBtn = screen.getByRole("button", { name: "Delete mailbox completely" });
|
|
502
|
+
fireEvent.click(delBtn);
|
|
503
|
+
|
|
504
|
+
await waitFor(() => {
|
|
505
|
+
expect(screen.getByText("Delete mailbox support@acme.com and all its email messages?")).toBeDefined();
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const confirmBtn = screen.getByRole("button", { name: "Confirm" });
|
|
509
|
+
fireEvent.click(confirmBtn);
|
|
510
|
+
|
|
511
|
+
await waitFor(() => {
|
|
512
|
+
expect(screen.queryByText("Delete mailbox support@acme.com and all its email messages?")).toBeNull();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
describe("SMTPSenders", () => {
|
|
518
|
+
it("uses Core Vault when it is mounted and hides the local sender form", async () => {
|
|
519
|
+
renderWithProviders(<SMTPSenders />);
|
|
520
|
+
|
|
521
|
+
await waitFor(() => {
|
|
522
|
+
expect(screen.getByText("Corporate Mailgun")).toBeDefined();
|
|
523
|
+
expect(screen.getByText("noreply@acme.com via smtp.mailgun.org:587")).toBeDefined();
|
|
524
|
+
expect(screen.getByText("alerts@acme.com")).toBeDefined();
|
|
525
|
+
expect(screen.getByText("Bare SMTP")).toBeDefined();
|
|
526
|
+
expect(screen.getAllByText("password set").length).toBeGreaterThan(0);
|
|
527
|
+
expect(screen.getByText("no password")).toBeDefined();
|
|
528
|
+
expect(screen.getByText("Manage third-party credentials and cloud provider integrations centrally.")).toBeDefined();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
expect(document.body.textContent).not.toContain("undefined");
|
|
532
|
+
|
|
533
|
+
// Test connection goes through Core Vault, not the local table.
|
|
534
|
+
fireEvent.click(screen.getAllByRole("button", { name: "Test" })[0]);
|
|
535
|
+
|
|
536
|
+
await waitFor(() => {
|
|
537
|
+
const tested = fetchMock.mock.calls.some((c) => {
|
|
538
|
+
const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
|
|
539
|
+
return url.includes("/api/vault/items/1/test");
|
|
540
|
+
});
|
|
541
|
+
expect(tested).toBe(true);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// The local CRUD surfaces stay absent while Core Vault is authoritative.
|
|
545
|
+
expect(screen.queryByRole("button", { name: "Add SMTP" })).toBeNull();
|
|
546
|
+
expect(screen.queryByRole("button", { name: "Edit SMTP" })).toBeNull();
|
|
547
|
+
expect(screen.queryByRole("button", { name: "Remove" })).toBeNull();
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("unwraps { body: [...] } envelope from Core Vault API", async () => {
|
|
551
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
552
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
553
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
554
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
555
|
+
if (method === "GET" && urlObj.pathname === "/api/vault/items" && urlObj.searchParams.get("provider_type") === "communication") {
|
|
556
|
+
return jsonResponse({ body: mockIntegrations });
|
|
557
|
+
}
|
|
558
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
renderWithProviders(<SMTPSenders />);
|
|
562
|
+
|
|
563
|
+
await waitFor(() => {
|
|
564
|
+
expect(screen.getByText("Corporate Mailgun")).toBeDefined();
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("renders empty state with deep link when Core Vault has no senders", async () => {
|
|
569
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
570
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
571
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
572
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
573
|
+
const path = urlObj.pathname;
|
|
574
|
+
if (method === "GET" && path === "/api/vault/items") return jsonResponse([]);
|
|
575
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
renderWithProviders(<SMTPSenders />);
|
|
579
|
+
|
|
580
|
+
await waitFor(() => {
|
|
581
|
+
expect(screen.getByText("No SMTP outgoing senders configured.")).toBeDefined();
|
|
582
|
+
expect(screen.getAllByText("Integrations Hub").length).toBeGreaterThan(0);
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
// Standalone instances without Core Vault serve the local registry and keep its CRUD controls.
|
|
587
|
+
it("serves the local sender registry when Core Vault is absent", async () => {
|
|
588
|
+
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
589
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
590
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
591
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
592
|
+
const path = urlObj.pathname;
|
|
593
|
+
|
|
594
|
+
if (method === "GET" && path === "/api/vault/items") return jsonResponse({ detail: "Not Found" }, 404);
|
|
595
|
+
if (method === "GET" && path === "/api/smtp-senders") return jsonResponse(mockSenders);
|
|
596
|
+
if (method === "POST" && path === "/api/smtp-senders/1/test") return jsonResponse({ ok: true });
|
|
597
|
+
if (method === "POST" && path === "/api/smtp-senders") {
|
|
598
|
+
const body = init?.body ? JSON.parse(init.body as string) : {};
|
|
599
|
+
return jsonResponse({ id: 2, ...body, passSet: true, createdAt: new Date().toISOString() });
|
|
600
|
+
}
|
|
601
|
+
throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
renderWithProviders(<SMTPSenders />);
|
|
605
|
+
|
|
606
|
+
await waitFor(() => {
|
|
607
|
+
expect(screen.getByText("Corporate Mailgun")).toBeDefined();
|
|
608
|
+
expect(screen.getByText("noreply@acme.com via smtp.mailgun.org:587")).toBeDefined();
|
|
609
|
+
expect(screen.getByRole("button", { name: "Add SMTP" })).toBeDefined();
|
|
610
|
+
expect(screen.getByRole("button", { name: "Edit SMTP" })).toBeDefined();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
fireEvent.click(screen.getByRole("button", { name: "Test" }));
|
|
614
|
+
await waitFor(() => {
|
|
615
|
+
const tested = fetchMock.mock.calls.some((c) => {
|
|
616
|
+
const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
|
|
617
|
+
return url.includes("/api/smtp-senders/1/test");
|
|
618
|
+
});
|
|
619
|
+
expect(tested).toBe(true);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
// The local form is reachable and posts the password under the wire
|
|
623
|
+
// field the server reads.
|
|
624
|
+
fireEvent.click(screen.getByRole("button", { name: "Add SMTP" }));
|
|
625
|
+
await waitFor(() => {
|
|
626
|
+
expect(screen.getByText("Add SMTP Sender")).toBeDefined();
|
|
627
|
+
});
|
|
628
|
+
fireEvent.change(screen.getByPlaceholderText("e.g. Corporate SMTP"), { target: { value: "Local relay" } });
|
|
629
|
+
fireEvent.change(screen.getByPlaceholderText("smtp.mailgun.org"), { target: { value: "smtp.example.com" } });
|
|
630
|
+
fireEvent.change(screen.getByPlaceholderText("587"), { target: { value: "587" } });
|
|
631
|
+
fireEvent.change(screen.getByPlaceholderText("e.g. postmaster@domain.com"), { target: { value: "user@example.com" } });
|
|
632
|
+
fireEvent.change(screen.getByPlaceholderText("noreply@domain.com"), { target: { value: "noreply@example.com" } });
|
|
633
|
+
fireEvent.change(screen.getByPlaceholderText("••••••••"), { target: { value: "secret" } });
|
|
634
|
+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
|
635
|
+
|
|
636
|
+
await waitFor(() => {
|
|
637
|
+
const createCall = fetchMock.mock.calls.find((c) => {
|
|
638
|
+
const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
|
|
639
|
+
const method = ((c[1] as RequestInit | undefined)?.method ?? "GET").toUpperCase();
|
|
640
|
+
return method === "POST" && url.endsWith("/api/smtp-senders");
|
|
641
|
+
});
|
|
642
|
+
expect(createCall).toBeDefined();
|
|
643
|
+
const payload = JSON.parse(createCall![1]?.body as string);
|
|
644
|
+
expect(payload).toMatchObject({ pass: "secret", host: "smtp.example.com" });
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe("SuppressionList", () => {
|
|
650
|
+
it("renders suppression list with reason badges, adds new suppression, and removes item", async () => {
|
|
651
|
+
renderWithProviders(<SuppressionList />);
|
|
652
|
+
|
|
653
|
+
await waitFor(() => {
|
|
654
|
+
expect(screen.getByText("hardbounce@invalid.com")).toBeDefined();
|
|
655
|
+
expect(screen.getByText("complaint@spam.com")).toBeDefined();
|
|
656
|
+
expect(screen.getByText("manual@blocked.com")).toBeDefined();
|
|
657
|
+
expect(screen.getByText("Hard bounce")).toBeDefined();
|
|
658
|
+
expect(screen.getByText("Complaint")).toBeDefined();
|
|
659
|
+
expect(screen.getByText("Manual")).toBeDefined();
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
// Add address
|
|
663
|
+
const addBtn = screen.getByRole("button", { name: "Add address" });
|
|
664
|
+
fireEvent.click(addBtn);
|
|
665
|
+
|
|
666
|
+
expect(screen.getByText("Add to suppression list")).toBeDefined();
|
|
667
|
+
|
|
668
|
+
const addrInput = screen.getByPlaceholderText("colleague@example.com");
|
|
669
|
+
fireEvent.change(addrInput, { target: { value: "spammer@bad.org" } });
|
|
670
|
+
|
|
671
|
+
const saveBtn = screen.getByRole("button", { name: "Save configuration" });
|
|
672
|
+
fireEvent.click(saveBtn);
|
|
673
|
+
|
|
674
|
+
await waitFor(() => {
|
|
675
|
+
expect(screen.queryByText("Add to suppression list")).toBeNull();
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
// Remove suppression item with confirmation
|
|
679
|
+
const delButtons = screen.getAllByTitle("Remove");
|
|
680
|
+
fireEvent.click(delButtons[0]);
|
|
681
|
+
|
|
682
|
+
await waitFor(() => {
|
|
683
|
+
expect(screen.getByText("Remove hardbounce@invalid.com from suppression list?")).toBeDefined();
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
const confirmBtn = screen.getByRole("button", { name: "Confirm" });
|
|
687
|
+
fireEvent.click(confirmBtn);
|
|
688
|
+
|
|
689
|
+
await waitFor(() => {
|
|
690
|
+
expect(screen.queryByText("Remove hardbounce@invalid.com from suppression list?")).toBeNull();
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
});
|