| import { describe, expect, it } from 'vitest' |
| import * as schemas from '../src/models/schemas.js' |
| import { fromWire, toWire } from '../src/lib/wire.js' |
| import { |
| collectFieldKeys, |
| operationSchemaPairs, |
| sampleCamel, |
| sampleSnake, |
| } from './wire-helpers.js' |
|
|
| const SNAKE_KEY = /_/ |
| const CAMEL_KEY = /[A-Z]/ |
|
|
| const pairs = operationSchemaPairs(schemas as Record<string, unknown>) |
|
|
| |
| |
| |
| |
| |
| |
| describe('per-operation wire casing (toWire → snake, fromWire → camel)', () => { |
| for (const { base, body, response } of pairs) { |
| if (body) { |
| it(`${base}: request body has no camelCase field key on the wire`, () => { |
| const wire = toWire(sampleCamel(body), body) |
| const leaked = collectFieldKeys(wire).filter((k) => CAMEL_KEY.test(k)) |
| expect(leaked).toEqual([]) |
| }) |
|
|
| |
| |
| |
| |
| it(`${base}: request body round-trips (camel → wire → camel)`, () => { |
| const sample = sampleCamel(body) |
| expect(fromWire(toWire(sample, body), body)).toEqual(sample) |
| }) |
| } |
| if (response) { |
| it(`${base}: response has no snake_case field key after mapping`, () => { |
| const camel = fromWire(sampleSnake(response), response) |
| const leaked = collectFieldKeys(camel).filter((k) => SNAKE_KEY.test(k)) |
| expect(leaked).toEqual([]) |
| }) |
|
|
| it(`${base}: response round-trips (wire → camel → wire)`, () => { |
| const wire = sampleSnake(response) |
| expect(toWire(fromWire(wire, response), response)).toEqual(wire) |
| }) |
| } |
| } |
| }) |
|
|
| |
| |
| |
| |
| |
|
|