mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
baa906fb6b
Five tables carry the mail import: forwarding addresses (token hash plus the encrypted token), a person's switches, the readers' cursor and lease, every mail as it arrived, and each booking read from it with its checks and fate. Repositories read the trips a booking may go to by column, so the import weighs a booking without reaching into five other domains.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
/**
|
|
* A person's switches for the mail import: no row until something changes,
|
|
* and a write names only the switches it changes.
|
|
*/
|
|
import { MailIngestPrefs } from '../../../../src/db/entities/MailIngestPrefs.entity';
|
|
import type { MailIngestPrefsRepository } from '../../../../src/db/repositories/MailIngestPrefs.repository';
|
|
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
|
import { makeUser } from '../../../helpers/factories/users';
|
|
import { resetTestDb } from '../../../helpers/test-db';
|
|
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
|
|
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
let t: TestOrm;
|
|
let prefs: MailIngestPrefsRepository;
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestOrm(testDb);
|
|
prefs = t.repo(MailIngestPrefs);
|
|
});
|
|
beforeEach(() => {
|
|
resetTestDb(testDb);
|
|
t.clear();
|
|
});
|
|
afterAll(async () => {
|
|
await t.close();
|
|
testDb.close();
|
|
});
|
|
|
|
describe('MailIngestPrefsRepository', () => {
|
|
it('has no row until a switch changes, then the defaults for the others', async () => {
|
|
const { user } = await makeUser(t);
|
|
expect(await prefs.findForUser(user.id)).toBeNull();
|
|
|
|
await prefs.upsertForUser(user.id, { auto_add: 0 });
|
|
expect(await prefs.findForUser(user.id)).toMatchObject({ enabled: 1, ai_enabled: 1, auto_add: 0 });
|
|
|
|
await prefs.upsertForUser(user.id, { ai_enabled: 0 });
|
|
expect(await prefs.findForUser(user.id)).toMatchObject({ enabled: 1, ai_enabled: 0, auto_add: 0 });
|
|
});
|
|
|
|
it('writes nothing for an empty change', async () => {
|
|
const { user } = await makeUser(t);
|
|
await prefs.upsertForUser(user.id, {});
|
|
expect(await prefs.findForUser(user.id)).toBeNull();
|
|
});
|
|
});
|