mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 16:15:39 +00:00
api.tasks.create and update take alerts by id: a trigger from the task's due (or start) as an ISO 8601 duration, or at an instant in UTC; display or email; at most five. An update merges by id, each alert written by its JMAP patch path: an alert given is set, one given null is removed, and alerts the plugin did not name, such as one another app wrote, stay as the server holds them; null for the whole map removes every alert. Whether the map is patched or written whole is decided on the task as the server holds it, not an older copy. An alert kept with the same trigger and action stays acknowledged, so a snooze is an update of its trigger, which then fires again. While a task uses its calendar's default alerts, a change makes them the task's own under new ids, as the task form does, an alert under a default's id is refused rather than dropped, and removing every alert turns the defaults off too. TaskView returns the alerts, each with when it was acknowledged, and useDefaultAlerts. api.tasks.acknowledgeAlert dismisses one alert (or undoes that with null) by writing only its acknowledged. A plugin's writes to one task go one after another, since Stalwart refuses a set while another is under way on the same object. The task store applies patch paths to the task the caller read, so a task the list does not hold is shown and reported whole.
31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { applyPatchObject, patchPath, patchedProperties } from '../jmap/patch-object';
|
|
|
|
describe('patch-object', () => {
|
|
it('escapes path segments as JSON Pointer does', () => {
|
|
expect(patchPath('relatedTo', '<a/b~c@x>')).toBe('relatedTo/<a~1b~0c@x>');
|
|
});
|
|
|
|
it('applies plain keys and member paths without touching the target', () => {
|
|
const target = { title: 'T', alerts: { a: { acknowledged: null, action: 'display' }, b: { acknowledged: null } } };
|
|
const after = applyPatchObject(target, { title: 'U', 'alerts/a/acknowledged': '2026-05-04T07:00:00Z', 'alerts/b': null, 'links/x~1y': { href: 'h' } });
|
|
expect(after).toEqual({
|
|
title: 'U',
|
|
alerts: { a: { acknowledged: '2026-05-04T07:00:00Z', action: 'display' } },
|
|
links: { 'x/y': { href: 'h' } },
|
|
});
|
|
expect(target.alerts.b).toEqual({ acknowledged: null });
|
|
});
|
|
|
|
it('keeps __proto__ as a plain key', () => {
|
|
const after = applyPatchObject({ alerts: {} }, { 'alerts/__proto__': { polluted: true } }) as { alerts: object };
|
|
expect(Object.getPrototypeOf(after.alerts)).toBe(Object.prototype);
|
|
expect(Object.keys(after.alerts)).toEqual(['__proto__']);
|
|
expect(({} as Record<string, unknown>).polluted).toBeUndefined();
|
|
});
|
|
|
|
it('shows a path patch as whole properties', () => {
|
|
expect(patchedProperties({ alerts: { a: { x: 1 }, b: { x: 2 } } }, { 'alerts/a/x': 3 })).toEqual({ alerts: { a: { x: 3 }, b: { x: 2 } } });
|
|
});
|
|
});
|