From 91bb0463393714d11effb42369ad4d5a4bbe6fb6 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Wed, 24 Jun 2026 13:21:30 +0300 Subject: [PATCH] feat(Pairing): add createPairing id factory --- .../createPairing/createPairing.test.ts | 22 +++++++++++++++++++ .../domain/createPairing/createPairing.ts | 15 +++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/entities/Pairing/domain/createPairing/createPairing.test.ts create mode 100644 src/entities/Pairing/domain/createPairing/createPairing.ts diff --git a/src/entities/Pairing/domain/createPairing/createPairing.test.ts b/src/entities/Pairing/domain/createPairing/createPairing.test.ts new file mode 100644 index 0000000..5281405 --- /dev/null +++ b/src/entities/Pairing/domain/createPairing/createPairing.test.ts @@ -0,0 +1,22 @@ +import { + describe, + expect, + it, +} from 'vitest'; +import { createPairing } from './createPairing'; + +describe('createPairing', () => { + it('builds a pairing from two font ids', () => { + const p = createPairing('Inter', 'Lora'); + expect(p.headerFontId).toBe('Inter'); + expect(p.bodyFontId).toBe('Lora'); + }); + it('generates a unique id each call (duplicates stay distinct)', () => { + const a = createPairing('Inter', 'Lora'); + const b = createPairing('Inter', 'Lora'); + expect(a.id).not.toBe(b.id); + }); + it('accepts an explicit id for rehydration', () => { + expect(createPairing('Inter', 'Lora', 'fixed-id').id).toBe('fixed-id'); + }); +}); diff --git a/src/entities/Pairing/domain/createPairing/createPairing.ts b/src/entities/Pairing/domain/createPairing/createPairing.ts new file mode 100644 index 0000000..8c86d50 --- /dev/null +++ b/src/entities/Pairing/domain/createPairing/createPairing.ts @@ -0,0 +1,15 @@ +import type { Pairing } from '../types'; + +/** + * Creates a Pairing with a fresh surrogate id (or a supplied one when + * rehydrating from storage). The id is identity, never content — two pairings + * with the same fonts are still distinct cards. + * + * @param headerFontId - Font entity id for the header role. + * @param bodyFontId - Font entity id for the body role. + * @param id - Explicit id for rehydration; defaults to a fresh UUID. + * @returns The new Pairing. + */ +export function createPairing(headerFontId: string, bodyFontId: string, id: string = crypto.randomUUID()): Pairing { + return { id, headerFontId, bodyFontId }; +}