feat(Pairing): add createPairing id factory
This commit is contained in:
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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 };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user