Files
TREK/client/src/repo/mailIngestRepo.test.ts
T
Maurice a7adef5353 feat(mail-ingest): admin card, review mark, inbox events and links, translations
- Admin settings (desktop and phone, self-hosted only): the instance switch,
  how mail arrives (IMAP or a signed webhook) with its fields, the address
  template, the AI allowance per person and day, a connection test and the
  status in counts. Changed fields only are saved; secrets stay masked.
- The review mark of an imported booking takes its mark off: the pill in the
  desktop dialog and a row in the phone's transport sheet ('Looks right'),
  through the ordinary booking update. Its hint no longer speaks of airports.
- The inbox follows mailInbox:changed and mailInbox:settings, and
  ?inbox=mail (the 'bookings waiting' notification) opens it.
- mailIngestRepo: the online-only path the views take, answers parsed
  against the shared contracts.
- Dropped 'read with AI' and the unused mail-review contract: the server
  reads a passing AI failure again on its own.
- mailInbox, mailAdmin and the new reservation, settings and notification
  strings in all 28 locales; the pending notice is a plural group.
- The live flight line on the booking cards is one of the card's fields,
  full width on the phone; the phone's live card keeps its map to the middle.
- Admin flight and mail cards sit in the left column.
2026-11-13 18:31:07 +01:00

39 lines
1.6 KiB
TypeScript

// FE-MAILINGEST-REPO-001 to FE-MAILINGEST-REPO-003
import { afterEach, describe, expect, it, vi } from 'vitest';
vi.mock('../api/mailIngest', () => ({
mailIngestApi: { inboxCount: vi.fn(), tripAddress: vi.fn(), adminSettings: vi.fn() },
}));
import { mailIngestApi } from '../api/mailIngest';
import { _resetNetworkMode, setForcedOffline } from '../sync/networkMode';
import { mailIngestRepo } from './mailIngestRepo';
import { OnlineOnlyError } from './onlineOnly';
afterEach(() => {
_resetNetworkMode();
vi.mocked(mailIngestApi.inboxCount).mockReset();
});
describe('mailIngestRepo', () => {
it('FE-MAILINGEST-REPO-001: answers parsed against the shared contract', async () => {
vi.mocked(mailIngestApi.inboxCount).mockResolvedValue({ pending: 3 });
vi.mocked(mailIngestApi.tripAddress).mockResolvedValue({ address: null });
expect(await mailIngestRepo.inboxCount()).toBe(3);
expect(await mailIngestRepo.tripAddress(7)).toBeNull();
});
it('FE-MAILINGEST-REPO-002: an answer of another shape fails here, not in the view', async () => {
vi.mocked(mailIngestApi.inboxCount).mockResolvedValue({ pending: 'many' });
await expect(mailIngestRepo.inboxCount()).rejects.toThrow();
vi.mocked(mailIngestApi.adminSettings).mockResolvedValue(null);
expect(await mailIngestRepo.adminSettings()).toEqual({});
});
it('FE-MAILINGEST-REPO-003: offline nothing is asked, and the caller hears why', async () => {
setForcedOffline(true);
await expect(mailIngestRepo.inboxCount()).rejects.toBeInstanceOf(OnlineOnlyError);
expect(mailIngestApi.inboxCount).not.toHaveBeenCalled();
});
});