Derive the notation names from one table and refuse an smsIdFormat that is not the pair

This commit is contained in:
2026-08-30 22:45:02 +02:00
parent 8e5b9bb556
commit 696e018b77
12 changed files with 111 additions and 56 deletions
+2
View File
@@ -872,6 +872,8 @@ describe('message id notation', () => {
assert.ok(checked.err instanceof Error);
assert.match(checked.err.message, /smsIdFormat\.receipt/);
// The shape todo.md sketched, which a caller without types would otherwise pass unnoticed.
assert.ok(checkSessionOptions({ smsIdFormat: 'hex' }).err instanceof Error);
assert.equal(checkSessionOptions({ smsIdFormat: { submitResp: 'hex' } }).err, undefined);
});
});
+23
View File
@@ -0,0 +1,23 @@
import assert from 'node:assert/strict';
import test, { describe } from 'node:test';
import { normaliseSmsId } from '../src/sms-id.ts';
describe('normaliseSmsId()', () => {
test('reads an id the length a message_id may be, and leaves a longer one alone', () => {
const padded = `0${'1'.repeat(63)}`;
const tooLong = `0${'1'.repeat(64)}`;
assert.equal(normaliseSmsId(padded, 'decimal'), '1'.repeat(63));
assert.equal(normaliseSmsId(tooLong, 'decimal'), tooLong);
});
test('leaves an id the notation cannot read as it arrived', () => {
assert.equal(normaliseSmsId('', 'hex'), '');
assert.equal(normaliseSmsId('0x1f', 'hex'), '0x1f');
assert.equal(normaliseSmsId('beef-1', 'hex'), 'beef-1', 'the segment convention stays whole');
});
test('reads either case of a hexadecimal id', () => {
assert.equal(normaliseSmsId('1a2B', 'hex'), normaliseSmsId('1A2b', 'hex'));
});
});