Read a delivery receipt's body as the octets that arrived (#81)
* Regression tests for a receipt body read under a data_coding it is not written in * Read a delivery receipt's body as the octets that arrived, not by its data_coding * Assert SMPPSim's UCS2 receipt body parses like every other segment's * Record the receipt-body defect as fixed * Retain a multipart segment's octets once, not twice * Sort the new type import into its file's order
This commit is contained in:
+37
-1
@@ -1,6 +1,8 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test, { describe } from 'node:test';
|
||||
import { PduRefusedError, isCommand, isResp, objToPdu, pduReturn, pduToObj, refusalAnswer } from '../src/pdu.ts';
|
||||
import { PduRefusedError, refusalAnswer } from '../src/pdu-refusal.ts';
|
||||
import { isCommand, isResp, objToPdu, pduReturn, pduToObj } from '../src/pdu.ts';
|
||||
import { paramText } from '../src/defs/types.ts';
|
||||
|
||||
function encode(...args: Parameters<typeof objToPdu>): Buffer {
|
||||
const { buffer, err } = objToPdu(...args);
|
||||
@@ -206,6 +208,40 @@ describe('encoding submit_sm', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('decoding short_message', () => {
|
||||
function deliverSm(dataCoding: number, message: Buffer | string) {
|
||||
return decode(encode({
|
||||
cmdName: 'deliver_sm',
|
||||
params: {
|
||||
data_coding: dataCoding,
|
||||
destination_addr: '46709771337',
|
||||
short_message: message,
|
||||
source_addr: '46701113311',
|
||||
},
|
||||
seqNr: 3,
|
||||
}));
|
||||
}
|
||||
|
||||
test('reads an inbound message with the data_coding the PDU declares', () => {
|
||||
const binary = Buffer.from([0x00, 0x1B, 0x60, 0x80, 0xFF]);
|
||||
|
||||
assert.equal(deliverSm(0x08, 'hej 一').params.short_message, 'hej 一');
|
||||
assert.equal(deliverSm(0x03, Buffer.from([0xE1, 0xE7, 0xDA])).params.short_message, 'áçÚ');
|
||||
assert.deepEqual(
|
||||
Buffer.from(paramText(deliverSm(0x04, binary).params.short_message), 'latin1'),
|
||||
binary,
|
||||
);
|
||||
});
|
||||
|
||||
// A delivery receipt is read from these rather than from the text above, since its body is
|
||||
// Appendix B's fixed format whatever the data_coding the peer inherited onto it says.
|
||||
test('keeps the octets that arrived alongside the text they decoded to', () => {
|
||||
const pduObj = deliverSm(0x08, 'hej 一');
|
||||
|
||||
assert.deepEqual(pduObj.shortMessageOctets, Buffer.from('hej 一', 'utf16le').swap16());
|
||||
});
|
||||
});
|
||||
|
||||
describe('encoding submit_multi', () => {
|
||||
const dest = { dest_addr_npi: 1, dest_addr_ton: 1, destination_addr: '46709771337' };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user