37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { toSnakeCase, toCamelCase, pick } from './case';
|
|
|
|
test('toSnakeCase converts keys', () => {
|
|
assert.deepEqual(toSnakeCase({ weightLbs: 3.5, sireId: 1, locusEn: 'Enen' }), {
|
|
weight_lbs: 3.5,
|
|
sire_id: 1,
|
|
locus_en: 'Enen',
|
|
});
|
|
});
|
|
|
|
test('toCamelCase converts keys', () => {
|
|
assert.deepEqual(toCamelCase({ weight_lbs: 3.5, sire_id: 1, pp_grandsire_name_text: 'Bob' }), {
|
|
weightLbs: 3.5,
|
|
sireId: 1,
|
|
ppGrandsireNameText: 'Bob',
|
|
});
|
|
});
|
|
|
|
test('snake<->camel round-trips for schema-style keys', () => {
|
|
const original = { maternal_granddam_name_text: 'X', registration_number: 'R1' };
|
|
assert.deepEqual(toSnakeCase(toCamelCase(original)), original);
|
|
});
|
|
|
|
test('pick keeps only allowed keys', () => {
|
|
const result = pick(
|
|
{ name: 'Daisy', id: 99, createdAt: 'now', photoPath: '/x.jpg' },
|
|
['name', 'sex']
|
|
);
|
|
assert.deepEqual(result, { name: 'Daisy' });
|
|
});
|
|
|
|
test('pick drops everything when nothing is allowed', () => {
|
|
assert.deepEqual(pick({ id: 1, name: 'x' }, []), {});
|
|
});
|