Read a body from message_payload and accept data_sm (#84)
* Regression tests for a body in message_payload and for data_sm * Read a body from message_payload and accept data_sm * Assert the fixed message_payload and data_sm behaviour against Jasmin * Record the message_payload and data_sm fixes in the Jasmin findings * Read an inbound data_sm as the direction it travelled, and export messageOctets * Refuse a segment with the code its stand-in command defines * Name the stand-in the refusal status is read from
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
smppTime,
|
||||
splitMessage,
|
||||
} from '../src/message.ts';
|
||||
// Through the public surface: an application handed a PduObject needs this same answer.
|
||||
import { messageOctets, objToPdu, pduToObj } from '../src/index.ts';
|
||||
|
||||
describe('bitCount()', () => {
|
||||
test('counts GSM characters as seven bits each', () => {
|
||||
@@ -130,6 +132,41 @@ describe('encodeMessage() and decodeMessage()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('messageOctets()', () => {
|
||||
/** A data_sm has no short_message field at all, which is the case that has neither. */
|
||||
function parsed(short: Buffer | undefined, payload?: Buffer) {
|
||||
const { buffer } = short === undefined
|
||||
? objToPdu({
|
||||
cmdName: 'data_sm',
|
||||
params: { destination_addr: '46709771337', source_addr: '46701113311' },
|
||||
})
|
||||
: objToPdu({
|
||||
cmdName: 'deliver_sm',
|
||||
params: { destination_addr: '46709771337', short_message: short, source_addr: '46701113311' },
|
||||
...(payload ? { tlvs: { message_payload: { tagValue: payload } } } : {}),
|
||||
});
|
||||
|
||||
assert.ok(buffer);
|
||||
|
||||
const { pduObj } = pduToObj(buffer);
|
||||
|
||||
assert.ok(pduObj);
|
||||
|
||||
return pduObj;
|
||||
}
|
||||
|
||||
test('reads the TLV only where short_message carries nothing', () => {
|
||||
const short = Buffer.from('in the field');
|
||||
const payload = Buffer.from('in the TLV');
|
||||
|
||||
assert.deepEqual(messageOctets(parsed(Buffer.alloc(0), payload)), payload);
|
||||
assert.deepEqual(messageOctets(parsed(short, payload)), short);
|
||||
assert.deepEqual(messageOctets(parsed(short)), short);
|
||||
assert.deepEqual(messageOctets(parsed(Buffer.alloc(0))), Buffer.alloc(0));
|
||||
assert.equal(messageOctets(parsed(undefined)), undefined, 'a PDU with neither carries no body');
|
||||
});
|
||||
});
|
||||
|
||||
describe('smppDate()', () => {
|
||||
// 0.4.0 used getMonth() without adding one, so January rendered as 00 and every delivery
|
||||
// receipt carried a date a month in the past.
|
||||
|
||||
Reference in New Issue
Block a user