82 lines
2.7 KiB
JavaScript
82 lines
2.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { createMailClient } from "../src/integrations/mail.js";
|
|
|
|
function fakeRunJxa(result) {
|
|
const calls = [];
|
|
return {
|
|
calls,
|
|
client: createMailClient(async (script, input) => {
|
|
calls.push({ script, input });
|
|
return result;
|
|
}),
|
|
};
|
|
}
|
|
|
|
test("mail_accounts returns normalized account identities without message data", async () => {
|
|
const { client, calls } = fakeRunJxa([
|
|
{ id: "acct-personal", name: "Personal", emailAddresses: ["me@example.com"] },
|
|
{ id: "acct-emi", name: "EMI", emailAddresses: ["info@emmint.com"] },
|
|
]);
|
|
|
|
const result = await client.accounts();
|
|
|
|
assert.deepEqual(result, [
|
|
{ id: "acct-personal", name: "Personal", emailAddresses: ["me@example.com"] },
|
|
{ id: "acct-emi", name: "EMI", emailAddresses: ["info@emmint.com"] },
|
|
]);
|
|
assert.equal(calls.length, 1);
|
|
assert.deepEqual(calls[0].input, {});
|
|
});
|
|
|
|
test("mail_list_messages scopes the request to an account mailbox and bounded limit", async () => {
|
|
const { client, calls } = fakeRunJxa([
|
|
{
|
|
id: "message-1",
|
|
accountId: "acct-emi",
|
|
account: "EMI",
|
|
mailbox: "INBOX",
|
|
subject: "Board update",
|
|
sender: "Board <board@example.org>",
|
|
dateSent: "2026-08-03T12:00:00.000Z",
|
|
read: false,
|
|
},
|
|
]);
|
|
|
|
const result = await client.listMessages({ accountId: "acct-emi", mailbox: "INBOX", limit: 5, unreadOnly: true });
|
|
|
|
assert.equal(result.length, 1);
|
|
assert.equal(result[0].subject, "Board update");
|
|
assert.deepEqual(calls[0].input, { accountId: "acct-emi", mailbox: "INBOX", limit: 5, unreadOnly: true });
|
|
assert.match(calls[0].script, /input\.limit/);
|
|
});
|
|
|
|
test("mail_read_message requires the selected message ID and never returns data from another message", async () => {
|
|
const { client, calls } = fakeRunJxa({
|
|
id: "message-1",
|
|
accountId: "acct-personal",
|
|
mailbox: "INBOX",
|
|
subject: "Receipt",
|
|
sender: "Store <sales@example.org>",
|
|
dateSent: "2026-08-03T12:00:00.000Z",
|
|
read: true,
|
|
body: "Thanks for your order.",
|
|
});
|
|
|
|
const result = await client.readMessage({ accountId: "acct-personal", mailbox: "INBOX", id: "message-1" });
|
|
|
|
assert.equal(result.id, "message-1");
|
|
assert.equal(result.body, "Thanks for your order.");
|
|
assert.deepEqual(calls[0].input, { accountId: "acct-personal", mailbox: "INBOX", id: "message-1" });
|
|
});
|
|
|
|
test("mail_list_messages rejects out-of-range limits before asking Mail", async () => {
|
|
const { client, calls } = fakeRunJxa([]);
|
|
|
|
assert.throws(
|
|
() => client.listMessages({ accountId: "acct-emi", mailbox: "INBOX", limit: 51, unreadOnly: false }),
|
|
/limit must be between 1 and 50/,
|
|
);
|
|
assert.equal(calls.length, 0);
|
|
});
|