39948-vm/backend/tests/helpers.test.js
2026-06-28 21:29:29 +02:00

34 lines
861 B
JavaScript

const assert = require('node:assert/strict');
const test = require('node:test');
const { assertRouteIdMatchesBody } = require('../src/helpers');
test('assertRouteIdMatchesBody allows matching top-level body id', () => {
assert.doesNotThrow(() =>
assertRouteIdMatchesBody({
params: { id: 'route-id' },
body: { id: 'route-id' },
}),
);
});
test('assertRouteIdMatchesBody allows matching data body id', () => {
assert.doesNotThrow(() =>
assertRouteIdMatchesBody({
params: { id: 'route-id' },
body: { data: { id: 'route-id' } },
}),
);
});
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/,
);
});