71 lines
2.9 KiB
JavaScript
71 lines
2.9 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { createFolderService } = require('../desktop/mail/folders.cjs');
|
|
const { isReservedFolderName } = require('../desktop/mail-model.cjs');
|
|
|
|
function clientWith(mailboxes = []) {
|
|
const created = [];
|
|
return {
|
|
created,
|
|
async list() { return mailboxes; },
|
|
async mailboxCreate(name) {
|
|
created.push(name);
|
|
const mailbox = { path: name, name };
|
|
mailboxes.push(mailbox);
|
|
return mailbox;
|
|
}
|
|
};
|
|
}
|
|
|
|
const folders = createFolderService({ isReservedFolderName });
|
|
|
|
test('resolves special-use folders before provider-specific fallback names', async () => {
|
|
const client = clientWith([
|
|
{ path: 'Sent Items', specialUse: null },
|
|
{ path: 'Provider/Sent', specialUse: '\\Sent' }
|
|
]);
|
|
assert.equal(await folders.findSpecialMailbox(client, '\\Sent', ['sent', 'sent items']), 'Provider/Sent');
|
|
assert.equal(await folders.findSpecialMailbox(client, '\\Archive', ['archive']), null);
|
|
});
|
|
|
|
test('creates a missing special mailbox only when requested', async () => {
|
|
const client = clientWith([]);
|
|
assert.equal(await folders.findSentMailbox(client), null);
|
|
assert.equal(client.created.length, 0);
|
|
assert.equal(await folders.findSentMailbox(client, true), 'Sent');
|
|
assert.deepEqual(client.created, ['Sent']);
|
|
});
|
|
|
|
test('maps built-in folder labels and validates custom folder paths', async () => {
|
|
const client = clientWith([
|
|
{ path: 'INBOX', name: 'INBOX' },
|
|
{ path: 'Sent Items', name: 'Sent Items' },
|
|
{ path: 'ArchiveBox', name: 'ArchiveBox' },
|
|
{ path: 'Projects/2026', name: '2026' },
|
|
{ path: 'Private', name: 'Private', flags: new Set(['\\Noselect']) }
|
|
]);
|
|
assert.equal(await folders.folderPath(client, 'Inbox'), 'INBOX');
|
|
assert.equal(await folders.folderPath(client, 'Starred'), 'INBOX');
|
|
assert.equal(await folders.folderPath(client, 'Sent'), 'Sent Items');
|
|
assert.equal(await folders.folderPath(client, 'Folder:Projects/2026'), 'Projects/2026');
|
|
await assert.rejects(() => folders.folderPath(client, 'Folder:Private'), /not available/);
|
|
await assert.rejects(() => folders.folderPath(client, 'Folder:Missing'), /not available/);
|
|
await assert.rejects(() => folders.folderPath(client, 'Unknown'), /not available/);
|
|
});
|
|
|
|
test('lists sorted custom folders and excludes reserved and non-selectable mailboxes', async () => {
|
|
const client = clientWith([
|
|
{ path: 'INBOX', name: 'INBOX' },
|
|
{ path: 'Sent Items', name: 'Sent Items' },
|
|
{ path: 'Projects/Zeta', name: 'Zeta' },
|
|
{ path: 'Projects/Alpha', name: 'Alpha' },
|
|
{ path: 'Junk', name: 'Junk' },
|
|
{ path: 'NoSelect', name: 'NoSelect', flags: new Set(['\\Noselect']) },
|
|
{ path: 'Archive', name: 'Archive', specialUse: '\\Archive' }
|
|
]);
|
|
assert.deepEqual(await folders.listCustomFolders(client), [
|
|
{ name: 'Alpha', path: 'Projects/Alpha', id: 'Folder:Projects/Alpha' },
|
|
{ name: 'Zeta', path: 'Projects/Zeta', id: 'Folder:Projects/Zeta' }
|
|
]);
|
|
});
|