fix: drop the scheduled badge from a demo message once its send is cancelled

This commit is contained in:
Linus Rath
2026-10-28 10:29:26 +01:00
parent 780b64461e
commit 53c49143ec
2 changed files with 22 additions and 1 deletions
+18
View File
@@ -30,3 +30,21 @@ describe('DemoJMAPClient raw messages', () => {
expect(await (await client.fetchBlob(draft!.blobId!)).text()).toContain('Subject: Draft for export');
});
});
// A server sends a new object on every fetch. The app stamps the scheduled
// send onto the message it opens; with the demo's own object, a cancelled
// send kept its Scheduled badge in Drafts.
describe('DemoJMAPClient getEmail', () => {
it('returns a copy that the caller may change', async () => {
const client = new DemoJMAPClient();
const { emails } = await client.getEmails(undefined, undefined, 1);
const opened = (await client.getEmail(emails[0].id))!;
opened.isScheduled = true;
opened.scheduledSendAt = '2030-01-01T08:00:00Z';
const again = (await client.getEmail(emails[0].id))!;
expect(again.isScheduled).toBeUndefined();
expect(again.scheduledSendAt).toBeUndefined();
const { emails: listed } = await client.getEmails(undefined, undefined, 500);
expect(listed.find((e) => e.id === emails[0].id)!.isScheduled).toBeUndefined();
});
});
+4 -1
View File
@@ -383,7 +383,10 @@ export class DemoJMAPClient implements IJMAPClient {
}
async getEmail(emailId: string): Promise<Email | null> {
return this.data.emails.find(e => e.id === emailId) ?? null;
// A copy, as a server sends: the app stamps what it opens (a scheduled
// send's fields), which must not stick to the stored message.
const email = this.data.emails.find(e => e.id === emailId);
return email ? structuredClone(email) : null;
}
async getTagCounts(tagIds: string[], accountId?: string, excludeMailboxIds?: string[]): Promise<Record<string, { total: number; unread: number }>> {