Added tests for long messages
This commit is contained in:
+14
-13
@@ -16,9 +16,10 @@ var log = require('winston'),
|
||||
*/
|
||||
function smsResp(status, callback) {
|
||||
var sms = this,
|
||||
tasks = [],
|
||||
localSmsId,
|
||||
err,
|
||||
i,
|
||||
tasks = [];
|
||||
i;
|
||||
|
||||
if (typeof status === 'function') {
|
||||
callback = status;
|
||||
@@ -43,26 +44,27 @@ function smsResp(status, callback) {
|
||||
status = 'ESME_RUNKNOWNERR'; // Set to unknown error in this case
|
||||
}
|
||||
|
||||
if (sms.pduObjs === undefined && sms.pduObj === undefined) {
|
||||
if (sms.pduObjs === undefined) {
|
||||
err = new Error('No pdu objects found to base return PDU upon');
|
||||
log.warn('larvitsmpp: lib/session.js: smsResp() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sms.pduObjs === undefined) {
|
||||
sms.pduObjs = [{'pduObj': sms.pduObj}];
|
||||
}
|
||||
|
||||
// Build async tasks to run the responses in parallel
|
||||
i = 0;
|
||||
|
||||
while (sms.pduObjs[i] !== undefined) {
|
||||
if (sms.pduObjs[i].pduObj.params.esm_class === 0x40) {
|
||||
localSmsId = sms.smsId + '-' + (i + 1);
|
||||
} else {
|
||||
localSmsId = sms.smsId;
|
||||
}
|
||||
|
||||
tasks.push(async.apply(
|
||||
sms.session.sendReturn,
|
||||
sms.pduObjs[i].pduObj,
|
||||
status,
|
||||
{'message_id': sms.smsId},
|
||||
{'message_id': localSmsId},
|
||||
false
|
||||
));
|
||||
|
||||
@@ -355,7 +357,7 @@ function session(sock) {
|
||||
* to - international format
|
||||
* message - string
|
||||
* dlr - boolean defaults to false
|
||||
* @param func callback(err, smsIds, retPduObj)
|
||||
* @param func callback(err, smsIds, retPduObjs)
|
||||
*/
|
||||
returnObj.sendSms = function(smsOptions, callback) {
|
||||
var pduObj = {};
|
||||
@@ -384,7 +386,7 @@ function session(sock) {
|
||||
|
||||
returnObj.send(pduObj, function(err, retPduObj) {
|
||||
if (typeof callback === 'function') {
|
||||
callback(err, [retPduObj.params.message_id], retPduObj);
|
||||
callback(err, [retPduObj.params.message_id], [retPduObj]);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -619,8 +621,7 @@ function session(sock) {
|
||||
|
||||
// These are needed for references here and there in functions
|
||||
'session': returnObj,
|
||||
'pduObj': pduObj,
|
||||
|
||||
'pduObjs': [{'pduObj': pduObj}],
|
||||
'from': pduObj.params.source_addr,
|
||||
'to': pduObj.params.destination_addr,
|
||||
'submitTime': new Date(),
|
||||
|
||||
+69
-6
@@ -116,7 +116,7 @@ describe('Sessions', function() {
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'hello world', 'SMS message should be "hello world"');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
@@ -140,13 +140,14 @@ describe('Sessions', function() {
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'hello world'
|
||||
}, function(err, smsIds, retPduObj) {
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343', 'Given smsId should be "2343"');
|
||||
assert(retPduObj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObj.cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs instanceof Array, 'retPduObjs should be an Array');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -157,8 +158,70 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
/*it('should try sending a long sms', function(done) {
|
||||
it('should try sending a long sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
});*/
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.', 'SMS message should be correct');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
assert(retPdus[0].toString('hex') === '00000017800000040000000000000002323334332d3100', 'Return PDU 0 is wrong');
|
||||
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334332d3200', 'Return PDU 1 is wrong');
|
||||
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334332d3300', 'Return PDU 2 is wrong');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
|
||||
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
|
||||
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user