39948-vm/backend/tests/helpers.test.ts
2026-07-01 15:45:38 +02:00

34 lines
864 B
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { assertRouteIdMatchesBody } from '../src/helpers.ts';
void test('assertRouteIdMatchesBody allows matching top-level body id', () => {
assert.doesNotThrow(() =>
assertRouteIdMatchesBody({
params: { id: 'route-id' },
body: { id: 'route-id' },
}),
);
});
void test('assertRouteIdMatchesBody allows matching data body id', () => {
assert.doesNotThrow(() =>
assertRouteIdMatchesBody({
params: { id: 'route-id' },
body: { data: { id: 'route-id' } },
}),
);
});
void test('assertRouteIdMatchesBody rejects mismatched body id', () => {
assert.throws(
() =>
assertRouteIdMatchesBody({
params: { id: 'route-id' },
body: { data: { id: 'body-id' } },
}),
/Request body id does not match route id/,
);
});