30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { RecipientDeduplicator } from '../src/services/recipient-deduplicator.js';
|
|
|
|
describe('RecipientDeduplicator', () => {
|
|
it('reserves a recipient once across username casing variants', () => {
|
|
const history = { hasSentTo: vi.fn(() => false) };
|
|
const deduplicator = new RecipientDeduplicator(history);
|
|
|
|
expect(deduplicator.tryReserve('Some_User')).toBe(true);
|
|
expect(deduplicator.hasSentTo('some_user')).toBe(true);
|
|
expect(deduplicator.tryReserve('SOME_USER')).toBe(false);
|
|
});
|
|
|
|
it('rejects recipients found in persisted cross-account history', () => {
|
|
const history = { hasSentTo: vi.fn((recipient: string) => recipient === 'contacted') };
|
|
const deduplicator = new RecipientDeduplicator(history);
|
|
|
|
expect(deduplicator.tryReserve('contacted')).toBe(false);
|
|
expect(deduplicator.tryReserve('new-user')).toBe(true);
|
|
});
|
|
|
|
it('allows another account to retry after a failed send releases its reservation', () => {
|
|
const deduplicator = new RecipientDeduplicator({ hasSentTo: () => false });
|
|
|
|
expect(deduplicator.tryReserve('retry-user')).toBe(true);
|
|
deduplicator.release('RETRY-USER');
|
|
expect(deduplicator.tryReserve('retry-user')).toBe(true);
|
|
});
|
|
});
|