Name the refusal rule, and refuse a period the encoder cannot spell (#99)
* Refuse a relative validity period the SMPP time format cannot hold * Export unencodableText(), so a caller can word a refusal as the library does * Name the refusal rule in the README, and correct what it claims * Word the period refusal by what the encoder spells, and keep unencodableText() internal * Correct the decision bullet premise about what the relative format holds * Close the stability nits on the time guard and its tests
This commit is contained in:
+39
-2
@@ -237,10 +237,47 @@ describe('smppTime', () => {
|
||||
assert.equal(smppTime.encode(new Date(Date.UTC(2026, 7, 25, 14, 30, 0))).text, '260825143000000+');
|
||||
});
|
||||
|
||||
test('encodes a relative time given in seconds, clamped to what the format holds', () => {
|
||||
test('encodes a relative time given in seconds', () => {
|
||||
assert.equal(smppTime.encode(0).text, '000000000000000R');
|
||||
assert.equal(smppTime.encode(3600).text, '000000010000000R');
|
||||
assert.equal(smppTime.encode(99 * 86400).text, '000099000000000R');
|
||||
assert.equal(smppTime.encode(100 * 86400).text, '000099235959000R');
|
||||
assert.equal(smppTime.encode(99 * 86400 + 86399).text, '000099235959000R');
|
||||
});
|
||||
|
||||
test('refuses a second count past the day field rather than clamping it, naming the Date spelling', () => {
|
||||
for (const seconds of [99 * 86400 + 86400, 86400 * 365]) {
|
||||
const encoded = smppTime.encode(seconds);
|
||||
|
||||
assert.ok(encoded.err instanceof Error, String(seconds));
|
||||
assert.equal(encoded.text, undefined);
|
||||
assert.match(encoded.err.message, /pass a Date/);
|
||||
}
|
||||
});
|
||||
|
||||
test('refuses a negative period without sending the caller to the Date that cannot help', () => {
|
||||
const encoded = smppTime.encode(-1);
|
||||
|
||||
assert.ok(encoded.err instanceof Error);
|
||||
assert.equal(encoded.text, undefined);
|
||||
assert.match(encoded.err.message, /cannot be negative/);
|
||||
assert.doesNotMatch(encoded.err.message, /Date/);
|
||||
});
|
||||
|
||||
test('decodes the years and months the relative format holds but a second count cannot name', () => {
|
||||
const before = Date.now();
|
||||
const year = smppTime.decode('010000000000000R');
|
||||
const months = smppTime.decode('001000000000000R');
|
||||
const day = 86400_000;
|
||||
|
||||
assert.equal(year.err, undefined);
|
||||
assert.ok(year.date, 'a year is a period the format holds');
|
||||
assert.ok(year.date.getTime() >= before + 365 * day, year.date.toISOString());
|
||||
assert.ok(year.date.getTime() <= Date.now() + 366 * day, year.date.toISOString());
|
||||
|
||||
assert.equal(months.err, undefined);
|
||||
assert.ok(months.date, 'ten months is a period the format holds');
|
||||
assert.ok(months.date.getTime() >= before + 290 * day, months.date.toISOString());
|
||||
assert.ok(months.date.getTime() <= Date.now() + 320 * day, months.date.toISOString());
|
||||
});
|
||||
|
||||
test('passes an already-formatted string through', () => {
|
||||
|
||||
@@ -382,6 +382,17 @@ describe('a time no peer can read', () => {
|
||||
assert.equal(attempts.length, 0);
|
||||
});
|
||||
|
||||
test('refuses a year-long relative period rather than sending 99 days and reporting a year', async () => {
|
||||
const attempts: PduObjectInput[] = [];
|
||||
const sent = await submitSms(recordingDeps(attempts), { from, message: 'Hello world', to, validityPeriod: 86400 * 365 });
|
||||
|
||||
assert.ok(sent.err instanceof Error);
|
||||
assert.match(sent.err.message, /validityPeriod/);
|
||||
assert.match(sent.err.message, /Date/);
|
||||
assert.deepEqual(sent.smsIds, []);
|
||||
assert.equal(attempts.length, 0, 'a period the relative format cannot hold puts nothing on the wire');
|
||||
});
|
||||
|
||||
test('refuses a time that is no kind of time rather than throwing out of the send', async () => {
|
||||
const attempts: PduObjectInput[] = [];
|
||||
const deps = recordingDeps(attempts);
|
||||
|
||||
Reference in New Issue
Block a user